当前位置: 首页>>代码示例>>Java>>正文


Java IPAddressVO.isSourceNat方法代码示例

本文整理汇总了Java中com.cloud.network.dao.IPAddressVO.isSourceNat方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressVO.isSourceNat方法的具体用法?Java IPAddressVO.isSourceNat怎么用?Java IPAddressVO.isSourceNat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cloud.network.dao.IPAddressVO的用法示例。


在下文中一共展示了IPAddressVO.isSourceNat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reapplyPublicIps

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:23,代码来源:NetworkMigrationManagerImpl.java

示例2: getPublicIpByNetwork

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
public String getPublicIpByNetwork(Network network){
    List<IPAddressVO> allocatedIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
    for (IPAddressVO ip: allocatedIps){
        if(ip.isSourceNat()){
            return ip.getAddress().addr();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:10,代码来源:BigSwitchBcfUtils.java

示例3: getPublicIpByVpc

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
public String getPublicIpByVpc(Vpc vpc){
    List<IPAddressVO> allocatedIps = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true);
    for (IPAddressVO ip: allocatedIps){
        if(ip.isSourceNat()){
            return ip.getAddress().addr();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:10,代码来源:BigSwitchBcfUtils.java

示例4: releaseIpAddressInternal

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@DB
private boolean releaseIpAddressInternal(final long ipAddressId) throws InsufficientAddressCapacityException {
    final Long userId = CallContext.current().getCallingUserId();
    final Account caller = CallContext.current().getCallingAccount();

    // Verify input parameters
    final IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId);
    if (ipVO == null) {
        throw new InvalidParameterValueException("Unable to find ip address by id");
    }

    if (ipVO.getAllocatedTime() == null) {
        s_logger.debug("Ip Address id= " + ipAddressId + " is not allocated, so do nothing.");
        return true;
    }

    // verify permissions
    if (ipVO.getAllocatedToAccountId() != null) {
        _accountMgr.checkAccess(caller, null, true, ipVO);
    }

    if (ipVO.isSourceNat()) {
        throw new IllegalArgumentException("ip address is used for source nat purposes and can not be disassociated.");
    }

    final VlanVO vlan = _vlanDao.findById(ipVO.getVlanId());
    if (!vlan.getVlanType().equals(VlanType.VirtualNetwork)) {
        throw new IllegalArgumentException("only ip addresses that belong to a virtual network may be disassociated.");
    }

    // don't allow releasing system ip address
    if (ipVO.getSystem()) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Can't release system IP address with specified id");
        ex.addProxyObject(ipVO.getUuid(), "systemIpAddrId");
        throw ex;
    }

    final boolean success = _ipAddrMgr.disassociatePublicIpAddress(ipAddressId, userId, caller);

    if (success) {
        final Long networkId = ipVO.getAssociatedWithNetworkId();
        if (networkId != null) {
            final Network guestNetwork = getNetwork(networkId);
            final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            final Long vmId = ipVO.getAssociatedWithVmId();
            if (offering.getElasticIp() && vmId != null) {
                _rulesMgr.getSystemIpAndEnableStaticNatForVm(_userVmDao.findById(vmId), true);
                return true;
            }
        }
    } else {
        s_logger.warn("Failed to release public ip address id=" + ipAddressId);
    }
    return success;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:56,代码来源:NetworkServiceImpl.java

示例5: isIpReadyForStaticNat

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
protected void isIpReadyForStaticNat(final long vmId, final IPAddressVO ipAddress, final String vmIp, final Account caller, final long callerUserId) throws
        NetworkRuleConflictException,
        ResourceUnavailableException {
    if (ipAddress.isSourceNat()) {
        throw new InvalidParameterValueException("Can't enable static, ip address " + ipAddress + " is a sourceNat ip address");
    }

    if (!ipAddress.isOneToOneNat()) { // Dont allow to enable static nat if PF/LB rules exist for the IP
        final List<FirewallRuleVO> portForwardingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.PortForwarding);
        if (portForwardingRules != null && !portForwardingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has PortForwarding rules assigned");
        }

        final List<FirewallRuleVO> loadBalancingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.LoadBalancing);
        if (loadBalancingRules != null && !loadBalancingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has LoadBalancing rules assigned");
        }
    } else if (ipAddress.getAssociatedWithVmId() != null && ipAddress.getAssociatedWithVmId().longValue() != vmId) {
        throw new NetworkRuleConflictException("Failed to enable static for the ip address " + ipAddress + " and vm id=" + vmId +
                " as it's already assigned to antoher vm");
    }

    //check wether the vm ip is alreday associated with any public ip address
    final IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmIdAndVmIp(vmId, vmIp);

    if (oldIP != null) {
        // If elasticIP functionality is supported in the network, we always have to disable static nat on the old
        // ip in order to re-enable it on the new one
        final Long networkId = oldIP.getAssociatedWithNetworkId();
        final VMInstanceVO vm = _vmInstanceDao.findById(vmId);

        boolean reassignStaticNat = false;
        if (networkId != null) {
            final Network guestNetwork = _networkModel.getNetwork(networkId);
            final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            if (offering.getElasticIp()) {
                reassignStaticNat = true;
            }
        }

        // If there is public ip address already associated with the vm, throw an exception
        if (!reassignStaticNat) {
            throw new InvalidParameterValueException("Failed to enable static nat on the  ip " +
                    ipAddress.getAddress() + " with Id " + ipAddress.getUuid() + " as the vm " + vm.getInstanceName() + " with Id " +
                    vm.getUuid() + " is already associated with another public ip " + oldIP.getAddress() + " with id " +
                    oldIP.getUuid());
        }
        // unassign old static nat rule
        s_logger.debug("Disassociating static nat for ip " + oldIP);
        if (!disableStaticNat(oldIP.getId(), caller, callerUserId, true)) {
            throw new CloudRuntimeException("Failed to disable old static nat rule for vm " + vm.getInstanceName() +
                    " with id " + vm.getUuid() + "  and public ip " + oldIP);
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:56,代码来源:RulesManagerImpl.java

示例6: createStaticNatRule

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating static nat rule", create = true)
public StaticNatRule createStaticNatRule(final StaticNatRule rule, final boolean openFirewall) throws NetworkRuleConflictException {
    final Account caller = CallContext.current().getCallingAccount();

    final Long ipAddrId = rule.getSourceIpAddressId();

    final IPAddressVO ipAddress = _ipAddressDao.findById(ipAddrId);

    // Validate ip address
    if (ipAddress == null) {
        throw new InvalidParameterValueException("Unable to create static nat rule; ip id=" + ipAddrId + " doesn't exist in the system");
    } else if (ipAddress.isSourceNat() || !ipAddress.isOneToOneNat() || ipAddress.getAssociatedWithVmId() == null) {
        throw new NetworkRuleConflictException("Can't do static nat on ip address: " + ipAddress.getAddress());
    }

    _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), Purpose.StaticNat,
            FirewallRuleType.User, null, rule.getTrafficType());

    final Long networkId = ipAddress.getAssociatedWithNetworkId();
    final Long accountId = ipAddress.getAllocatedToAccountId();
    final Long domainId = ipAddress.getAllocatedInDomainId();

    _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);

    final Network network = _networkModel.getNetwork(networkId);
    final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (off.getElasticIp()) {
        throw new InvalidParameterValueException("Can't create ip forwarding rules for the network where elasticIP service is enabled");
    }

    //String dstIp = _networkModel.getIpInNetwork(ipAddress.getAssociatedWithVmId(), networkId);
    final String dstIp = ipAddress.getVmIp();
    return Transaction.execute(new TransactionCallbackWithException<StaticNatRule, NetworkRuleConflictException>() {
        @Override
        public StaticNatRule doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException {

            FirewallRuleVO newRule =
                    new FirewallRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol().toLowerCase(),
                            networkId, accountId, domainId, rule.getPurpose(), null, null, null, null, null);

            newRule = _firewallDao.persist(newRule);

            // create firewallRule for 0.0.0.0/0 cidr
            if (openFirewall) {
                _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null,
                        newRule.getId(), networkId);
            }

            try {
                _firewallMgr.detectRulesConflict(newRule);
                if (!_firewallDao.setStateToAdd(newRule)) {
                    throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
                }
                CallContext.current().setEventDetails("Rule Id: " + newRule.getId());

                final StaticNatRule staticNatRule = new StaticNatRuleImpl(newRule, dstIp);

                return staticNatRule;
            } catch (final Exception e) {
                if (newRule != null) {
                    // no need to apply the rule as it wasn't programmed on the backend yet
                    _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false);
                    _firewallMgr.removeRule(newRule);
                }

                if (e instanceof NetworkRuleConflictException) {
                    throw (NetworkRuleConflictException) e;
                }
                throw new CloudRuntimeException("Unable to add static nat rule for the ip id=" + newRule.getSourceIpAddressId(), e);
            }
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:76,代码来源:RulesManagerImpl.java

示例7: releasePublicIpRange

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@DB
public boolean releasePublicIpRange(final long vlanDbId, final long userId, final Account caller) {
    VlanVO vlan = _vlanDao.findById(vlanDbId);

    // Verify range is dedicated
    boolean isAccountSpecific = false;
    final List<AccountVlanMapVO> acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanDbId);
    // Verify range is dedicated
    if (acctVln != null && !acctVln.isEmpty()) {
        isAccountSpecific = true;
    }

    boolean isDomainSpecific = false;
    final List<DomainVlanMapVO> domainVln = _domainVlanMapDao.listDomainVlanMapsByVlan(vlanDbId);
    // Check for domain wide pool. It will have an entry for domain_vlan_map.
    if (domainVln != null && !domainVln.isEmpty()) {
        isDomainSpecific = true;
    }

    if (!isAccountSpecific && !isDomainSpecific) {
        throw new InvalidParameterValueException("Can't release Public IP range " + vlanDbId
                + " as it not dedicated to any domain and any account");
    }
    // Check if range has any allocated public IPs
    final long allocIpCount = _publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true);
    final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
    boolean success = true;
    final List<IPAddressVO> ipsInUse = new ArrayList<>();
    if (allocIpCount > 0) {
        try {
            vlan = _vlanDao.acquireInLockTable(vlanDbId, 30);
            if (vlan == null) {
                throw new CloudRuntimeException("Unable to acquire vlan configuration: " + vlanDbId);
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("lock vlan " + vlanDbId + " is acquired");
            }
            for (final IPAddressVO ip : ips) {
                // Disassociate allocated IP's that are not in use
                if (!ip.isOneToOneNat() && !ip.isSourceNat() && !(_firewallDao.countRulesByIpId(ip.getId()) > 0)) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Releasing Public IP addresses" + ip + " of vlan " + vlanDbId + " as part of Public IP" + " range release to the system pool");
                    }
                    success = success && _ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller);
                } else {
                    ipsInUse.add(ip);
                }
            }
            if (!success) {
                s_logger.warn("Some Public IP addresses that were not in use failed to be released as a part of" + " vlan " + vlanDbId + "release to the system pool");
            }
        } finally {
            _vlanDao.releaseFromLockTable(vlanDbId);
        }
    }

    // A Public IP range can only be dedicated to one account at a time
    if (isAccountSpecific && _accountVlanMapDao.remove(acctVln.get(0).getId())) {
        // decrement resource count for dedicated public ip's
        _resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip, new Long(ips.size()));
        return true;
    } else if (isDomainSpecific && _domainVlanMapDao.remove(domainVln.get(0).getId())) {
        s_logger.debug("Remove the vlan from domain_vlan_map successfully.");
        return true;
    } else {
        return false;
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:69,代码来源:ConfigurationManagerImpl.java

示例8: releaseIpAddressInternal

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@DB
private boolean releaseIpAddressInternal(long ipAddressId) throws InsufficientAddressCapacityException {
    Long userId = CallContext.current().getCallingUserId();
    Account caller = CallContext.current().getCallingAccount();

    // Verify input parameters
    IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId);
    if (ipVO == null) {
        throw new InvalidParameterValueException("Unable to find ip address by id");
    }

    if (ipVO.getAllocatedTime() == null) {
        s_logger.debug("Ip Address id= " + ipAddressId + " is not allocated, so do nothing.");
        return true;
    }

    // verify permissions
    if (ipVO.getAllocatedToAccountId() != null) {
        _accountMgr.checkAccess(caller, null, true, ipVO);
    }

    if (ipVO.isSourceNat()) {
        throw new IllegalArgumentException("ip address is used for source nat purposes and can not be disassociated.");
    }

    VlanVO vlan = _vlanDao.findById(ipVO.getVlanId());
    if (!vlan.getVlanType().equals(VlanType.VirtualNetwork)) {
        throw new IllegalArgumentException("only ip addresses that belong to a virtual network may be disassociated.");
    }

    // don't allow releasing system ip address
    if (ipVO.getSystem()) {
        throwInvalidIdException("Can't release system IP address with specified id", ipVO.getUuid(), "systemIpAddrId");
    }

    boolean success = _ipAddrMgr.disassociatePublicIpAddress(ipAddressId, userId, caller);

    if (success) {
        Long networkId = ipVO.getAssociatedWithNetworkId();
        if (networkId != null) {
            Network guestNetwork = getNetwork(networkId);
            NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            Long vmId = ipVO.getAssociatedWithVmId();
            if (offering.getElasticIp() && vmId != null) {
                _rulesMgr.getSystemIpAndEnableStaticNatForVm(_userVmDao.findById(vmId), true);
                return true;
            }
        }
    } else {
        s_logger.warn("Failed to release public ip address id=" + ipAddressId);
    }
    return success;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:54,代码来源:NetworkServiceImpl.java

示例9: createStaticNatRule

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating static nat rule", create = true)
public StaticNatRule createStaticNatRule(final StaticNatRule rule, final boolean openFirewall) throws NetworkRuleConflictException {
    final Account caller = CallContext.current().getCallingAccount();

    final Long ipAddrId = rule.getSourceIpAddressId();

    IPAddressVO ipAddress = _ipAddressDao.findById(ipAddrId);

    // Validate ip address
    if (ipAddress == null) {
        throw new InvalidParameterValueException("Unable to create static nat rule; ip id=" + ipAddrId + " doesn't exist in the system");
    } else if (ipAddress.isSourceNat() || !ipAddress.isOneToOneNat() || ipAddress.getAssociatedWithVmId() == null) {
        throw new NetworkRuleConflictException("Can't do static nat on ip address: " + ipAddress.getAddress());
    }

    _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), Purpose.StaticNat,
        FirewallRuleType.User, null, rule.getTrafficType());

    final Long networkId = ipAddress.getAssociatedWithNetworkId();
    final Long accountId = ipAddress.getAllocatedToAccountId();
    final Long domainId = ipAddress.getAllocatedInDomainId();

    _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);

    Network network = _networkModel.getNetwork(networkId);
    NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (off.getElasticIp()) {
        throw new InvalidParameterValueException("Can't create ip forwarding rules for the network where elasticIP service is enabled");
    }

    //String dstIp = _networkModel.getIpInNetwork(ipAddress.getAssociatedWithVmId(), networkId);
    final String dstIp = ipAddress.getVmIp();
    return Transaction.execute(new TransactionCallbackWithException<StaticNatRule, NetworkRuleConflictException>() {
        @Override
        public StaticNatRule doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {

            FirewallRuleVO newRule =
                new FirewallRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol().toLowerCase(),
                    networkId, accountId, domainId, rule.getPurpose(), null, null, null, null, null);

            newRule = _firewallDao.persist(newRule);

            // create firewallRule for 0.0.0.0/0 cidr
            if (openFirewall) {
                _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null,
                    newRule.getId(), networkId);
            }

            try {
                _firewallMgr.detectRulesConflict(newRule);
                if (!_firewallDao.setStateToAdd(newRule)) {
                    throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
                }
                CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), 0, newRule.getId(), null, FirewallRule.class.getName(),
                    newRule.getUuid());

                StaticNatRule staticNatRule = new StaticNatRuleImpl(newRule, dstIp);

                return staticNatRule;
            } catch (Exception e) {
                if (newRule != null) {
                    // no need to apply the rule as it wasn't programmed on the backend yet
                    _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false);
                    _firewallMgr.removeRule(newRule);
                }

                if (e instanceof NetworkRuleConflictException) {
                    throw (NetworkRuleConflictException)e;
                }
                throw new CloudRuntimeException("Unable to add static nat rule for the ip id=" + newRule.getSourceIpAddressId(), e);
            }
        }
    });

}
 
开发者ID:apache,项目名称:cloudstack,代码行数:79,代码来源:RulesManagerImpl.java

示例10: isIpReadyForStaticNat

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress, String vmIp, Account caller, long callerUserId) throws NetworkRuleConflictException,
    ResourceUnavailableException {
    if (ipAddress.isSourceNat()) {
        throw new InvalidParameterValueException("Can't enable static, ip address " + ipAddress + " is a sourceNat ip address");
    }

    if (!ipAddress.isOneToOneNat()) { // Dont allow to enable static nat if PF/LB rules exist for the IP
        List<FirewallRuleVO> portForwardingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.PortForwarding);
        if (portForwardingRules != null && !portForwardingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has PortForwarding rules assigned");
        }

        List<FirewallRuleVO> loadBalancingRules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipAddress.getId(), Purpose.LoadBalancing);
        if (loadBalancingRules != null && !loadBalancingRules.isEmpty()) {
            throw new NetworkRuleConflictException("Failed to enable static nat for the ip address " + ipAddress + " as it already has LoadBalancing rules assigned");
        }
    } else if (ipAddress.getAssociatedWithVmId() != null && ipAddress.getAssociatedWithVmId().longValue() != vmId) {
        throw new NetworkRuleConflictException("Failed to enable static for the ip address " + ipAddress + " and vm id=" + vmId +
            " as it's already assigned to antoher vm");
    }

    //check wether the vm ip is alreday associated with any public ip address
    IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmIdAndVmIp(vmId, vmIp);

    if (oldIP != null) {
        // If elasticIP functionality is supported in the network, we always have to disable static nat on the old
        // ip in order to re-enable it on the new one
        Long networkId = oldIP.getAssociatedWithNetworkId();
        VMInstanceVO vm = _vmInstanceDao.findById(vmId);

        boolean reassignStaticNat = false;
        if (networkId != null) {
            Network guestNetwork = _networkModel.getNetwork(networkId);
            NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            if (offering.getElasticIp()) {
                reassignStaticNat = true;
            }
        }

        // If there is public ip address already associated with the vm, throw an exception
        if (!reassignStaticNat) {
            throw new InvalidParameterValueException("Failed to enable static nat on the  ip " +
                      ipAddress.getAddress()+" with Id " +ipAddress.getUuid()+" as the vm " +vm.getInstanceName() + " with Id " +
                    vm.getUuid() +" is already associated with another public ip " + oldIP.getAddress() +" with id "+
                    oldIP.getUuid());
        }
    // unassign old static nat rule
    s_logger.debug("Disassociating static nat for ip " + oldIP);
    if (!disableStaticNat(oldIP.getId(), caller, callerUserId, true)) {
            throw new CloudRuntimeException("Failed to disable old static nat rule for vm "+ vm.getInstanceName() +
                    " with id "+vm.getUuid() +"  and public ip " + oldIP);
        }
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:55,代码来源:RulesManagerImpl.java


注:本文中的com.cloud.network.dao.IPAddressVO.isSourceNat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。