public Ip getVmSecondaryIp() { if (vmSecondaryIp == null) { return null; } return new Ip(vmSecondaryIp); }
public Ip getVmGuestIp() { if (vmGuestIp == null) { return null; } return new Ip(vmGuestIp); }
/** * Gets source ip address based on the LB rule scheme/source IP network/requested IP address * @param scheme * @param sourceIpNtwk * @param requestedIp * @return * @throws InsufficientVirtualNetworkCapacityException */ protected Ip getSourceIp(Scheme scheme, Network sourceIpNtwk, String requestedIp) throws InsufficientVirtualNetworkCapacityException { if (requestedIp != null) { if (_lbDao.countBySourceIp(new Ip(requestedIp), sourceIpNtwk.getId()) > 0) { s_logger.debug("IP address " + requestedIp + " is already used by existing LB rule, returning it"); return new Ip(requestedIp); } validateRequestedSourceIpForLbRule(sourceIpNtwk, new Ip(requestedIp), scheme); } requestedIp = allocateSourceIpForLbRule(scheme, sourceIpNtwk, requestedIp); if (requestedIp == null) { throw new InsufficientVirtualNetworkCapacityException("Unable to acquire IP address for network " + sourceIpNtwk, Network.class, sourceIpNtwk.getId()); } return new Ip(requestedIp); }
@Override public Map<Ip, UserVm> getLbInstances(long lbId) { Map<Ip, UserVm> dstList = new HashMap<Ip, UserVm>(); List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(lbId); LoadBalancerVO lb = _lbDao.findById(lbId); for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) { UserVm vm = _vmDao.findById(lbVmMap.getInstanceId()); Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(lb.getNetworkId(), vm.getId()); Ip ip = new Ip(nic.getIPv4Address()); dstList.put(ip, vm); } return dstList; }
if (serverPublicIP != null && !_publicIPAddressDao.mark(dc.getId(), new Ip(serverPublicIP))) {
protected boolean implementInternalLbVms(Network network, DeployDestination dest) throws ResourceUnavailableException { //1) Get all the Ips from the network having LB rules assigned List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal); //2) Start internal lb vms for the ips having active rules for (String ip : ips) { Ip sourceIp = new Ip(ip); long active = _appLbDao.countActiveBySourceIp(sourceIp, network.getId()); if (active > 0) { s_logger.debug("Have to implement internal lb vm for source ip " + sourceIp + " as a part of network " + network + " implement as there are " + active + " internal lb rules exist for this ip"); List<? extends VirtualRouter> internalLbVms; try { internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null); } catch (InsufficientCapacityException e) { s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); return false; } catch (ConcurrentOperationException e) { s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); return false; } if (internalLbVms == null || internalLbVms.isEmpty()) { throw new ResourceUnavailableException("Can't deploy " + getName() + " to handle LB rules", DataCenter.class, network.getDataCenterId()); } } } return true; }
@Test public void testStart() { Ip min = new Ip(0); assertEquals("Minimal address not created", "0.0.0.0", min.addr()); }
@Test public void testUltimate() { Ip max = new Ip(2L * Integer.MAX_VALUE +1 ); assertEquals("Maximal address not created", "255.255.255.255", max.addr()); } @Test
IPAddressVO ipaddr = new IPAddressVO(new Ip(allocatedPortableIp.getAddress()), dcId, networkId, vpcID, physicalNetworkId, network.getId(), vlan.getId(), true); ipaddr.setState(State.Allocated); ipaddr.setAllocatedTime(new Date());
@Override public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) { final DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); final NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control); if (controlNic == null) { s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm); return false; } finalizeSshAndVersionOnStart(cmds, profile, internalLbVm, controlNic); // restart network if restartNetwork = false is not specified in profile parameters boolean reprogramGuestNtwk = true; if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean)profile.getParameter(Param.ReProgramGuestNetworks) == false) { reprogramGuestNtwk = false; } final VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId()); if (lbProvider == null) { throw new CloudRuntimeException("Cannot find related element " + Type.InternalLbVm + " of vm: " + internalLbVm.getHostName()); } final Provider provider = Network.Provider.getProvider(lbProvider.getType().toString()); if (provider == null) { throw new CloudRuntimeException("Cannot find related provider of provider: " + lbProvider.getType().toString()); } if (reprogramGuestNtwk) { final NicProfile guestNic = getNicProfileByTrafficType(profile, TrafficType.Guest); finalizeLbRulesForIp(cmds, internalLbVm, provider, new Ip(guestNic.getIPv4Address()), guestNic.getNetworkId()); } return true; }
_ipAddressDao.mark(network.getDataCenterId(), new Ip(vspNetwork.getVirtualRouterIp())); } else if (VirtualMachine.Type.User.equals(vm.getType()) && nic.getIPv4Address().equals(vspNetwork.getVirtualRouterIp())) { s_logger.error("Deploying a user VM with the same IP as the VR is not allowed.");
throw new InvalidParameterValueException("Vm doesn't belong to network associated with ipAddress"); } else { dstIp = new Ip(guestNic.getIPv4Address());
throw new InvalidParameterValueException("Vm doesn't belong to network associated with ipAddress"); } else { dstIp = new Ip(guestNic.getIPv4Address());
long ipMask = getIpMask(pfRule.getDestinationIpAddress().addr(), cidrSize); String maskedDestinationIpAddress = NetUtils.long2Ip(newCidrAddress | ipMask); pfRule.setDestinationIpAddress(new Ip(maskedDestinationIpAddress)); _pfRulesDao.update(pfRule.getId(), pfRule);