use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method deleteNiciraNvpDevice.
@Override
public boolean deleteNiciraNvpDevice(final DeleteNiciraNvpDeviceCmd cmd) {
final Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
final NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraDeviceId);
if (niciraNvpDevice == null) {
throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
}
// Find the physical network we work for
final Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork != null) {
// Lets see if there are networks that use us
// Find the nicira networks on this physical network
final List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
if (networkList != null) {
// Networks with broadcast type lswitch are ours
for (final NetworkVO network : networkList) {
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
if (network.getState() != Network.State.Shutdown && network.getState() != Network.State.Destroy) {
throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
}
}
}
}
}
final HostVO niciraHost = hostDao.findById(niciraNvpDevice.getHostId());
final Long hostId = niciraHost.getId();
niciraHost.setResourceState(ResourceState.Maintenance);
hostDao.update(hostId, niciraHost);
resourceMgr.deleteHost(hostId, false, false);
niciraNvpDao.remove(niciraDeviceId);
return true;
}
use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method prepare.
@Override
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, IllegalVirtualMachineException {
if (!canHandle(network, Network.Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
final NicVO nicVO = nicDao.findById(nic.getId());
final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
final NiciraNvpNicMappingVO existingNicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
if (existingNicMap != null) {
final FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchUuid(), existingNicMap.getLogicalSwitchPortUuid());
final FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), findCmd);
if (answer.getResult()) {
s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
final UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
agentMgr.easySend(niciraNvpHost.getId(), cmd);
return true;
} else {
s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid());
niciraNvpNicMappingDao.remove(existingNicMap.getId());
}
}
VirtualMachine virtualMachine = vm.getVirtualMachine();
boolean macLearning = false;
if (virtualMachine != null) {
macLearning = guestOSDao.listByGuestOSId(virtualMachine.getGuestOSId()).isMacLearning();
}
final CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName(), macLearning);
final CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
throw new NicPreparationException("CreateLogicalSwitchPortCommand failed");
}
final NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
niciraNvpNicMappingDao.persist(nicMap);
return true;
}
use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method applyIps.
/**
* From interface IpDeployer
*
* @param network
* @param ipAddress
* @param services
* @return
* @throws ResourceUnavailableException
*/
@Override
public boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Network.Service> services) throws ResourceUnavailableException {
if (services.contains(Network.Service.SourceNat)) {
// Only if we need to provide SourceNat we need to configure the logical router
// SourceNat is required for StaticNat and PortForwarding
final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
final NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
if (routermapping == null) {
s_logger.error("No logical router uuid found for network " + network.getDisplayText());
return false;
}
final List<String> cidrs = new ArrayList<>();
for (final PublicIpAddress ip : ipAddress) {
if (ip.getState() == IpAddress.State.Releasing) {
// the Logical Router
continue;
}
cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
}
final ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
// FIXME answer can be null if the host is down
return answer.getResult();
} else {
s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
}
return true;
}
use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method implement.
@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
if (!canHandle(network, Network.Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
final Account owner = context.getAccount();
// Implement SourceNat immediately as we have al the info already
if (networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) {
s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
final PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
// assuming a vlan:
String vtag = sourceNatIp.getVlanTag();
BroadcastDomainType tiep = null;
try {
tiep = BroadcastDomainType.getTypeOf(vtag);
} catch (final URISyntaxException use) {
throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
}
if (tiep == BroadcastDomainType.Vlan) {
vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
} else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
}
final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag);
final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
return false;
}
// Store the uuid so we can easily find it during cleanup
final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
niciraNvpRouterMappingDao.persist(routermapping);
}
return true;
}
use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method listNiciraNvpDeviceNetworks.
@Override
public List<? extends Network> listNiciraNvpDeviceNetworks(final ListNiciraNvpDeviceNetworksCmd cmd) {
final Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
final NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraDeviceId);
if (niciraNvpDevice == null) {
throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
}
// Find the physical network we work for
final Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
// No such physical network, so no provisioned networks
return Collections.emptyList();
}
// Find the nicira networks on this physical network
final List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
if (networkList == null) {
return Collections.emptyList();
}
// Networks with broadcast type lswitch are ours
final List<NetworkVO> responseList = new ArrayList<>();
for (final NetworkVO network : networkList) {
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
responseList.add(network);
}
}
return responseList;
}
Aggregations