@Override public boolean prepareMigration( final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) { if (!canHandle(network, Service.Connectivity)) { return false; } if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) { return false; } if (nic.getTrafficType() != Networks.TrafficType.Guest) { return false; } if (vm.getType() != VirtualMachine.Type.User && vm.getType() != VirtualMachine.Type.DomainRouter) { return false; } // prepare the tunnel network on the host, in order for VM to get launched _ovsTunnelMgr.checkAndPrepareHostForTunnelNetwork(network, dest.getHost()); return true; }
@Override public void reserve( NicProfile nic, Network config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert nic.getTrafficType() == TrafficType.Control; if (dest.getHost().getHypervisorType() == HypervisorType.VmWare && vm.getType() == VirtualMachine.Type.DomainRouter) { super.reserve(nic, config, vm, dest, context); String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); nic.setMacAddress(mac); return; } String ip = _dcDao.allocateLinkLocalIpAddress( dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId()); nic.setIp4Address(ip); nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40))); nic.setNetmask("255.255.0.0"); nic.setFormat(AddressFormat.Ip4); nic.setGateway(NetUtils.getLinkLocalGateway()); }
/** * @param networks * @param offerings * @throws ConcurrentOperationException */ private void mockMgrs() throws ConcurrentOperationException { final Service service = Service.Connectivity; testNetwork.setState(Network.State.Implementing); testNetwork.setTrafficType(TrafficType.Guest); when(_networkMdl.isProviderEnabledInPhysicalNetwork(0L, "VirtualRouter")).thenReturn(true); when(_networkMdl.isProviderSupportServiceInNetwork( testNetwork.getId(), service, Network.Provider.VirtualRouter)) .thenReturn(true); when(_networkMdl.isProviderForNetwork(Network.Provider.VirtualRouter, 0L)).thenReturn(true); when(testVMProfile.getType()).thenReturn(VirtualMachine.Type.User); when(testVMProfile.getHypervisorType()).thenReturn(HypervisorType.XenServer); final List<NetworkVO> networks = new ArrayList<NetworkVO>(1); networks.add(testNetwork); final List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(1); offerings.add(testOffering); doReturn(offerings) .when(_networkModel) .getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); doReturn(networks) .when(_networkMgr) .setupNetwork( any(Account.class), any(NetworkOffering.class), any(DeploymentPlan.class), any(String.class), any(String.class), anyBoolean()); // being anti-social and testing my own case first doReturn(HypervisorType.XenServer).when(_resourceMgr).getDefaultHypervisor(anyLong()); doReturn(new AccountVO()).when(_accountMgr).getAccount(testNetwork.getAccountId()); }
@Override public boolean release( NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) { assert nic.getTrafficType() == TrafficType.Control; if (vm.getHypervisorType() == HypervisorType.VmWare && vm.getType() == VirtualMachine.Type.DomainRouter) { super.release(nic, vm, reservationId); return true; } _dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId); nic.setIp4Address(null); nic.setMacAddress(null); nic.setNetmask(null); nic.setFormat(null); nic.setGateway(null); return true; }
@Override public boolean prepare( Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (vm.getType() != Type.User) { return false; } // ensure that there is an ASA 1000v assigned to this network NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId()); if (asaForNetwork == null) { return false; } return true; }
@Override public NicProfile allocate( Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (config.getTrafficType() != TrafficType.Control) { return null; } if (vm.getHypervisorType() == HypervisorType.VmWare && vm.getType() != VirtualMachine.Type.DomainRouter) { NicProfile nicProf = new NicProfile(ReservationStrategy.Create, null, null, null, null); String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); nicProf.setMacAddress(mac); return nicProf; } if (nic != null) { throw new CloudRuntimeException("Does not support nic specification at this time: " + nic); } return new NicProfile(ReservationStrategy.Start, null, null, null, null); }