@Override public long getId() { return _addr.getId(); }
/** * Acquires lock in "user_ip_address" and checks if the requested IPv4 address is Free. */ protected void acquireLockAndCheckIfIpv4IsFree(Network network, String requestedIpv4Address) { IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIpv4Address); if (ipVO == null) { throw new InvalidParameterValueException( String.format("Cannot find IPAddressVO for guest [IPv4 address='%s'] and [network id='%s']", requestedIpv4Address, network.getId())); } try { IPAddressVO lockedIpVO = _ipAddressDao.acquireInLockTable(ipVO.getId()); validateLockedRequestedIp(ipVO, lockedIpVO); lockedIpVO.setState(IPAddressVO.State.Allocated); _ipAddressDao.update(lockedIpVO.getId(), lockedIpVO); } finally { _ipAddressDao.releaseFromLockTable(ipVO.getId()); } }
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); }
private void applyStaticNatRuleForInlineLBRule(DataCenterVO zone, Network network, boolean revoked, String publicIp, String privateIp) throws ResourceUnavailableException { List<StaticNat> staticNats = new ArrayList<StaticNat>(); IPAddressVO ipVO = _ipAddressDao.listByDcIdIpAddress(zone.getId(), publicIp).get(0); StaticNatImpl staticNat = new StaticNatImpl(ipVO.getAllocatedToAccountId(), ipVO.getAllocatedInDomainId(), network.getId(), ipVO.getId(), privateIp, revoked); staticNats.add(staticNat); StaticNatServiceProvider element = _networkMgr.getStaticNatProviderForNetwork(network); element.applyStaticNats(network, staticNats); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { for (Nic nic : nics) { if (nic.getIPv4Address() != null) { s_logger.debug("Releasing ip " + nic.getIPv4Address() + " of placeholder nic " + nic); IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address()); if (ip != null) { _ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId()); s_logger.debug("Removing placeholder nic " + nic); _nicDao.remove(nic.getId()); } } } } });
@Override public void doInTransactionWithoutResult(TransactionStatus status) { List<IPAddressVO> ips = _ipAddressDao.listByAssociatedNetwork(network.getId(),true); //removing static nat configured on ips. for (IPAddressVO ip : ips) { ip.setSourceNat(false); _ipAddressDao.update(ip.getId(),ip); } } });
@Override public void doInTransactionWithoutResult(TransactionStatus status) { List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId()); for (IPAddressVO ip : ips) { ip.setOneToOneNat(false); ip.setAssociatedWithVmId(null); ip.setVmIp(null); _ipAddressDao.update(ip.getId(),ip); } } });
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { _nicIpAliasDao.update(ipAlias.getId(), ipAlias); final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address()); _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId()); } });
@Override public void finalizeStop(VirtualMachineProfile profile, Answer answer) { //release elastic IP here if assigned IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { CallContext ctx = CallContext.current(); try { _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); } } }
@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; } });
private void reapplyPublicIps(Network networkInOldPhysicalNetwork, Network networkInNewPhysicalNet) { CallContext ctx = CallContext.current(); long callerUserId = ctx.getCallingUserId(); Account caller = ctx.getCallingAccount(); AccountVO networkAccount = _accountDao.findById(networkInNewPhysicalNet.getAccountId()); List<? extends IPAddressVO> staticNatIps = _ipAddressDao.listStaticNatPublicIps(networkInOldPhysicalNetwork.getId()); List<String> providers = _networkOfferingServiceDao.listProvidersForServiceForNetworkOffering(networkInNewPhysicalNet.getNetworkOfferingId(), Network.Service.SourceNat); boolean isSrcNatIpNeeded = providers.stream().anyMatch(provider -> provider.contains(Network.Provider.VirtualRouter.getName())); for (IPAddressVO ipAddress : staticNatIps) { if (!ipAddress.isSourceNat() || isSrcNatIpNeeded) { ipAddress.setAssociatedWithNetworkId(networkInNewPhysicalNet.getId()); _ipAddressDao.persist(ipAddress); } else { _ipAddressManager.disassociatePublicIpAddress(ipAddress.getId(), callerUserId, caller); } } _rulesMgr.applyStaticNatsForNetwork(networkInNewPhysicalNet.getId(), false, networkAccount); }
@Override @ActionEvent(eventType = EventTypes.EVENT_FIREWALL_OPEN, eventDescription = "creating firewall rule", create = true) public boolean addSystemFirewallRules(IPAddressVO ip, Account acct) { List<FirewallRuleVO> systemRules = _firewallDao.listSystemRules(); for (FirewallRuleVO rule : systemRules) { try { if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) { _firewallDao.loadSourceCidrs(rule); } createFirewallRule(ip.getId(), acct, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(),null, rule.getIcmpCode(), rule.getIcmpType(), rule.getRelated(), FirewallRuleType.System, rule.getNetworkId(), rule.getTrafficType(), true); } catch (Exception e) { s_logger.debug("Failed to add system wide firewall rule, due to:" + e.toString()); } } return true; }
@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 List<FirewallRuleVO> listStaticNatByVmId(long vmId) { if (VmSearch == null) { SearchBuilder<IPAddressVO> IpSearch = _ipDao.createSearchBuilder(); IpSearch.and("associatedWithVmId", IpSearch.entity().getAssociatedWithVmId(), SearchCriteria.Op.EQ); IpSearch.and("oneToOneNat", IpSearch.entity().isOneToOneNat(), SearchCriteria.Op.NNULL); VmSearch = createSearchBuilder(); VmSearch.and("purpose", VmSearch.entity().getPurpose(), Op.EQ); VmSearch.join("ipSearch", IpSearch, VmSearch.entity().getSourceIpAddressId(), IpSearch.entity().getId(), JoinBuilder.JoinType.INNER); VmSearch.done(); } SearchCriteria<FirewallRuleVO> sc = VmSearch.create(); sc.setParameters("purpose", Purpose.StaticNat); sc.setJoinParameters("ipSearch", "associatedWithVmId", vmId); return listBy(sc); }