@Override public boolean isSystemDefaultNetwork(NetworkVO net) { if (net.getTrafficType() == TrafficType.Management || net.getTrafficType() == TrafficType.Storage || net.getTrafficType() == TrafficType.Control) { return true; } return false; }
@Override public List<NetworkVO> findSystemNetworks(List<TrafficType> types) { SearchBuilder<NetworkVO> searchBuilder = _networksDao.createSearchBuilder(); searchBuilder.and("trafficType", searchBuilder.entity().getTrafficType(), Op.IN); SearchCriteria<NetworkVO> sc = searchBuilder.create(); if (types == null || types.isEmpty()) { if (net.getTrafficType() == type) { if (!dbNets.contains(net)) { dbNets.add(net);
searchBuilder.and("trafficType", searchBuilder.entity().getTrafficType(), Op.IN); searchBuilder.and("networkOfferingId", searchBuilder.entity().getNetworkOfferingId(), Op.IN); if (net.getTrafficType() == type) { if (!dbNets.contains(net)) { dbNets.add(net);
private void initializeDefaultVirtualNetworkModels() { List<TrafficType> types = new ArrayList<TrafficType>(); types.add(TrafficType.Management); types.add(TrafficType.Storage); types.add(TrafficType.Control); List<NetworkVO> dbNets = findManagedNetworks(types); for (NetworkVO net : dbNets) { VirtualNetworkModel vnModel = getDatabase().lookupVirtualNetwork(null, getCanonicalName(net), net.getTrafficType()); if (vnModel == null) { vnModel = new VirtualNetworkModel(net, null, getCanonicalName(net), net.getTrafficType()); vnModel.build(getModelController(), net); try { if (!vnModel.verify(getModelController())) { vnModel.update(getModelController()); } } catch (Exception ex) { s_logger.warn("virtual-network update: ", ex); } getDatabase().getVirtualNetworks().add(vnModel); } } }
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(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); } } });
new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null, offering.isRedundantRouter()); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2());
@Override public VirtualNetworkModel lookupPublicNetworkModel() { List<TrafficType> types = new ArrayList<TrafficType>(); types.add(TrafficType.Public); List<NetworkVO> dbNets = findManagedNetworks(types); if (dbNets == null) { return null; } NetworkVO net = dbNets.get(0); VirtualNetworkModel vnModel = getDatabase().lookupVirtualNetwork(net.getUuid(), getCanonicalName(net), TrafficType.Public); if (vnModel == null) { vnModel = new VirtualNetworkModel(net, net.getUuid(), getCanonicalName(net), net.getTrafficType()); vnModel.setProperties(getModelController(), net); } try { if (!vnModel.verify(getModelController())) { vnModel.update(getModelController()); } getDatabase().getVirtualNetworks().add(vnModel); } catch (Exception ex) { s_logger.warn("virtual-network update: ", ex); } return vnModel; }
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 createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) throws IOException { syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbNet) + "(" + dbNet.getUuid() + "); VNC: none; action: create\n"); if (_manager.getDatabase().lookupVirtualNetwork(dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()) != null) { s_logger.warn("VN model object is already present in DB: " + dbNet.getUuid() + ", name: " + dbNet.getName()); VirtualNetworkModel vnModel = new VirtualNetworkModel(dbNet, dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()); if (dbNet.getTrafficType() == TrafficType.Guest && dbNet.getNetworkACLId() != null) { NetworkACLVO acl = _networkACLDao.findById(dbNet.getNetworkACLId()); NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
public NetworkVO cidrToNetwork(ModelController controller, String cidr) { SearchBuilder<NetworkVO> searchBuilder = controller.getNetworkDao().createSearchBuilder(); searchBuilder.and("trafficType", searchBuilder.entity().getTrafficType(), Op.EQ); searchBuilder.and("cidr", searchBuilder.entity().getCidr(), Op.EQ); searchBuilder.and("networkOfferingId", searchBuilder.entity().getNetworkOfferingId(), Op.EQ); SearchCriteria<NetworkVO> sc = searchBuilder.create(); sc.setParameters("networkOfferingId", controller.getManager().getVpcRouterOffering().getId()); sc.setParameters("cidr", cidr); sc.setParameters("trafficType", Networks.TrafficType.Guest); List<NetworkVO> dbNets = controller.getNetworkDao().search(sc, null); if (dbNets == null || dbNets.size() == 0) { return null; } if (dbNets.size() > 1) { s_logger.warn("more than one network found with cidr: " + cidr); } return dbNets.get(0); }
public Boolean equalVirtualNetwork(NetworkVO dbn, VirtualNetwork vnet, StringBuffer syncLogMesg) { syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbn) + "; VNC: " + vnet.getName() + "; action: equal\n"); VirtualNetworkModel current = _manager.getDatabase().lookupVirtualNetwork(vnet.getUuid(), _manager.getCanonicalName(dbn), dbn.getTrafficType()); VirtualNetworkModel vnModel = new VirtualNetworkModel(dbn, vnet.getUuid(), _manager.getCanonicalName(dbn), dbn.getTrafficType()); if (dbn.getTrafficType() == TrafficType.Guest && dbn.getNetworkACLId() != null) { NetworkACLVO acl = _networkACLDao.findById(dbn.getNetworkACLId()); NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.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); } }
NicForTrafficTypeSearch.join("network", networkSearch, networkSearch.entity().getId(), NicForTrafficTypeSearch.entity().getNetworkId(), JoinType.INNER); NicForTrafficTypeSearch.and("instance", NicForTrafficTypeSearch.entity().getInstanceId(), Op.EQ); networkSearch.and("traffictype", networkSearch.entity().getTrafficType(), Op.EQ); NicForTrafficTypeSearch.done();
@Override public void finalizeStop(VirtualMachineProfile profile, Answer answer) { VirtualMachine vm = profile.getVirtualMachine(); // release elastic IP here IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { CallContext ctx = CallContext.current(); try { long networkId = ip.getAssociatedWithNetworkId(); Network guestNetwork = _networkDao.findById(networkId); NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId()); assert (offering.isAssociatePublicIP() == true) : "User VM should not have system owned public IP associated with it when offering configured not to associate public IP."; _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true); } catch (Exception ex) { s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex); } } List<NicVO> nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { if (nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); setupVmForPvlan(false, vm.getHostId(), nicProfile); } } } }
@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; }
if (network.getTrafficType() != Networks.TrafficType.Guest) { throw new InvalidParameterValueException("Network ACL can be created just for networks of type " + Networks.TrafficType.Guest);
vmiModel.addToVirtualMachine(this); NetworkVO network = networkDao.findById(nic.getNetworkId()); VirtualNetworkModel vnModel = manager.getDatabase().lookupVirtualNetwork(network.getUuid(), manager.getCanonicalName(network), network.getTrafficType()); assert vnModel != null; vmiModel.addToVirtualNetwork(vnModel);
for (final Nic nic: _nicDao.listByVmId(vmId)) { final NetworkVO nw = _networksDao.findById(nic.getNetworkId()); if (nw.getTrafficType() == TrafficType.Guest) { return _configMgr.getNetworkOfferingNetworkRate(nw.getNetworkOfferingId(), network.getDataCenterId());
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; }