public VspNic buildVspNic(String nicUuid, NicProfile nicProfile) { return buildVspNic(nicUuid, nicProfile.getMacAddress(), nicProfile.getIPv4Address(), nicProfile.getNetworkId(), null); }
@Override public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) { if (!nic.getBroadCastUri().getScheme().equals("pvlan")) { return false; } String op = "add"; if (!add) { // "delete" would remove all the rules(if using ovs) related to this vm op = "delete"; } Network network = _networkDao.findById(nic.getNetworkId()); Host host = _hostDao.findById(hostId); String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network); PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress()); Answer answer = null; try { answer = _agentMgr.send(hostId, cmd); } catch (OperationTimedoutException e) { s_logger.warn("Timed Out", e); return false; } catch (AgentUnavailableException e) { s_logger.warn("Agent Unavailable ", e); return false; } boolean result = true; if (answer == null || !answer.getResult()) { result = false; } return result; }
@Override public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { 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 DisassociateMacFromNetworkCmd instance and agentMgr execute it. DisassociateMacFromNetworkCommand cmd = new DisassociateMacFromNetworkCommand(network.getId(), interfaceMac); DisassociateMacFromNetworkAnswer answer = (DisassociateMacFromNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("DisassociateMacFromNetworkCommand failed"); s_logger.error("Unable to disassociate mac " + interfaceMac + " from network " + network.getId()); return; } } super.deallocate(network, nic, vm); }
final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, nicProfile.getMacAddress());
@Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { super.reserve(nic, network, vm, dest, context); //get physical network id Long physicalNetworkId = network.getPhysicalNetworkId(); List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { s_logger.error("No Controller on physical network " + physicalNetworkId); throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId()); } OpenDaylightControllerVO controller = devices.get(0); AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress()); AddHypervisorAnswer addAnswer = (AddHypervisorAnswer)agentManager.easySend(controller.getHostId(), addCmd); if (addAnswer == null || !addAnswer.getResult()) { s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller"); throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId()); } ConfigurePortCommand cmd = new ConfigurePortCommand(UUID.fromString(nic.getUuid()), UUID.fromString(BroadcastDomainType.getValue(network.getBroadcastUri())), context .getAccount().getAccountName(), nic.getMacAddress()); ConfigurePortAnswer answer = (ConfigurePortAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ConfigureNetworkCommand failed"); throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId()); } }
@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 boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); List<NicProfile> nics = profile.getNics(); for (NicProfile nic : nics) { if (nic.getTrafficType() == TrafficType.Public) { elbVm.setPublicIpAddress(nic.getIPv4Address()); elbVm.setPublicNetmask(nic.getIPv4Netmask()); elbVm.setPublicMacAddress(nic.getMacAddress()); } else if (nic.getTrafficType() == TrafficType.Control) { elbVm.setPrivateIpAddress(nic.getIPv4Address()); elbVm.setPrivateMacAddress(nic.getMacAddress()); } } _routerDao.update(elbVm.getId(), elbVm); finalizeCommandsOnStart(cmds, profile); return true; }
@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 boolean finalizeDeployment(final Commands cmds, final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException { final DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); final List<NicProfile> nics = profile.getNics(); for (final NicProfile nic : nics) { if (nic.getTrafficType() == TrafficType.Control) { internalLbVm.setPrivateIpAddress(nic.getIPv4Address()); internalLbVm.setPrivateMacAddress(nic.getMacAddress()); } } _internalLbVmDao.update(internalLbVm.getId(), internalLbVm); finalizeCommandsOnStart(cmds, profile); return true; }
@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()); } } }
@Override @DB public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Host host = dest.getHost(); if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { return false; } nic.setMacAddress(host.getPrivateMacAddress()); NicVO vo = _nicDao.findById(nic.getId()); assert vo != null : "Where ths nic " + nic.getId() + " going???"; vo.setMacAddress(nic.getMacAddress()); _nicDao.update(vo.getId(), vo); return true; }
@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 boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; String op = "add"; if (!_isAddPvlan) { op = "delete"; } NetworkDao networkDao = visitor.getVirtualNetworkApplianceFactory().getNetworkDao(); final Network network = networkDao.findById(_nic.getNetworkId()); NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel(); final String networkTag = networkModel.getNetworkTag(_router.getHypervisorType(), network); _setupCommand = PvlanSetupCommand.createDhcpSetup(op, _nic.getBroadCastUri(), networkTag, _router.getInstanceName(), _nic.getMacAddress(), _nic.getIPv4Address()); return visitor.visit(this); }
nic.setIPv6Gateway(network.getIp6Gateway()); IPv6Address ipv6addr = NetUtils.EUI64Address(network.getIp6Cidr(), nic.getMacAddress()); s_logger.info("Calculated IPv6 address " + ipv6addr + " using EUI-64 for NIC " + nic.getUuid()); nic.setIPv6Address(ipv6addr.toString());
private boolean preparePxeInBasicZone(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) throws AgentUnavailableException, OperationTimedoutException { NetworkVO nwVO = _nwDao.findById(nic.getNetworkId()); QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class); sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString()); sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId()); BaremetalPxeVO pxeVo = sc.find(); if (pxeVo == null) { throw new CloudRuntimeException("No kickstart PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM"); } VMTemplateVO template = _tmpDao.findById(profile.getTemplateId()); List<String> tuple = parseKickstartUrl(profile); String ks = tuple.get(0); String kernel = tuple.get(1); String initrd = tuple.get(2); PrepareKickstartPxeServerCommand cmd = new PrepareKickstartPxeServerCommand(); cmd.setKsFile(ks); cmd.setInitrd(initrd); cmd.setKernel(kernel); cmd.setMac(nic.getMacAddress()); cmd.setTemplateUuid(template.getUuid()); Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd); if (!aws.getResult()) { s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); return false; } return true; }
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()); }
if(nic.getMacAddress() == null) { nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
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; }
String mac = pxeNic.getMacAddress(); String ip = pxeNic.getIPv4Address(); String gateway = pxeNic.getIPv4Gateway();
@Override @DB public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { return false; } VMInstanceVO vo = _vmDao.findById(vm.getId()); assert vo != null : "Where ths nic " + nic.getId() + " going???"; if (vo.getLastHostId() == null) { nic.setMacAddress(dest.getHost().getPrivateMacAddress()); NicVO nicVo = _nicDao.findById(nic.getId()); nicVo.setMacAddress(nic.getMacAddress()); _nicDao.update(nicVo.getId(), nicVo); /*This vm is just being created */ if (!_pxeMgr.prepare(vm, nic, network, dest, context)) { throw new CloudRuntimeException("Cannot prepare pxe server"); } } if (dest.getDataCenter().getNetworkType() == DataCenter.NetworkType.Advanced){ prepareVlan(network, dest); } return true; }