use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class NuageVspGuestNetworkGuru method allocate.
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
if (vm.getType() != VirtualMachine.Type.DomainRouter && _nuageVspEntityBuilder.usesVirtualRouter(network.getNetworkOfferingId())) {
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
if (nic != null && nic.getRequestedIPv4() != null && vspNetwork.getVirtualRouterIp().equals(nic.getRequestedIPv4())) {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
s_logger.error("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved for the VR in network " + network);
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved " + "for the VR in network " + network, DataCenter.class, dc.getId());
}
}
return super.allocate(network, nic, vm);
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class NuageVspGuestNetworkGuru method updateDhcpOptionsForExistingVms.
private void updateDhcpOptionsForExistingVms(Network network, HostVO nuageVspHost, VspNetwork vspNetwork, boolean networkHasDns, Map<Long, Boolean> networkHasDnsCache) throws InsufficientVirtualNetworkCapacityException {
// Update dhcp options if a VR is added when we are not initiating the network
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("DomainRouter is added to an existing network: %s in state: %s", network.getName(), network.getState()));
}
List<NicVO> userNics = _nicDao.listByNetworkId(network.getId());
LinkedListMultimap<Long, VspDhcpVMOption> dhcpOptionsPerDomain = LinkedListMultimap.create();
for (NicVO userNic : userNics) {
if (userNic.getVmType() == VirtualMachine.Type.DomainRouter) {
continue;
}
VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId());
boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, userNic);
VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(userNic, defaultHasDns, networkHasDns);
dhcpOptionsPerDomain.put(userVm.getDomainId(), dhcpOption);
}
for (Long domainId : dhcpOptionsPerDomain.keySet()) {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_domainDao.findById(domainId));
VspNetwork vspNetworkForDomain = new VspNetwork.Builder().fromObject(vspNetwork).domain(vspDomain).build();
List<VspDhcpVMOption> dhcpOptions = dhcpOptionsPerDomain.get(domainId);
UpdateDhcpOptionVspCommand cmd = new UpdateDhcpOptionVspCommand(dhcpOptions, vspNetworkForDomain);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("UpdateDhcpOptionVspCommand failed at \"reserve\" for network " + vspNetwork.getName() + " under domain " + vspNetwork.getVspDomain().getName());
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class BigSwitchBcfGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
bcfUtilsInit();
long dcId = dest.getDataCenter().getId();
long physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, false);
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
String vnetId = "";
if (network.getBroadcastUri() == null) {
vnetId = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), context.getReservationId(), UseSystemGuestVlans.valueIn(network.getAccountId()));
if (vnetId == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId);
}
implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnetId));
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnetId + " Network Id: " + network.getId(), 0);
} else {
implemented.setBroadcastUri(network.getBroadcastUri());
}
// Name is either the given name or the uuid
String name = network.getName();
if (name == null || name.isEmpty()) {
name = ((NetworkVO) network).getUuid();
}
if (name.length() > 64) {
// max length 64
name = name.substring(0, 63);
}
// update fields in network object
NetworkVO networkObject = (NetworkVO) network;
// determine whether this is VPC network or stand-alone network
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcDao.acquireInLockTable(network.getVpcId());
}
// use uuid of networkVO as network id in BSN
String networkId = networkObject.getUuid();
String tenantId;
String tenantName;
if (vpc != null) {
tenantId = vpc.getUuid();
tenantName = vpc.getName();
_vpcDao.releaseFromLockTable(vpc.getId());
} else {
// use network in CS as tenant in BSN
// for non-VPC networks, use network name and id as tenant name and id
tenantId = networkId;
tenantName = name;
}
// store tenantId in networkObject for NetworkOrchestrator implementNetwork use
networkObject.setNetworkDomain(tenantId);
// store tenant Id in implemented object for future actions (e.g., shutdown)
implemented.setNetworkDomain(tenantId);
String vlanStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());
// get public net info - needed to set up source nat gateway
NetworkVO pubNet = _bcfUtils.getPublicNetwork(physicalNetworkId);
// locate subnet info
SearchCriteria<VlanVO> sc = _vlanDao.createSearchCriteria();
sc.setParameters("network_id", pubNet.getId());
VlanVO pubVlanVO = _vlanDao.findOneBy(sc);
String pubVlanStr = pubVlanVO.getVlanTag();
Integer vlan;
if (StringUtils.isNumeric(vlanStr)) {
vlan = Integer.valueOf(vlanStr);
} else {
vlan = 0;
}
CreateBcfSegmentCommand cmd1 = new CreateBcfSegmentCommand(tenantId, tenantName, networkId, name, vlan);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd1, networkObject);
if (_bcfUtils.isNatEnabled()) {
Integer pvlan;
if (StringUtils.isNumeric(pubVlanStr)) {
pvlan = Integer.valueOf(pubVlanStr);
} else {
pvlan = 0;
}
CreateBcfSegmentCommand cmd2 = new CreateBcfSegmentCommand("external", "external", "external", "external", pvlan);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd2, networkObject);
CreateBcfRouterCommand cmd3 = new CreateBcfRouterCommand(tenantId);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd3, network);
CreateBcfRouterInterfaceCommand cmd5 = new CreateBcfRouterInterfaceCommand(tenantId, network.getUuid(), network.getCidr(), network.getGateway(), network.getName());
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd5, network);
}
return implemented;
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuru method reserve.
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
super.reserve(nic, network, vm, dest, context);
DataCenter dc = _dcDao.findById(network.getDataCenterId());
String interfaceMac = nic.getMacAddress();
List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId());
return;
}
for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
// create AssociateMacToNetworkCmd instance and agentMgr execute it.
AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(network.getId(), interfaceMac, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("AssociateMacToNetworkCommand failed");
throw new InsufficientVirtualNetworkCapacityException("Unable to associate mac " + interfaceMac + " to network " + network.getId(), DataCenter.class, dc.getId());
}
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateStorageMigration.
private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (destPool == null) {
throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
}
try {
stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
} catch (final NoTransitionException e) {
s_logger.debug("Unable to migrate vm: " + e.toString());
throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
}
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
boolean migrationResult = false;
try {
migrationResult = volumeMgr.storageMigration(profile, destPool);
if (migrationResult) {
if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
_networkMgr.reallocate(vmProfile, plan);
}
//when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
vm.setLastHostId(null);
vm.setPodIdToDeployIn(destPool.getPodId());
// unregister the VM from the source host and cleanup the associated VM files.
if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
Long srcClusterId = null;
Long srcHostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (srcHostId != null) {
HostVO srcHost = _hostDao.findById(srcHostId);
srcClusterId = srcHost.getClusterId();
}
final Long destClusterId = destPool.getClusterId();
if (srcClusterId != null && destClusterId != null && !srcClusterId.equals(destClusterId)) {
final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
s_logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() + " from source host: " + srcHostId);
final UnregisterVMCommand uvc = new UnregisterVMCommand(vm.getInstanceName());
uvc.setCleanupVmFiles(true);
try {
_agentMgr.send(srcHostId, uvc);
} catch (final AgentUnavailableException | OperationTimedoutException e) {
throw new CloudRuntimeException("Failed to unregister VM: " + vm.getInstanceName() + " from source host: " + srcHostId + " after successfully migrating VM's storage across VMware Datacenters");
}
}
}
}
} else {
s_logger.debug("Storage migration failed");
}
} catch (final ConcurrentOperationException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientVirtualNetworkCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientAddressCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final StorageUnavailableException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} finally {
try {
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
} catch (final NoTransitionException e) {
s_logger.debug("Failed to change vm state: " + e.toString());
throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
}
}
}
Aggregations