private boolean isIpDedicated(IPAddressVO addr) { List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByVlan(addr.getVlanId()); if (maps != null && !maps.isEmpty()) return true; return false; }
protected Long getPodIdForDirectIp(final IPAddressVO ipAddr) { final PodVlanMapVO podVlanMaps = _podVlanMapDao.listPodVlanMapsByVlan(ipAddr.getVlanId()); if (podVlanMaps == null) { return null; } else { return podVlanMaps.getPodId(); } }
@Override public PublicIpAddress getPublicIpAddress(long ipAddressId) { IPAddressVO addr = _ipAddressDao.findById(ipAddressId); if (addr == null) { return null; } return PublicIp.createFromAddrAndVlan(addr, _vlanDao.findById(addr.getVlanId())); }
public void createFloatingIp(IPAddressVO dbIp, StringBuffer syncLogMesg) throws Exception { if (dbIp.getState() == IpAddress.State.Releasing) { /* Don't need to push releasing ip */ syncLogMesg.append("fip# DB: " + dbIp.getUuid() + ", state releasing, don't create in vnc\n"); return; } syncLogMesg.append("fip# DB: " + dbIp.getAddress().addr() + "; VNC: none; action: create\n"); if (!_manager.createFloatingIp(PublicIp.createFromAddrAndVlan(dbIp, _vlanDao.findById(dbIp.getVlanId())))) { syncLogMesg.append("fip# VNC: " + dbIp.getAddress().addr() + " unable to create\n"); return; } syncLogMesg.append("fip# VNC: " + dbIp.getUuid() + " created\n"); }
@Override public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) { Network network = _networksDao.findById(networkId); if (network == null) { throw new InvalidParameterValueException("Invalid network id is given"); } IPAddressVO ip = _ipAddressDao.findById(ipAddrId); if (ip == null) { throw new InvalidParameterValueException("Invalid network id is given"); } // Check if IP has any services (rules) associated in the network List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>(); PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId())); ipList.add(publicIp); Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true); if (!ipToServices.isEmpty()) { Set<Service> ipServices = ipToServices.get(publicIp); if (ipServices != null && !ipServices.isEmpty()) { return false; } } return true; }
if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId())); publicIps.add(publicIp);
@Override public PublicIpAddress getSourceNatIpAddressForGuestNetwork(Account owner, Network guestNetwork) { List<? extends IpAddress> addrs = listPublicIpsAssignedToGuestNtwk(owner.getId(), guestNetwork.getId(), true); IPAddressVO sourceNatIp = null; if (addrs.isEmpty()) { return null; } else { for (IpAddress addr : addrs) { if (addr.isSourceNat()) { sourceNatIp = _ipAddressDao.findById(addr.getId()); return PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId())); } } } return null; }
/** * Return true if vlan IP range is dedicated for system vms (SSVM and CPVM), false if not * @param vlanId vlan id * @return true if VLAN IP range is dedicated to system vms */ private boolean isForSystemVms(long vlanId){ SearchBuilder<IPAddressVO> sb = userIpAddressDao.createSearchBuilder(); sb.and("vlanId", sb.entity().getVlanId(), SearchCriteria.Op.EQ); SearchCriteria<IPAddressVO> sc = sb.create(); sc.setParameters("vlanId", vlanId); IPAddressVO userIpAddresVO = userIpAddressDao.findOneBy(sc); return userIpAddresVO.isForSystemVms(); }
@Override public PublicIp assignSourceNatIpAddressToVpc(final Account owner, final Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { final long dcId = vpc.getZoneId(); final IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId()); PublicIp ipToReturn = null; if (sourceNatIp != null) { ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId())); } else { ipToReturn = _ipAddrMgr.assignDedicateIpAddress(owner, null, vpc.getId(), dcId, true); } return ipToReturn; }
@Override public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { assert(guestNetwork.getTrafficType() != null) : "You're asking for a source nat but your network " + "can't participate in source nat. What do you have to say for yourself?"; long dcId = guestNetwork.getDataCenterId(); IPAddressVO sourceNatIp = getExistingSourceNatInNetwork(owner.getId(), guestNetwork.getId()); PublicIp ipToReturn = null; if (sourceNatIp != null) { ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId())); } else { ipToReturn = assignDedicateIpAddress(owner, guestNetwork.getId(), null, dcId, true); } return ipToReturn; }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId(); long publicNetworkId = _networkModel.getSystemNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId(); ip.setDataCenterId(dstNetwork.getDataCenterId()); ip.setPhysicalNetworkId(physicalNetworkId); ip.setSourceNetworkId(publicNetworkId); _ipAddressDao.update(ipAddrId, ip); VlanVO vlan = _vlanDao.findById(ip.getVlanId()); vlan.setPhysicalNetworkId(physicalNetworkId); vlan.setNetworkId(publicNetworkId); vlan.setDataCenterId(dstNetwork.getDataCenterId()); _vlanDao.update(ip.getVlanId(), vlan); } });
@Override public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException { List<VspStaticNat> vspStaticNatDetails = new ArrayList<VspStaticNat>(); for (StaticNat staticNat : rules) { IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId()); VlanVO sourceNatVlan = _vlanDao.findById(sourceNatIp.getVlanId()); checkVlanUnderlayCompatibility(sourceNatVlan); if (!staticNat.isForRevoke()) { final List<FirewallRuleVO> firewallRules = _firewallRulesDao.listByIpAndNotRevoked(staticNat.getSourceIpAddressId()); for (FirewallRuleVO firewallRule : firewallRules) { _nuageVspEntityBuilder.buildVspAclRule(firewallRule, config, sourceNatIp); } } NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId()); VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(staticNat.isForRevoke(), sourceNatIp, sourceNatVlan, nicVO); vspStaticNatDetails.add(vspStaticNat); } VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config); ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails); send(cmd, config); return true; }
@Override public IPAddressVO doInTransaction(TransactionStatus status) { if (updateIpResourceCount(ip)) { _resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip); } // Save usage event if (ip.getAllocatedToAccountId() != null && ip.getAllocatedToAccountId() != Account.ACCOUNT_ID_SYSTEM) { VlanVO vlan = _vlanDao.findById(ip.getVlanId()); String guestType = vlan.getVlanType().toString(); if (!isIpDedicated(ip)) { String eventType = ip.isPortable() ? EventTypes.EVENT_PORTABLE_IP_RELEASE : EventTypes.EVENT_NET_IP_RELEASE; UsageEventUtils.publishUsageEvent(eventType, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getSystem(), ip.getClass().getName(), ip.getUuid()); } } return _ipAddressDao.markAsUnavailable(addrId); } });
FloatingIpModel fipModel = new FloatingIpModel(db.getUuid()); fipModel.addToFloatingIpPool(fipPoolModel); fipModel.build(_manager.getModelController(), PublicIp.createFromAddrAndVlan(db, _vlanDao.findById(db.getVlanId()))); try { fipModel.update(_manager.getModelController());
@Override public Boolean doInTransaction(TransactionStatus status) { portableIpLock.lock(5); IPAddressVO ip = _ipAddressDao.findById(addrId); // unassign portable IP PortableIpVO portableIp = _portableIpDao.findByIpAddress(ip.getAddress().addr()); _portableIpDao.unassignIpAddress(portableIp.getId()); // removed the provisioned vlan VlanVO vlan = _vlanDao.findById(ip.getVlanId()); _vlanDao.remove(vlan.getId()); // remove the provisioned public ip address _ipAddressDao.remove(ip.getId()); return true; } });
SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ); IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER); IpAddressSearch.done();
@Override public void doInTransactionWithoutResult(TransactionStatus status) { Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId()); if (_ipAddressDao.lockRow(addr.getId(), true) != null) { final IPAddressVO userIp = _ipAddressDao.findById(addr.getId()); if (userIp.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) { addr.setState(IpAddress.State.Allocated); if (_ipAddressDao.update(addr.getId(), addr)) { // Save usage event if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { VlanVO vlan = _vlanDao.findById(addr.getVlanId()); String guestType = vlan.getVlanType().toString(); if (!isIpDedicated(addr)) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem(), addr.getClass().getName(), addr.getUuid()); } if (updateIpResourceCount(addr)) { _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip); } } } else { s_logger.error("Failed to mark public IP as allocated with id=" + addr.getId() + " address=" + addr.getAddress()); } } } else { s_logger.error("Failed to acquire row lock to mark public IP as allocated with id=" + addr.getId() + " address=" + addr.getAddress()); } } });
PodVlanMapVO mapVO = _podVlanDao.listPodVlanMapsByVlan(ipVO.getVlanId()); if (mapVO.getPodId() != dest.getPod().getId()) { Transaction.execute(new TransactionCallbackNoReturn() {
if (placeholderNic != null) { IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIPv4Address()); ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId())); s_logger.debug("Nic got an ip address " + placeholderNic.getIPv4Address() + " stored in placeholder nic for the network " + network);
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(); }