use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method applyStaticRoutes.
@Override
public boolean applyStaticRoutes(final Vpc vpc, final List<StaticRouteProfile> routes) throws ResourceUnavailableException {
final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router element doesn't need to static routes on the backend; virtual router doesn't exist in the vpc " + vpc);
return true;
}
final Zone zone = zoneRepository.findOne(vpc.getZoneId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
if (!networkTopology.applyStaticRoutes(routes, routers)) {
throw new CloudRuntimeException("Failed to apply static routes in vpc " + vpc);
} else {
s_logger.debug("Applied static routes on vpc " + vpc);
return true;
}
}
use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method applyACLItemsToPrivateGw.
@Override
public boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
final Network network = _networkDao.findById(gateway.getNetworkId());
final boolean isPrivateGateway = true;
final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router element doesn't need to apply network acl rules on the backend; virtual router doesn't exist in the network " + network.getId());
return true;
}
final Zone zone = zoneRepository.findOne(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId());
boolean result = true;
for (final DomainRouterVO domainRouterVO : routers) {
final NicProfile nicProfile = _networkModel.getNicProfile(domainRouterVO, privateNetwork.getId(), null);
if (nicProfile != null) {
result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
} else {
s_logger.warn("Nic Profile for router '" + domainRouterVO + "' has already been removed. Router is redundant = " + domainRouterVO.getIsRedundantRouter());
}
}
return result;
}
use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method createPrivateGateway.
@Override
public boolean createPrivateGateway(final PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
if (gateway.getType() != VpcGateway.Type.Private) {
s_logger.warn("Type of vpc gateway is not " + VpcGateway.Type.Private);
return true;
}
final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual router doesn't exist in the vpc id=" + gateway.getVpcId());
return true;
}
final Zone zone = zoneRepository.findOne(gateway.getZoneId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
boolean result = true;
final Network network = _networkDao.findById(gateway.getNetworkId());
final boolean isPrivateGateway = true;
for (final DomainRouterVO domainRouterVO : routers) {
if (networkTopology.setupPrivateGateway(gateway, domainRouterVO)) {
try {
final List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(gateway.getNetworkACLId());
result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
} catch (final Exception ex) {
s_logger.debug("Failed to apply network acl id " + gateway.getNetworkACLId() + " on gateway ");
return false;
}
}
}
return result;
}
use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.
the class DirectNetworkGuru method allocate.
@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
final Zone zone = zoneRepository.findOne(network.getDataCenterId());
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
} else if (nic.getIPv4Address() == null && nic.getIPv6Address() == null) {
nic.setReservationStrategy(ReservationStrategy.Start);
} else {
nic.setReservationStrategy(ReservationStrategy.Create);
}
allocateDirectIp(nic, network, vm, zone, nic.getRequestedIPv4(), nic.getRequestedIPv6());
nic.setReservationStrategy(ReservationStrategy.Create);
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.db.model.Zone in project cosmic by MissionCriticalCloud.
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 Zone zone = zoneRepository.findOne(network.getDataCenterId());
if (nic.getIPv4Address() == null && !GuestType.Sync.equals(network.getGuestType())) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setIPv4Gateway(network.getGateway());
final String guestIp;
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, zone, vm, network, nic.getRequestedIPv4(), null);
} else {
final VirtualMachine.Type vmtype = vm.getVirtualMachine().getType();
switch(vmtype) {
case User:
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
break;
case DomainRouter:
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter)) {
// Networks that support the Gateway service acquire the gateway ip on their nic
guestIp = network.getGateway();
} else {
// In other cases, acquire an ip address from the DHCP range (take lowest possible)
guestIp = _ipAddrMgr.acquireGuestIpAddressForRouter(network, nic.getRequestedIPv4());
}
break;
default:
// Backwards compatibility
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
break;
}
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, zone.getId());
}
nic.setIPv4Address(guestIp);
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
if (network.getDns1() != null && network.getDns1().equals("")) {
nic.setIPv4Dns1(zone.getDns1());
} else {
nic.setIPv4Dns1(network.getDns1());
}
if (network.getDns2() != null && network.getDns2().equals("")) {
nic.setIPv4Dns2(zone.getDns2());
} else {
nic.setIPv4Dns2(network.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;
}
Aggregations