@Override public IpAddress getIp(long ipAddressId) { return _ipAddressDao.findById(ipAddressId); }
@Override public IpAddress getIp(long ipAddressId) { return _ipAddressDao.findById(ipAddressId); }
public static IPAddressVO findIpAddressById(long addressId) { return s_ipAddressDao.findById(addressId); }
/** * Get the list of public IPs that need to be applied for a static NAT enable/disable operation. * Manipulating only these ips prevents concurrency issues when disabling static nat at the same time. * @param staticNats * @return The list of IPs that need to be applied for the static NAT to work. */ public List<IPAddressVO> getStaticNatSourceIps(List<? extends StaticNat> staticNats) { List<IPAddressVO> userIps = new ArrayList<>(); for (StaticNat snat : staticNats) { userIps.add(_ipAddressDao.findById(snat.getSourceIpAddressId())); } return userIps; }
protected boolean applyStaticNatForIp(long sourceIpId, boolean continueOnError, Account caller, boolean forRevoke) { IpAddress sourceIp = _ipAddressDao.findById(sourceIpId); List<StaticNat> staticNats = createStaticNatForIp(sourceIp, caller, forRevoke); if (staticNats != null && !staticNats.isEmpty()) { try { if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, forRevoke)) { return false; } } catch (ResourceUnavailableException ex) { s_logger.warn("Failed to create static nat rule due to ", ex); return false; } } return true; }
@Override public PublicIpAddress getPublicIpAddress(long ipAddressId) { IPAddressVO addr = _ipAddressDao.findById(ipAddressId); if (addr == null) { return null; } return PublicIp.createFromAddrAndVlan(addr, _vlanDao.findById(addr.getVlanId())); }
private void releaseIp(final long ipId, final long userId, final Account caller) { s_logger.info("ELB: Release public IP for loadbalancing " + ipId); final IPAddressVO ipvo = _ipAddressDao.findById(ipId); ipvo.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipvo.getId(), ipvo); _ipAddrMgr.disassociatePublicIpAddress(ipId, userId, caller); _ipAddressDao.unassignIpAddress(ipId); }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { final IPAddressVO ip = _ipAddressDao.findById(ipId); // update ip address with networkId ip.setVpcId(vpcId); ip.setSourceNat(isSourceNatFinal); _ipAddressDao.update(ipId, ip); // mark ip as allocated _ipAddrMgr.markPublicIpAsAllocated(ip); } });
@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; }
protected boolean handleSystemLBIpRelease(LoadBalancerVO lb) { IpAddress ip = _ipAddressDao.findById(lb.getSourceIpAddressId()); boolean success = true; if (ip.getSystem()) { s_logger.debug("Releasing system ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule"); if (!_ipAddrMgr.disassociatePublicIpAddress(lb.getSourceIpAddressId(), CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount())) { s_logger.warn("Unable to release system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); success = false; } else { s_logger.warn("Successfully released system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); } } return success; }
@Override public PublicIp doInTransaction(final TransactionStatus status) throws InsufficientAddressCapacityException { final Network frontEndNetwork = _networkModel.getNetwork(guestNetworkId); final PublicIp ip = _ipAddrMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true, false); final IPAddressVO ipvo = _ipAddressDao.findById(ip.getId()); ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId()); _ipAddressDao.update(ipvo.getId(), ipvo); s_logger.info("Acquired frontend IP for ELB " + ip); return ip; } });
@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; }
@Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_UPDATE, eventDescription = "updating public ip address", async = true) public IpAddress updateIP(Long id, String customId, Boolean displayIp) { Account caller = CallContext.current().getCallingAccount(); IPAddressVO ipVO = _ipAddressDao.findById(id); if (ipVO == null) { throw new InvalidParameterValueException("Unable to find ip address by id"); } // verify permissions if (ipVO.getAllocatedToAccountId() != null) { _accountMgr.checkAccess(caller, null, true, ipVO); } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { throw new PermissionDeniedException("Only Root admin can update non-allocated ip addresses"); } if (customId != null) { ipVO.setUuid(customId); } if (displayIp != null) { ipVO.setDisplay(displayIp); } _ipAddressDao.update(id, ipVO); return _ipAddressDao.findById(id); }
@Override public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException { final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn); if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) { s_logger.error("try to start site 2 site vpn on unsupported network element?"); return false; } final Long vpcId = ip.getVpcId(); final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId()); } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId()); if (routers == null) { throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId()); } boolean result = true; for (final DomainRouterVO domainRouterVO : routers) { result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO); } return result; }
@Override public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException { final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn); if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) { s_logger.error("try to stop site 2 site vpn on unsupported network element?"); return false; } final Long vpcId = ip.getVpcId(); final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId()); } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId()); if (routers == null) { throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId()); } boolean result = true; for (final DomainRouterVO domainRouterVO : routers) { result = result && _vpcRouterMgr.stopSite2SiteVpn(conn, domainRouterVO); } return result; }
@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); } });
@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; } });
@Override public boolean checkIpForService(IpAddress userIp, Service service, Long networkId) { if (networkId == null) { networkId = userIp.getAssociatedWithNetworkId(); } NetworkVO network = _networksDao.findById(networkId); NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); if (offering.getGuestType() != GuestType.Isolated) { return true; } IPAddressVO ipVO = _ipAddressDao.findById(userIp.getId()); PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipVO, _vlanDao.findById(userIp.getVlanId())); if (!canIpUsedForService(publicIp, service, networkId)) { return false; } if (!offering.isConserveMode()) { return canIpUsedForNonConserveService(publicIp, service); } return true; }
@Override public StaticNatRule buildStaticNatRule(FirewallRule rule, boolean forRevoke) { IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId()); FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId()); if (ip == null || !ip.isOneToOneNat() || ip.getAssociatedWithVmId() == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Source ip address of the specified firewall rule id is not static nat enabled"); ex.addProxyObject(ruleVO.getUuid(), "ruleId"); throw ex; } String dstIp = ip.getVmIp(); if (dstIp == null) { InvalidParameterValueException ex = new InvalidParameterValueException("VM ip address of the specified public ip is not set "); ex.addProxyObject(ruleVO.getUuid(), "ruleId"); throw ex; } return new StaticNatRuleImpl(ruleVO, dstIp); }