@Override public void doInTransactionWithoutResult(final TransactionStatus status) { _nicDao.update(nic.getId(), nic); if (nic.getVmType() == VirtualMachine.Type.User) { s_logger.debug("Changing active number of nics for network id=" + networkId + " on " + count); _networksDao.changeActiveNicsBy(networkId, count); } if (nic.getVmType() == VirtualMachine.Type.User || nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest) { _networksDao.setCheckForGc(networkId); } } });
private NicVO getPlaceholderNic(Network network) { List<NicVO> guestIps = _nicDao.listByNetworkId(network.getId()); for (NicVO guestIp : guestIps) { // only external firewall and external load balancer will create NicVO with PlaceHolder reservation strategy if (guestIp.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && guestIp.getVmType() == null && guestIp.getReserver() == null && !guestIp.getIPv4Address().equals(network.getGateway())) { return guestIp; } } return null; }
if (userNic.getVmType() == VirtualMachine.Type.DomainRouter || userNic.getState() != Nic.State.Reserved) { iterator.remove(); continue;
/** * reassigns the nics to the new network from the src network. * @param srcNetworkId * @param dstNetworkId */ private void assignUserNicsToNewNetwork(long srcNetworkId, long dstNetworkId) { List<NicVO> nics = _nicDao.listByNetworkId(srcNetworkId); for (NicVO nic : nics) { if (nic.getVmType() == VirtualMachine.Type.User) { nic.setNetworkId(dstNetworkId); _nicDao.persist(nic); //update the number of active nics in both networks after migration. if (nic.getState() == Nic.State.Reserved) { _networksDao.changeActiveNicsBy(srcNetworkId, -1); _networksDao.changeActiveNicsBy(dstNetworkId, 1); } } } List<? extends IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(srcNetworkId, null); for (IPAddressVO ipAddress : publicIps) { ipAddress.setAssociatedWithNetworkId(dstNetworkId); _ipAddressDao.persist(ipAddress); } }
@Override public void assignNicsToNewPhysicalNetwork(Network srcNetwork, Network networkInNewPhysicalNet) { List<NicVO> nics = _nicDao.listByNetworkId(srcNetwork.getId()); final CallContext cctx = CallContext.current(); final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount()); final DataCenter dc = _entityMgr.findById(DataCenter.class, networkInNewPhysicalNet.getDataCenterId()); //For each nic in the old network check if the nic belongs to a guest vm and migrate it to the new network. for (NicVO originalNic : nics) { if (originalNic.getVmType() != VirtualMachine.Type.User) { continue; } Transaction.execute((TransactionCallback<Boolean>) (status) -> migrateNicsInDB(originalNic, networkInNewPhysicalNet, dc, context)); } //Now that nics are migrated we can migrate the static nats on those nics reapplyPublicIps(srcNetwork, networkInNewPhysicalNet); }
/** Build VspDhcpVMOption to put on the VM interface */ public VspDhcpVMOption buildVmDhcpOption (NicVO userNic, boolean defaultHasDns, boolean networkHasDns) { VMInstanceVO userVm = _vmInstanceDao.findById(userNic.getInstanceId()); VspDhcpVMOption.Builder vspDhcpVMOptionBuilder = new VspDhcpVMOption.Builder() .nicUuid(userNic.getUuid()) .defaultHasDns(defaultHasDns) .hostname(userVm.getHostName()) .networkHasDns(networkHasDns) .isDefaultInterface(userNic.isDefaultNic()) .domainRouter(VirtualMachine.Type.DomainRouter.equals(userNic.getVmType())); return vspDhcpVMOptionBuilder.build(); }
if (nicVO.getVmType() != VirtualMachine.Type.User) { throw new InvalidParameterValueException(String.format("The NIC [%s] does not belong to a user VM", nicVO.getUuid()));
List<NicVO> nics = _nicDao.listByNetworkId(network.getId()); for (NicVO nic : nics) { if (nic.getVmType() == null && nic.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && nic.getIPv4Address().equals(network.getGateway())) { s_logger.debug("Removing placeholder nic " + nic + " for the network " + network); _nicDao.remove(nic.getId());
to.setUuid(nicVO.getUuid()); if (nicVO.getVmType() != VirtualMachine.Type.User) { to.setPxeDisable(true);
if (nicVO.getVmType() != VirtualMachine.Type.User) { throw new InvalidParameterValueException("The nic is not belongs to user vm");
protected NicTO toNicTO(final NicVO nic, final NicProfile profile, final NetworkVO config) { final NicTO to = new NicTO(); to.setDeviceId(nic.getDeviceId()); to.setBroadcastType(config.getBroadcastDomainType()); to.setType(config.getTrafficType()); to.setIp(nic.getIPv4Address()); to.setNetmask(nic.getIPv4Netmask()); to.setMac(nic.getMacAddress()); to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); if (nic.getIPv4Gateway() != null) { to.setGateway(nic.getIPv4Gateway()); } else { to.setGateway(config.getGateway()); } if (nic.getVmType() != VirtualMachine.Type.User) { to.setPxeDisable(true); } to.setDefaultNic(nic.isDefaultNic()); to.setBroadcastUri(nic.getBroadcastUri()); to.setIsolationuri(nic.getIsolationUri()); if (profile != null) { to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); } final Integer networkRate = _networkModel.getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); to.setUuid(config.getUuid()); return to; }
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ); AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getIPv4Gateway(), Op.EQ); AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ); AllFieldsSearch.and("address", AllFieldsSearch.entity().getIPv4Address(), Op.LIKE); AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ); PeerRouterSearch.and("instanceId", PeerRouterSearch.entity().getInstanceId(), Op.NEQ); PeerRouterSearch.and("macAddress", PeerRouterSearch.entity().getMacAddress(), Op.EQ); PeerRouterSearch.and("vmType", PeerRouterSearch.entity().getVmType(), Op.EQ); PeerRouterSearch.done();