private Long getDefaultNetwork(long vmId) { NicVO defaultNic = _nicDao.findDefaultNicForVM(vmId); if (defaultNic != null) return defaultNic.getNetworkId(); return null; } }
private boolean isLastNicInSubnet(final NicVO nic) { if (_nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getIPv4Gateway(), nic.getBroadcastUri()).size() > 1) { return false; } return true; }
private NicVO findDefaultDnsIp(final long userVmId) { final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId); // check if DNS provider is the domR if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) { return null; } final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId()); if (offering.isRedundantRouter()) { return findGatewayIp(userVmId); } final DataCenter dc = _dcDao.findById(_networkModel.getNetwork(defaultNic.getNetworkId()).getDataCenterId()); final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic; // find domR's nic in the network NicVO domrDefaultNic; if (isZoneBasic) { domrDefaultNic = _nicDao.findByNetworkIdTypeAndGateway(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter, defaultNic.getIPv4Gateway()); } else { domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter); } return domrDefaultNic; }
public VspNic buildVspNic(NicVO nic) { return buildVspNic(nic.getUuid(), nic.getMacAddress(), nic.getIPv4Address(), nic.getNetworkId(), null); }
public VspNic buildVspNic(NicVO nic, NicSecondaryIpVO nicSecondaryIp) { return buildVspNic(nic.getUuid(), nic.getMacAddress(), nic.getIPv4Address(), nic.getNetworkId(), nicSecondaryIp); }
private void generateNetworkUsageForVm(VirtualMachine vm, boolean isDisplay, String eventType){ List<NicVO> nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); long isDefault = (nic.isDefaultNic()) ? 1 : 0; UsageEventUtils.publishUsageEvent(eventType, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, vm.getClass().getName(), vm.getUuid(), isDisplay); } }
protected String getInternalLbControlIp(final long internalLbVmId) { String controlIpAddress = null; final List<NicVO> nics = _nicDao.listByVmId(internalLbVmId); for (final NicVO nic : nics) { final Network ntwk = _ntwkModel.getNetwork(nic.getNetworkId()); if (ntwk.getTrafficType() == TrafficType.Control) { controlIpAddress = nic.getIPv4Address(); } } if (controlIpAddress == null) { s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId); final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId); return internalLbVm.getPrivateIpAddress(); } return controlIpAddress; }
@Override public void prepare(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { final List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId()); // we have to implement default nics first - to ensure that default network elements start up first in multiple //nics case // (need for setting DNS on Dhcp to domR's Ip4 address) Collections.sort(nics, new Comparator<NicVO>() { @Override public int compare(final NicVO nic1, final NicVO nic2) { final boolean isDefault1 = nic1.isDefaultNic(); final boolean isDefault2 = nic2.isDefaultNic(); return isDefault1 ^ isDefault2 ? isDefault1 ^ true ? 1 : -1 : 0; } }); for (final NicVO nic : nics) { final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter); if (implemented == null || implemented.first() == null) { s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId()); } final NetworkVO network = implemented.second(); final NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network); vmProfile.addNic(profile); } }
@DB @Override public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException { final VMInstanceVO vmInstance = _vmDao.findById(vm.getId()); final DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId()); if (dc.getNetworkType() == NetworkType.Basic) { final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId()); final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId()); final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>(); profiles.put(network, new ArrayList<NicProfile>()); Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException { cleanupNics(vm); allocate(vm, profiles, null); } }); } return true; }
public String getRouterControlIp(final long routerId) { String routerControlIpAddress = null; final List<NicVO> nics = nicDao.listByVmId(routerId); for (final NicVO n : nics) { final NetworkVO nc = networkDao.findById(n.getNetworkId()); if (nc != null && nc.getTrafficType() == TrafficType.Control) { routerControlIpAddress = n.getIPv4Address(); // router will have only one control ip break; } } if (routerControlIpAddress == null) { logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId); final DomainRouterVO router = routerDao.findById(routerId); return router.getPrivateIpAddress(); } return routerControlIpAddress; }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { final UserVmVO vm = _vmDao.findById(vmProfile.getId()); final List<NicVO> nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { Network network = _networkModel.getNetwork(nic.getNetworkId()); if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { vmIdCountMap.put(nic.getId(), new VmAndCountDetails(nic.getInstanceId(), VmIpFetchTrialMax.value())); } } } });
private String getRouterControlIP(DomainRouterVO router){ final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); String controlIP = null; if(router.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic ){ final List<NicVO> nics = _nicDao.listByVmId(router.getId()); for (final NicVO nic : nics) { final NetworkVO nc = _networkDao.findById(nic.getNetworkId()); if (nc.getTrafficType() == TrafficType.Guest && nic.getIPv4Address() != null) { controlIP = nic.getIPv4Address(); break; } } s_logger.debug("Vmware with Basic network selected Guest NIC ip as control IP " + controlIP ); }else{ controlIP = _routerControlHelper.getRouterControlIp(router.getId()); } s_logger.debug("IP of control NIC " + controlIP ); return controlIP; }
public void setProperties(ModelController controller, VMInstanceVO instance, NicVO nic) throws IOException { _vmName = instance.getInstanceName(); _deviceId = nic.getDeviceId(); Network network = controller.getNetworkDao().findById(nic.getNetworkId()); switch (nic.getState()) { case Allocated: case Reserved: _nicActive = true; break; default: _nicActive = false; break; } switch (network.getState()) { case Implemented: case Setup: _netActive = true; break; default: _netActive = false; break; } assert _vnModel != null; _networkId = _vnModel.getUuid(); }
private void buildNicResources(VirtualMachineModel vmModel, VMInstanceVO dbVm, StringBuffer syncLogMsg) throws IOException { List<NicVO> nics = _nicDao.listByVmId(dbVm.getId()); for (NicVO nic : nics) { VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid()); if (vmiModel == null) { vmiModel = new VMInterfaceModel(nic.getUuid()); NetworkVO network = _networksDao.findById(nic.getNetworkId()); VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); if (vnModel == null) { s_logger.warn("Unable to locate virtual-network for network id " + network.getId()); continue; } vmiModel.addToVirtualMachine(vmModel); vmiModel.addToVirtualNetwork(vnModel); } vmiModel.build(_manager.getModelController(), dbVm, nic); } }
public void createVmDataCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final String publicKey, final Commands cmds) { final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); final String zoneName = _dcDao.findById(router.getDataCenterId()).getName(); cmds.addCommand( "vmdata", generateVmDataCommand(router, nic.getIPv4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIPv4Address(), vm.getHostName(), vm.getInstanceName(), vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId())); }
public void createPasswordCommand(final VirtualRouter router, final VirtualMachineProfile profile, final NicVO nic, final Commands cmds) { final String password = (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); // password should be set only on default network element if (password != null && nic.isDefaultNic()) { final SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("password", cmd); } }
@Override public List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types) { if (NetworkTypeSearch == null) { SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder(); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); NetworkTypeSearch = createSearchBuilder(); NetworkTypeSearch.and("types", NetworkTypeSearch.entity().getType(), SearchCriteria.Op.IN); NetworkTypeSearch.and("removed", NetworkTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL); NetworkTypeSearch.join("nicSearch", nicSearch, NetworkTypeSearch.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); NetworkTypeSearch.done(); } SearchCriteria<VMInstanceVO> sc = NetworkTypeSearch.create(); if (types != null && types.length != 0) { sc.setParameters("types", (Object[])types); } sc.setJoinParameters("nicSearch", "networkId", networkId); return listBy(sc); }
/** * Recreates UserVmSearch depending on network type, as nics on L2 networks have no ip addresses * @param network network */ private void recreateUserVmSeach(NetworkVO network) { if (network != null) { SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder(); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); nicSearch.and("removed", nicSearch.entity().getRemoved(), SearchCriteria.Op.NULL); if (!Network.GuestType.L2.equals(network.getGuestType())) { nicSearch.and().op("ip4Address", nicSearch.entity().getIPv4Address(), SearchCriteria.Op.NNULL); nicSearch.or("ip6Address", nicSearch.entity().getIPv6Address(), SearchCriteria.Op.NNULL); nicSearch.cp(); } UserVmSearch = createSearchBuilder(); UserVmSearch.and("states", UserVmSearch.entity().getState(), SearchCriteria.Op.IN); UserVmSearch.join("nicSearch", nicSearch, UserVmSearch.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); UserVmSearch.done(); } }
@Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { UserVmVO userVm = _vmDao.findById(profile.getId()); List<NicVO> nics = _nicDao.listByVmId(userVm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest || network.getTrafficType() == TrafficType.Public) { userVm.setPrivateIpAddress(nic.getIPv4Address()); userVm.setPrivateMacAddress(nic.getMacAddress()); _vmDao.update(userVm.getId(), userVm); } } List<VolumeVO> volumes = _volsDao.findByInstance(userVm.getId()); VmDiskStatisticsVO diskstats = null; for (VolumeVO volume : volumes) { diskstats = _vmDiskStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId()); if (diskstats == null) { diskstats = new VmDiskStatisticsVO(userVm.getAccountId(), userVm.getDataCenterId(), userVm.getId(), volume.getId()); _vmDiskStatsDao.persist(diskstats); } } finalizeCommandsOnStart(cmds, profile); return true; }
public void createDhcpEntryCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final Commands cmds) { final DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), vm.getHostName(), nic.getIPv6Address(), _networkModel.getExecuteInSeqNtwkElmtCmd()); String gatewayIp = nic.getIPv4Gateway(); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); dhcpCommand.setDefaultRouter(gatewayIp); dhcpCommand.setIp6Gateway(nic.getIPv6Gateway()); String ipaddress = null; final NicVO domrDefaultNic = findDefaultDnsIp(vm.getId()); if (domrDefaultNic != null) { ipaddress = domrDefaultNic.getIPv4Address(); } dhcpCommand.setDefaultDns(ipaddress); dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress())); dhcpCommand.setDefault(nic.isDefaultNic()); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId())); dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("dhcp", dhcpCommand); }