@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(); }
public Network retrievePrivateNetwork(final NetworkTopologyVisitor visitor) { // This network might be the same we have already as an instance in the // RuleApplier super class. // Just doing this here, but will double check is remove if it's not // needed. final NetworkDao networkDao = visitor.getVirtualNetworkApplianceFactory().getNetworkDao(); final Network network = networkDao.findById(_nicProfile.getNetworkId()); return network; }
@Override @DB public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("public network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIPv4Address()); } final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address()); if (ip != null && nic.getReservationStrategy() != ReservationStrategy.Managed) { Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { _ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId()); } }); } nic.deallocate(); if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocated nic: " + nic); } }
public VspNic buildVspNic(String nicUuid, NicProfile nicProfile) { return buildVspNic(nicUuid, nicProfile.getMacAddress(), nicProfile.getIPv4Address(), nicProfile.getNetworkId(), null); }
@Override @DB public void deallocate(final Network network, final NicProfile nic, final VirtualMachineProfile vm) { if (network.getSpecifyIpRanges()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIPv4Address()); } final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address()); if (ip != null) { Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { _ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId()); } }); } nic.deallocate(); } }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { Network network = _networkDao.findById(nic.getNetworkId()); _sspMgr.deleteNicEnv(network, nic, new ReservationContextImpl(reservationId, null, null)); return super.release(nic, vm, reservationId); }
public PrivateIpVO retrivePrivateIP(final NetworkTopologyVisitor visitor) { final PrivateIpVO ipVO = visitor.getVirtualNetworkApplianceFactory().getPrivateIpDao().findByIpAndSourceNetworkId(_nicProfile.getNetworkId(), _nicProfile.getIPv4Address()); return ipVO; }
continue; final Network network = _networksDao.findById(profile.getNetworkId()); if (network == null) { continue;
@Override public boolean isVmSecurityGroupEnabled(Long vmId) { VirtualMachine vm = _vmDao.findByIdIncludingRemoved(vmId); List<NicProfile> nics = _networkMgr.getNicProfiles(vm); for (NicProfile nic : nics) { Network network = _networkModel.getNetwork(nic.getNetworkId()); if (_networkModel.isSecurityGroupSupportedInNetwork(network) && vm.getHypervisorType() != HypervisorType.VMware) { return true; } } return false; }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { boolean success = super.release(nic, vm, reservationId); if (success) { //get physical network id NetworkVO network = _networkDao.findById(nic.getNetworkId()); Long physicalNetworkId = network.getPhysicalNetworkId(); List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { s_logger.error("No Controller on physical network " + physicalNetworkId); throw new CloudRuntimeException("No OpenDaylight controller on this physical network"); } OpenDaylightControllerVO controller = devices.get(0); DestroyPortCommand cmd = new DestroyPortCommand(UUID.fromString(nic.getUuid())); DestroyPortAnswer answer = (DestroyPortAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("DestroyPortCommand failed"); success = false; } } return success; }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network != null && _networkModel.networkIsConfiguredForExternalNetworking(network.getDataCenterId(), network.getId())) { return true; } else { return super.release(nic, vm, reservationId); } }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { Network nw = _nwDao.findById(nic.getNetworkId()); if (!_sNwMgr.isStorageIpRangeAvailable(nw.getDataCenterId())) { return super.release(nic, vm, reservationId); } _sNwMgr.releaseIpAddress(nic.getIPv4Address()); s_logger.debug("Release an storage ip " + nic.getIPv4Address()); nic.deallocate(); return true; }
@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 doInTransactionWithoutResult(TransactionStatus status) { // if the ip address a part of placeholder, don't release it Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null); if (placeholderNic != null && placeholderNic.getIPv4Address().equalsIgnoreCase(ip.getAddress().addr())) { s_logger.debug("Not releasing direct ip " + ip.getId() + " yet as its ip is saved in the placeholder"); } else { _ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId()); } //unassign nic secondary ip address s_logger.debug("remove nic " + nic.getId() + " secondary ip "); List<String> nicSecIps = null; nicSecIps = _nicSecondaryIpDao.getSecondaryIpAddressesForNic(nic.getId()); for (String secIp : nicSecIps) { if (NetUtils.isValidIp4(secIp)) { IPAddressVO pubIp = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), secIp); _ipAddrMgr.markIpAsUnavailable(pubIp.getId()); _ipAddressDao.unassignIpAddress(pubIp.getId()); } else { NicSecondaryIpVO nicSecIp = nicSecondaryIpDao.findByIp6AddressAndNetworkId(secIp, nic.getNetworkId()); if (nicSecIp != null) { networkService.releaseSecondaryIpFromNic(nicSecIp.getId()); } } } } });
@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); }
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; }
@Override public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) { final DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); final NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control); if (controlNic == null) { s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm); return false; } finalizeSshAndVersionOnStart(cmds, profile, internalLbVm, controlNic); // restart network if restartNetwork = false is not specified in profile parameters boolean reprogramGuestNtwk = true; if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean)profile.getParameter(Param.ReProgramGuestNetworks) == false) { reprogramGuestNtwk = false; } final VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId()); if (lbProvider == null) { throw new CloudRuntimeException("Cannot find related element " + Type.InternalLbVm + " of vm: " + internalLbVm.getHostName()); } final Provider provider = Network.Provider.getProvider(lbProvider.getType().toString()); if (provider == null) { throw new CloudRuntimeException("Cannot find related provider of provider: " + lbProvider.getType().toString()); } if (reprogramGuestNtwk) { final NicProfile guestNic = getNicProfileByTrafficType(profile, TrafficType.Guest); finalizeLbRulesForIp(cmds, internalLbVm, provider, new Ip(guestNic.getIPv4Address()), guestNic.getNetworkId()); } return true; }
@Override public void rollbackNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) { for (final NicProfile nicDst : dst.getNics()) { final NetworkVO network = _networksDao.findById(nicDst.getNetworkId()); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NicProfile nicSrc = findNicProfileById(src, nicDst.getId()); final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null); final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null); if (guru instanceof NetworkMigrationResponder) { ((NetworkMigrationResponder)guru).rollbackMigration(nicDst, network, dst, src_context, dst_context); } final List<Provider> providersToImplement = getNetworkProviders(network.getId()); for (final NetworkElement element : networkElements) { if (providersToImplement.contains(element.getProvider())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); } if (element instanceof NetworkMigrationResponder) { ((NetworkMigrationResponder)element).rollbackMigration(nicDst, network, dst, src_context, dst_context); } } } } }
@Override public void commitNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) { for (final NicProfile nicSrc : src.getNics()) { final NetworkVO network = _networksDao.findById(nicSrc.getNetworkId()); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NicProfile nicDst = findNicProfileById(dst, nicSrc.getId()); final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null); final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null); if (guru instanceof NetworkMigrationResponder) { ((NetworkMigrationResponder)guru).commitMigration(nicSrc, network, src, src_context, dst_context); } final List<Provider> providersToImplement = getNetworkProviders(network.getId()); for (final NetworkElement element : networkElements) { if (providersToImplement.contains(element.getProvider())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); } if (element instanceof NetworkMigrationResponder) { ((NetworkMigrationResponder)element).commitMigration(nicSrc, network, src, src_context, dst_context); } } } // update the reservation id final NicVO nicVo = _nicDao.findById(nicDst.getId()); nicVo.setReservationId(nicDst.getReservationId()); _nicDao.persist(nicVo); } }
public SetupGuestNetworkCommand createSetupGuestNetworkCommand(final DomainRouterVO router, final boolean add, final NicProfile guestNic) { final Network network = _networkModel.getNetwork(guestNic.getNetworkId()); String defaultDns1 = null; String defaultDns2 = null; final boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VPCVirtualRouter); final boolean dhcpProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VPCVirtualRouter); final boolean setupDns = dnsProvided || dhcpProvided; if (setupDns) { defaultDns1 = guestNic.getIPv4Dns1(); defaultDns2 = guestNic.getIPv4Dns2(); } final Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId()); final String networkDomain = network.getNetworkDomain(); final String dhcpRange = getGuestDhcpRange(guestNic, network, _entityMgr.findById(DataCenter.class, network.getDataCenterId())); final NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null); final SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, router.getIsRedundantRouter(), defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType())); final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIPv4Address()) | ~NetUtils.ip2Long(guestNic.getIPv4Netmask())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(network.getId(), router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway()); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); if (network.getBroadcastDomainType() == BroadcastDomainType.Vlan) { final long guestVlanTag = Long.parseLong(BroadcastDomainType.Vlan.getValueFrom(network.getBroadcastUri())); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); } return setupCmd; }