/** * When a VM is stopped this API is called to release transient resources. */ @Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { s_logger.debug("release NicProfile " + nic.getId()); return true; }
private NicProfile findNicProfileById(final VirtualMachineProfile vm, final long id) { for (final NicProfile nic : vm.getNics()) { if (nic.getId() == id) { return nic; } } return null; }
@Override public void updateNicProfile(NicProfile profile, Network network) { // TODO Auto-generated method stub s_logger.debug("update NicProfile " + profile.getId() + " on " + network.getName()); }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { _dcDao.releasePrivateIpAddress(nic.getId(), nic.getReservationId()); nic.deallocate(); if (s_logger.isDebugEnabled()) { s_logger.debug("Released nic: " + nic); } return true; }
@Override public List<SspUuidVO> listUUidVoByNicProfile(NicProfile nicProfile) { SearchCriteria<SspUuidVO> cs = native2uuid.create(); cs.setParameters("obj_class", SspUuidVO.objClassNicProfile); cs.setParameters("obj_id", nicProfile.getId()); return listBy(cs); }
@Override public String findUuidByNicProfile(NicProfile nicProfile) { SearchCriteria<SspUuidVO> cs = native2uuid.create(); cs.setParameters("obj_class", SspUuidVO.objClassNicProfile); cs.setParameters("obj_id", nicProfile.getId()); SspUuidVO vo = findOneBy(cs); if (vo != null) { return vo.getUuid(); } return null; }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { assert nic.getTrafficType() == TrafficType.Control; HypervisorType hType = vm.getHypervisorType(); if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) { long dcId = vm.getVirtualMachine().getDataCenterId(); DataCenterVO dcVo = _dcDao.findById(dcId); if (dcVo.getNetworkType() != NetworkType.Basic) { super.release(nic, vm, reservationId); if (s_logger.isDebugEnabled()) { s_logger.debug("Released nic: " + nic); } return true; } else { nic.deallocate(); if (s_logger.isDebugEnabled()) { s_logger.debug("Released nic: " + nic); } return true; } } _dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId); nic.deallocate(); if (s_logger.isDebugEnabled()) { s_logger.debug("Released nic: " + nic); } return true; }
@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 accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); // for basic zone, send vm data/password information only to the router in the same pod NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); nicVo = nicDao.findById(nic.getId()); return visitor.visit(this); }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getId()); userVmDao.loadDetails(_userVM); //for basic zone, send vm data/password information only to the router in the same pod NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); return visitor.visit(this); }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getId()); userVmDao.loadDetails(_userVM); NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); return visitor.visit(this); }
@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; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getVirtualMachine().getId()); userVmDao.loadDetails(_userVM); // for basic zone, send vm data/password information only to the router in the same pod NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); return visitor.visit(this); }
@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; }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getVirtualMachine().getId()); userVmDao.loadDetails(_userVM); NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); // for basic zone, send vm data/password information only to the router in the same pod VMTemplateDao templateDao = visitor.getVirtualNetworkApplianceFactory().getTemplateDao(); _template = templateDao.findByIdIncludingRemoved(_profile.getTemplateId()); return visitor.visit(this); }
@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); } }
@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 reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { Pod pod = dest.getPod(); boolean forSystemVms = vm.getType().equals(VirtualMachine.Type.ConsoleProxy) || vm.getType().equals(VirtualMachine.Type.SecondaryStorageVm); PrivateAllocationData result = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId(), forSystemVms); if (result == null) { throw new InsufficientAddressCapacityException("Unable to get a management ip address", Pod.class, pod.getId()); } Integer vlan = result.getVlan(); nic.setIPv4Address(result.getIpAddress()); nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(result.getMacAddress(), NetworkModel.MACIdentifier.value()))); nic.setIPv4Gateway(pod.getGateway()); nic.setFormat(AddressFormat.Ip4); String netmask = NetUtils.getCidrNetmask(pod.getCidrSize()); nic.setIPv4Netmask(netmask); nic.setBroadcastType(BroadcastDomainType.Native); if (vlan != null) { nic.setBroadcastUri(BroadcastDomainType.Native.toUri(vlan)); } else { nic.setBroadcastUri(null); } nic.setIsolationUri(null); s_logger.debug("Allocated a nic " + nic + " for " + vm); }
String ip = _dcDao.allocateLinkLocalIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId()); if (ip == null) { throw new InsufficientAddressCapacityException("Insufficient link local address capacity", DataCenter.class, dest.getDataCenter().getId());