@Override public Long getAssociatedWithNetworkId() { return _addr.getAssociatedWithNetworkId(); }
protected boolean updateIpResourceCount(IPAddressVO ip) { // don't increment resource count for direct and dedicated ip addresses return (ip.getAssociatedWithNetworkId() != null || ip.getVpcId() != null) && !isIpDedicated(ip); }
if (ip.getAssociatedWithNetworkId() != null) { Network network = _networksDao.findById(ip.getAssociatedWithNetworkId()); try { if (!applyIpAssociations(network, rulesContinueOnErrFlag)) {
if (ipAddress.getAssociatedWithNetworkId() == null) { throw new InvalidParameterValueException("Unable to create firewall rule ; ip with specified id is not associated with any network"); } else { networkId = ipAddress.getAssociatedWithNetworkId();
@Override public List<IPAddressVO> findManagedPublicIps() { List<NetworkVO> dbNets = findManagedNetworks(null); if (dbNets == null || dbNets.isEmpty()) { s_logger.debug("Juniper managed networks is empty"); return null; } SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder(); searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ); searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.IN); searchBuilder.and("oneToOneNat", searchBuilder.entity().isOneToOneNat(), Op.EQ); searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NNULL); List<Long> netIds = new ArrayList<Long>(); for (NetworkVO net : dbNets) { netIds.add(net.getId()); } SearchCriteria<IPAddressVO> sc = searchBuilder.create(); sc.setParameters("oneToOneNat", true); sc.setParameters("sourceNat", false); sc.setParameters("network", netIds.toArray()); List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null); if (publicIps == null) { s_logger.debug("no public ips"); return null; } return publicIps; }
long networkId = ipAddress.getAssociatedWithNetworkId();
if (ipToAssoc != null) { if (ipToAssoc.getAssociatedWithNetworkId() == null) { throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with any network"); if (ipToAssoc.getAssociatedWithNetworkId() != network.getId()) { throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with network id" + networkId);
final Long networkId = ipAddr.getAssociatedWithNetworkId(); if (networkId == null) { InvalidParameterValueException ex =
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ); IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ); SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
@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); } } } }
Long networkId = ipVO.getAssociatedWithNetworkId(); if (networkId != null) { Network guestNetwork = getNetwork(networkId);
if (ipVO.getAssociatedWithNetworkId() == null) { boolean assignToVpcNtwk = network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId(); if (assignToVpcNtwk) { if (ipVO.getAssociatedWithNetworkId() == null) { throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
Long networkId = oldIP.getAssociatedWithNetworkId(); VMInstanceVO vm = _vmInstanceDao.findById(vmId);
assert ipAddrVO != null : "can not find address object in db"; Long vmId = ipAddrVO.getAssociatedWithVmId(); Long networkId = ipAddrVO.getAssociatedWithNetworkId(); if (vmId == null || networkId == null) { s_logger.debug("Floating ip is not yet associated to either vm or network");
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ); IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ); final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
@Override @ActionEvent(eventType = EventTypes.EVENT_DISABLE_STATIC_NAT, eventDescription = "disabling static nat", async = true) public boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException { CallContext ctx = CallContext.current(); Account caller = ctx.getCallingAccount(); IPAddressVO ipAddress = _ipAddressDao.findById(ipId); checkIpAndUserVm(ipAddress, null, caller, false); if (ipAddress.getSystem()) { InvalidParameterValueException ex = new InvalidParameterValueException("Can't disable static nat for system IP address with specified id"); ex.addProxyObject(ipAddress.getUuid(), "ipId"); throw ex; } Long vmId = ipAddress.getAssociatedWithVmId(); if (vmId == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Specified IP address id is not associated with any vm Id"); ex.addProxyObject(ipAddress.getUuid(), "ipId"); throw ex; } // if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to // re-enable it on the new one enable static nat takes care of that Network guestNetwork = _networkModel.getNetwork(ipAddress.getAssociatedWithNetworkId()); NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId()); if (offering.isElasticIp()) { if (offering.isAssociatePublicIP()) { getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true); return true; } } return disableStaticNat(ipId, caller, ctx.getCallingUserId(), false); }
public VspAclRule buildVspAclRule(FirewallRule firewallRule, Network network, IPAddressVO staticNat) { VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder() .uuid(firewallRule.getUuid()) .protocol(firewallRule.getProtocol()) .startPort(firewallRule.getSourcePortStart()) .endPort(firewallRule.getSourcePortEnd()) .sourceCidrList(firewallRule.getSourceCidrList()) .priority(-1) .type(VspAclRule.ACLType.Firewall) .state(getEnumValue(firewallRule.getState(), VspAclRule.ACLState.class)) .trafficType(getEnumValue(firewallRule.getTrafficType(), VspAclRule.ACLTrafficType.class)); NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId()); if (firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress && networkOffering.isEgressDefaultPolicy()) { vspAclRuleBuilder.deny(); } else { vspAclRuleBuilder.allow(); } if (staticNat == null && firewallRule.getSourceIpAddressId() != null) { IPAddressVO staticNatIp = _ipAddressDao.findById(firewallRule.getSourceIpAddressId()); if (staticNatIp != null) { VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId()); NicVO nic = _nicDao.findByIp4AddressAndNetworkId(staticNatIp.getVmIp(), staticNatIp.getAssociatedWithNetworkId()); vspAclRuleBuilder.staticNat(buildVspStaticNat(null, staticNatIp, staticNatVlan, nic)); } } return vspAclRuleBuilder.build(); }
FirewallRuleType.User, null, rule.getTrafficType()); final Long networkId = ipAddress.getAssociatedWithNetworkId(); final Long accountId = ipAddress.getAllocatedToAccountId(); final Long domainId = ipAddress.getAllocatedInDomainId();
networkId = ipAddress.getAssociatedWithNetworkId(); if (networkId != null) { _networkMgr.checkIpForService(ipAddress, Service.Vpn, null);
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAllocatedToAccountId(), Op.EQ); AllFieldsSearch.and("sourceNat", AllFieldsSearch.entity().isSourceNat(), Op.EQ); AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ); AllFieldsSearch.and("associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ); AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ); AllocatedIpCountForAccount.and("account", AllocatedIpCountForAccount.entity().getAllocatedToAccountId(), Op.EQ); AllocatedIpCountForAccount.and("allocated", AllocatedIpCountForAccount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCountForAccount.and().op("network", AllocatedIpCountForAccount.entity().getAssociatedWithNetworkId(), Op.NNULL); AllocatedIpCountForAccount.or("vpc", AllocatedIpCountForAccount.entity().getVpcId(), Op.NNULL); AllocatedIpCountForAccount.cp();AllocatedIpCountForAccount.done();