use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class CreateApplicationLoadBalancerCmd method create.
@Override
public void create() {
try {
ApplicationLoadBalancerRule result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(), getSourceIpNetworkId(), getSourceIp(), getSourcePort(), getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getDisplay());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
} catch (InsufficientAddressCapacityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
} catch (InsufficientVirtualNetworkCapacityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class NiciraNvpGuestNetworkGuru method implement.
@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert network.getState() == State.Implementing : "Why are we implementing " + network;
final long dcId = dest.getDataCenter().getId();
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
// 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() > MAX_NAME_LENGTH) {
name = name.substring(0, MAX_NAME_LENGTH - 1);
}
final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
return null;
}
final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
if (offering.getGuestType().equals(GuestType.Shared)) {
try {
checkL2GatewayServiceSharedNetwork(niciraNvpHost);
} catch (Exception e) {
s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
return null;
}
}
final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("CreateLogicalSwitchCommand failed");
return null;
}
try {
implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null));
implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString());
} catch (final URISyntaxException e) {
s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
return null;
}
return implemented;
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class GuestNetworkGuru method allocate.
@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Guest : "Look at my name! Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
if (nic.getIPv4Address() == null) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setIPv4Gateway(network.getGateway());
String guestIp = null;
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIPv4(), null);
} else {
//if Vm is router vm and source nat is enabled in the network, set ip4 to the network gateway
boolean isGateway = false;
if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
if (network.getVpcId() != null) {
final Vpc vpc = _vpcDao.findById(network.getVpcId());
// Redundant Networks need a guest IP that is not the same as the gateway IP.
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VPCVirtualRouter) && !vpc.isRedundant()) {
isGateway = true;
}
} else {
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VirtualRouter)) {
isGateway = true;
}
}
}
if (isGateway) {
guestIp = network.getGateway();
} else {
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, dc.getId());
}
}
nic.setIPv4Address(guestIp);
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
nic.setFormat(AddressFormat.Ip4);
}
}
nic.setReservationStrategy(ReservationStrategy.Start);
if (nic.getMacAddress() == null) {
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
if (nic.getMacAddress() == null) {
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
}
}
return nic;
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class ContrailGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
vnModel.setProperties(_manager.getModelController(), network);
}
try {
if (!vnModel.verify(_manager.getModelController())) {
vnModel.update(_manager.getModelController());
}
} catch (Exception ex) {
s_logger.warn("virtual-network update: ", ex);
return network;
}
_manager.getDatabase().getVirtualNetworks().add(vnModel);
if (network.getVpcId() != null) {
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for network " + network);
Account owner = _accountMgr.getAccount(network.getAccountId());
try {
PublicIp publicIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
IPAddressVO ip = publicIp.ip();
ip.setVpcId(network.getVpcId());
_ipAddressDao.acquireInLockTable(ip.getId());
_ipAddressDao.update(ip.getId(), ip);
_ipAddressDao.releaseFromLockTable(ip.getId());
} catch (Exception e) {
s_logger.error("Unable to allocate source nat ip: " + e);
}
}
}
return network;
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class ContrailGuru method allocate.
/**
* Allocate the NicProfile object.
* At this point the UUID of the nic is not yet known. We defer allocating the VMI and instance-ip objects
* until the reserve API is called because of this reason.
*/
@Override
public NicProfile allocate(Network network, NicProfile profile, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
s_logger.debug("allocate NicProfile on " + network.getName());
if (profile != null && profile.getRequestedIPv4() != null) {
throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + profile);
}
if (profile == null) {
profile = new NicProfile(ReservationStrategy.Create, null, null, null, null);
}
profile.setReservationStrategy(ReservationStrategy.Start);
URI broadcastUri = null;
try {
broadcastUri = new URI("vlan://untagged");
} catch (Exception e) {
s_logger.warn("unable to instantiate broadcast URI: " + e);
}
profile.setBroadcastUri(broadcastUri);
return profile;
}
Aggregations