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()); } }
protected Integer applyProfileToNic(final NicVO vo, final NicProfile profile, Integer deviceId) { if (profile.getDeviceId() != null) { vo.setDeviceId(profile.getDeviceId()); } else if (deviceId != null) { vo.setDeviceId(deviceId++); } if (profile.getReservationStrategy() != null) { vo.setReservationStrategy(profile.getReservationStrategy()); } vo.setDefaultNic(profile.isDefaultNic()); vo.setIPv4Address(profile.getIPv4Address()); vo.setAddressFormat(profile.getFormat()); if (profile.getMacAddress() != null) { vo.setMacAddress(profile.getMacAddress()); } vo.setMode(profile.getMode()); vo.setIPv4Netmask(profile.getIPv4Netmask()); vo.setIPv4Gateway(profile.getIPv4Gateway()); if (profile.getBroadCastUri() != null) { vo.setBroadcastUri(profile.getBroadCastUri()); } if (profile.getIsolationUri() != null) { vo.setIsolationUri(profile.getIsolationUri()); } vo.setState(Nic.State.Allocated); vo.setIPv6Address(profile.getIPv6Address()); vo.setIPv6Gateway(profile.getIPv6Gateway()); vo.setIPv6Cidr(profile.getIPv6Cidr()); return deviceId; }
public VspNic buildVspNic(String nicUuid, NicProfile nicProfile) { return buildVspNic(nicUuid, nicProfile.getMacAddress(), nicProfile.getIPv4Address(), nicProfile.getNetworkId(), null); }
@Override public boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId) { nic.setBroadcastUri(null); nic.setIsolationUri(null); return true; }
@Override public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIPv4Address()); } PrivateIpVO ip = _privateIpDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address()); if (ip != null) { _privateIpDao.releaseIpAddress(nic.getIPv4Address(), nic.getNetworkId()); } nic.deallocate(); }
@Override public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); to.setType(profile.getTrafficType()); to.setIp(profile.getIPv4Address()); to.setNetmask(profile.getIPv4Netmask()); to.setMac(profile.getMacAddress()); to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); to.setGateway(profile.getIPv4Gateway()); to.setDefaultNic(profile.isDefaultNic()); to.setBroadcastUri(profile.getBroadCastUri()); to.setIsolationuri(profile.getIsolationUri()); to.setNetworkRateMbps(profile.getNetworkRate()); to.setName(profile.getName()); to.setSecurityGroupEnabled(profile.isSecurityGroupEnabled()); to.setIp6Address(profile.getIPv6Address()); to.setIp6Cidr(profile.getIPv6Cidr()); NetworkVO network = _networkDao.findById(profile.getNetworkId()); to.setNetworkUuid(network.getUuid()); NicVO nicVO = _nicDao.findById(profile.getId()); if (nicVO != null) { to.setUuid(nicVO.getUuid()); s_logger.warn("Unabled to load NicVO for NicProfile " + profile.getId());
@Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) { super.reserve(nic, network, vm, dest, context); return; } Pod pod = dest.getPod(); Integer vlan = null; StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId()); if (ip == null) { throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId()); } vlan = ip.getVlan(); nic.setIPv4Address(ip.getIpAddress()); nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac(), NetworkModel.MACIdentifier.value()))); nic.setFormat(AddressFormat.Ip4); nic.setIPv4Netmask(ip.getNetmask()); nic.setBroadcastType(BroadcastDomainType.Storage); nic.setIPv4Gateway(ip.getGateway()); if (vlan != null) { nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan)); } else { nic.setBroadcastUri(null); } nic.setIsolationUri(null); s_logger.debug("Allocated a storage nic " + nic + " for " + vm); }
final NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP(); defaultNic.setIPv4Address(sourceNatIp.getAddress().addr()); defaultNic.setIPv4Gateway(sourceNatIp.getGateway()); defaultNic.setIPv4Netmask(sourceNatIp.getNetmask()); defaultNic.setMacAddress(sourceNatIp.getMacAddress()); defaultNic.setBroadcastType(BroadcastDomainType.Vxlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); } else { defaultNic.setBroadcastType(BroadcastDomainType.Vlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setDeviceId(2); final String publicIp = defaultNic.getIPv4Address(); if (peerNic != null) { s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); defaultNic.setMacAddress(peerNic.getMacAddress());
String defaultIp6Dns2 = null; for (final NicProfile nic : profile.getNics()) { final int deviceId = nic.getDeviceId(); boolean ipv4 = false, ipv6 = false; if (nic.getIPv4Address() != null) { ipv4 = true; buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask()); if (nic.getIPv6Address() != null) { ipv6 = true; buf.append(" eth").append(deviceId).append("ip6=").append(nic.getIPv6Address()); buf.append(" eth").append(deviceId).append("ip6prelen=").append(NetUtils.getIp6CidrSize(nic.getIPv6Cidr())); if (nic.isDefaultNic()) { if (ipv4) { buf.append(" gateway=").append(nic.getIPv4Gateway()); buf.append(" ip6gateway=").append(nic.getIPv6Gateway()); defaultDns1 = nic.getIPv4Dns1(); defaultDns2 = nic.getIPv4Dns2(); defaultIp6Dns1 = nic.getIPv6Dns1(); defaultIp6Dns2 = nic.getIPv6Dns2(); if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); } else if (nic.getTrafficType() == TrafficType.Control) { controlNic = nic;
final int deviceId = nic.getDeviceId(); buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask()); if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getIPv4Gateway()); buf.append(" dns1=").append(nic.getIPv4Gateway()); if (nic.getTrafficType() == TrafficType.Guest) { guestNetwork = _ntwkModel.getNetwork(nic.getNetworkId()); } else if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); } else if (nic.getTrafficType() == TrafficType.Control) { controlNic = nic;
Long guestNtwkId = null; for (NicProfile routerNic : elbNics) { if (routerNic.getTrafficType() == TrafficType.Guest) { guestNtwkId = routerNic.getNetworkId(); break; int deviceId = nic.getDeviceId(); buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask()); if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getIPv4Gateway()); defaultDns1 = nic.getIPv4Dns1(); defaultDns2 = nic.getIPv4Dns2(); if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); } else if (nic.getTrafficType() == TrafficType.Control) {
protected StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1, final String defaultDns2, final DomainRouterVO router) { final long guestNetworkId = guestNic.getNetworkId(); final NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); String dhcpRange = null; if (isRedundant) { buf.append(createRedundantRouterArgs(guestNic, router)); final Network net = _networkModel.getNetwork(guestNic.getNetworkId()); buf.append(" guestgw=").append(net.getGateway()); final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIPv4Address()) | ~NetUtils.ip2Long(guestNic.getIPv4Netmask())); buf.append(" guestbrd=").append(brd); buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getIPv4Netmask())); if (guestNic.isDefaultNic()) { cidrSize = NetUtils.getCidrSize(guestNic.getIPv4Netmask()); final String cidr = NetUtils.getCidrSubNet(guestNic.getIPv4Gateway(), cidrSize); if (cidr != null) { dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
String dns = nic.getIPv4Dns1(); if (dns == null) { dns = nic.getIPv4Dns2(); new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd()); String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()); if (ans.getResult()) { s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName())); return true; } else {
profile = new NicProfile(nic, network, broadcastUri, isolationUri, nic.setIPv4Address(profile.getIPv4Address()); nic.setAddressFormat(profile.getFormat()); nic.setIPv6Address(profile.getIPv6Address()); nic.setIPv6Cidr(profile.getIPv6Cidr()); nic.setIPv6Gateway(profile.getIPv6Gateway()); nic.setMacAddress(profile.getMacAddress()); nic.setIsolationUri(profile.getIsolationUri()); nic.setBroadcastUri(profile.getBroadCastUri()); nic.setReserver(guru.getName()); nic.setState(Nic.State.Reserved); nic.setIPv4Netmask(profile.getIPv4Netmask()); nic.setIPv4Gateway(profile.getIPv4Gateway()); if (profile.getReservationStrategy() != null) { nic.setReservationStrategy(profile.getReservationStrategy()); profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network)); guru.updateNicProfile(profile, network);
final NicProfile guestNic = new NicProfile(); if (guestIp != null) { guestNic.setIPv4Address(guestIp.addr()); } else { guestNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null)); guestNic.setIPv4Gateway(guestNetwork.getGateway()); guestNic.setBroadcastUri(guestNetwork.getBroadcastUri()); guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); guestNic.setIsolationUri(guestNetwork.getBroadcastUri()); guestNic.setMode(guestNetwork.getMode()); final String gatewayCidr = guestNetwork.getCidr(); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); guestNic.setDefaultNic(true); networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
protected void applyProfileToNicForRelease(final NicVO vo, final NicProfile profile) { vo.setIPv4Gateway(profile.getIPv4Gateway()); vo.setAddressFormat(profile.getFormat()); vo.setIPv4Address(profile.getIPv4Address()); vo.setIPv6Address(profile.getIPv6Address()); vo.setMacAddress(profile.getMacAddress()); if (profile.getReservationStrategy() != null) { vo.setReservationStrategy(profile.getReservationStrategy()); } vo.setBroadcastUri(profile.getBroadCastUri()); vo.setIsolationUri(profile.getIsolationUri()); vo.setIPv4Netmask(profile.getIPv4Netmask()); }
@Override public boolean finalizeDeployment(final Commands cmds, final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException { final DomainRouterVO router = _routerDao.findById(profile.getId()); final List<NicProfile> nics = profile.getNics(); for (final NicProfile nic : nics) { if (nic.getTrafficType() == TrafficType.Public) { router.setPublicIpAddress(nic.getIPv4Address()); router.setPublicNetmask(nic.getIPv4Netmask()); router.setPublicMacAddress(nic.getMacAddress()); } else if (nic.getTrafficType() == TrafficType.Control) { router.setPrivateIpAddress(nic.getIPv4Address()); router.setPrivateMacAddress(nic.getMacAddress()); } } _routerDao.update(router.getId(), router); finalizeCommandsOnStart(cmds, profile); return true; }
@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 NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(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, dc, 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; }
@Override public NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefinition vpcRouterDeploymentDefinition, final Network guestNetwork) { final NicProfile guestNic = new NicProfile(); if (vpcRouterDeploymentDefinition.isRedundant()) { guestNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null)); } else { guestNic.setIPv4Address(guestNetwork.getGateway()); } guestNic.setBroadcastUri(guestNetwork.getBroadcastUri()); guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); guestNic.setIsolationUri(guestNetwork.getBroadcastUri()); guestNic.setMode(guestNetwork.getMode()); final String gatewayCidr = _networkModel.getValidNetworkCidr(guestNetwork); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); return guestNic; }