public boolean shouldAvoid(DataCenter dc) { if (_dcIds != null && _dcIds.contains(dc.getId())) { return true; } return false; }
public NetworkTopology retrieveNetworkTopology(final DataCenter dc) { if (!_flyweight.containsKey(dc.getNetworkType())) { throw new IllegalArgumentException("The given type cannot be related to a NetworkTopology implementation. " + "Please, give a correct type."); } return _flyweight.get(dc.getNetworkType()); }
protected void sendPortForwardingRules(List<PortForwardingRuleTO> portForwardingRules, DataCenter zone, long externalFirewallId) throws ResourceUnavailableException { if (!portForwardingRules.isEmpty()) { SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(portForwardingRules); Answer answer = _agentMgr.easySend(externalFirewallId, cmd); if (answer == null || !answer.getResult()) { String details = (answer != null) ? answer.getDetails() : "details unavailable"; String msg = "External firewall was unable to apply port forwarding rules to the SRX appliance in zone " + zone.getName() + " due to: " + details + "."; s_logger.error(msg); throw new ResourceUnavailableException(msg, DataCenter.class, zone.getId()); } } }
@Override public void updateNicProfile(NicProfile profile, Network network) { DataCenter dc = _dcDao.findById(network.getDataCenterId()); if (profile != null) { profile.setIPv4Dns1(dc.getDns1()); profile.setIPv4Dns2(dc.getDns2()); profile.setIPv6Dns1(dc.getIp6Dns1()); profile.setIPv6Dns2(dc.getIp6Dns2()); } }
/** * Get default network for console proxy VM for starting up in a basic zone. Basic zones select * the Guest network whether or not the zone is SG-enabled. * @param dc - The zone. * @return The default network according to the zone's network selection rules. * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found. */ protected NetworkVO getDefaultNetworkForBasicZone(DataCenter dc) { if (dc.getNetworkType() != NetworkType.Basic) { throw new CloudRuntimeException("Zone " + dc + "is not basic."); } TrafficType defaultTrafficType = TrafficType.Guest; List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType); // api should never allow this situation to happen if (defaultNetworks.size() != 1) { throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1"); } return defaultNetworks.get(0); }
private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) throws InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIPv4Address() == null) { s_logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address())); PublicIp ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), requiredIp, false, false); nic.setIPv4Address(ip.getAddress().toString()); nic.setFormat(AddressFormat.Ip4); nic.setIPv4Gateway(ip.getGateway()); nic.setIPv4Netmask(ip.getNetmask()); if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) { nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED)); nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED)); nic.setBroadcastType(BroadcastDomainType.Native); } nic.setReservationId(String.valueOf(ip.getVlanTag())); nic.setMacAddress(ip.getMacAddress()); } nic.setIPv4Dns1(dc.getDns1()); nic.setIPv4Dns2(dc.getDns2()); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final DataCenter dataCenter = _resourceService.getZone(getZoneId()); if (dataCenter == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId()); } final boolean result = haConfigManager.enableHA(dataCenter); CallContext.current().setEventDetails("Zone Id:" + dataCenter.getId() + " HA enabled: true"); CallContext.current().putContextParameter(DataCenter.class, dataCenter.getUuid()); setupResponse(result); }
if (zone.getNetworkType() == NetworkType.Advanced) { List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId())); if (networks.size() == 0) { String domain = _domainService.getDomain(getDomainId()).getName(); throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { ResourceAllocationException ex = new ResourceAllocationException("Cannot perform this operation, " + "Zone is currently disabled" + "zoneId=" + zone.getUuid(), ResourceType.network); throw ex; throw new ResourceAllocationException("No sush pod exists", ResourceType.network); vo = _privateIPAddressDao.takeIpAddress(zone.getId(), podvo.getId(), 0, caller.getId() + "", false); if(vo == null) throw new ResourceAllocationException("Unable to allocate IP from this Pod", ResourceType.network);
&& (network.getGuestType() == Network.GuestType.Isolated || network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced)) { ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid()); throw ex; ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid()); throw ex;
@Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { finalizeCommandsOnStart(cmds, profile); ConsoleProxyVO proxy = _consoleProxyDao.findById(profile.getId()); DataCenter dc = dest.getDataCenter(); List<NicProfile> nics = profile.getNics(); for (NicProfile nic : nics) { if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { proxy.setPublicIpAddress(nic.getIPv4Address()); proxy.setPublicNetmask(nic.getIPv4Netmask()); proxy.setPublicMacAddress(nic.getMacAddress()); } else if (nic.getTrafficType() == TrafficType.Management) { proxy.setPrivateIpAddress(nic.getIPv4Address()); proxy.setPrivateMacAddress(nic.getMacAddress()); } } _consoleProxyDao.update(proxy.getId(), proxy); return true; }
@Override public String getCanonicalName(Network net) { String netname; if (net.getTrafficType() == TrafficType.Guest) { return net.getName(); } else if (net.getTrafficType() == TrafficType.Management || net.getTrafficType() == TrafficType.Storage) { return managementNetworkName; } else if (net.getTrafficType() == TrafficType.Control) { return "__link_local__"; } else { DataCenter zone = _dcDao.findById(net.getDataCenterId()); String zonename = zone.getName(); zonename = zonename.replaceAll("\\s", ""); zonename = zonename.replace("-", "_"); netname = "__" + zonename + "_" + net.getTrafficType().toString() + "__"; } return netname; }
@Override public PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { List<PhysicalNetworkVO> networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); DataCenter dc = ApiDBUtils.findZoneById(zoneId); String dcUuid = String.valueOf(zoneId); if (dc != null) { dcUuid = dc.getUuid(); } if (networkList.isEmpty()) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in the specified zone id"); ex.addProxyObject(dcUuid, "zoneId"); throw ex; } if (networkList.size() > 1) { InvalidParameterValueException ex = new InvalidParameterValueException("More than one physical networks exist in zone id=" + zoneId + " with traffic type=" + trafficType); ex.addProxyObject(dcUuid, "zoneId"); throw ex; } return networkList.get(0); }
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getName());
final boolean assign = false; if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { ex.addProxyObject(zone.getUuid(), "zoneId"); throw ex;
@Override public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? "; DataCenter dc = _dcDao.findById(config.getDataCenterId()); if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) { nic.setBroadcastUri(config.getBroadcastUri()); nic.setIsolationUri(config.getBroadcastUri()); nic.setIPv4Dns1(dc.getDns1()); nic.setIPv4Dns2(dc.getDns2()); nic.setIPv4Netmask(NetUtils.cidr2Netmask(config.getCidr())); long cidrAddress = NetUtils.ip2Long(config.getCidr().split("/")[0]); int cidrSize = getGloballyConfiguredCidrSize(); nic.setIPv4Gateway(config.getGateway()); if (nic.getIPv4Address() == null) { if (!_networkModel.listNetworkOfferingServices(config.getNetworkOfferingId()).isEmpty()) { String guestIp = _ipAddrMgr.acquireGuestIpAddress(config, null); if (guestIp == null) { throw new InsufficientVirtualNetworkCapacityException("Unable to acquire guest IP address for network " + config, DataCenter.class, dc.getId()); } nic.setIPv4Address(guestIp); } } else { long ipMask = NetUtils.ip2Long(nic.getIPv4Address()) & ~(0xffffffffffffffffl << (32 - cidrSize)); nic.setIPv4Address(NetUtils.long2Ip(cidrAddress | ipMask)); } } else { super.reserve(nic, config, vm, dest, context); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final DataCenter dataCenter = _resourceService.getZone(getZoneId()); if (dataCenter == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId()); } final boolean result = haConfigManager.disableHA(dataCenter); CallContext.current().setEventDetails("Zone Id:" + dataCenter.getId() + " HA enabled: false"); CallContext.current().putContextParameter(DataCenter.class, dataCenter.getUuid()); setupResponse(result); }