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


Java IPAddressVO.getAllocatedInDomainId方法代码示例

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


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

示例1: applyStaticNatsForNetwork

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public boolean applyStaticNatsForNetwork(final long networkId, final boolean continueOnError, final Account caller) {
    final List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(networkId);
    if (ips.isEmpty()) {
        s_logger.debug("There are no static nat to apply for network id=" + networkId);
        return true;
    }

    if (caller != null) {
        _accountMgr.checkAccess(caller, null, true, ips.toArray(new IPAddressVO[ips.size()]));
    }

    final List<StaticNat> staticNats = new ArrayList<>();
    for (final IPAddressVO ip : ips) {
        // Get nic IP4 address
        //String dstIp = _networkModel.getIpInNetwork(ip.getAssociatedWithVmId(), networkId);
        final StaticNatImpl staticNat = new StaticNatImpl(ip.getAllocatedToAccountId(), ip.getAllocatedInDomainId(), networkId, ip.getId(), ip.getVmIp(), false);
        staticNats.add(staticNat);
    }

    try {
        if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, false)) {
            return false;
        }
    } catch (final ResourceUnavailableException ex) {
        s_logger.warn("Failed to create static nat for network due to ", ex);
        return false;
    }

    return true;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:32,代码来源:RulesManagerImpl.java

示例2: applyStaticNatRuleForInlineLBRule

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

示例3: applyStaticNatsForNetwork

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public boolean applyStaticNatsForNetwork(long networkId, boolean continueOnError, Account caller) {
    List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(networkId);
    if (ips.isEmpty()) {
        s_logger.debug("There are no static nat to apply for network id=" + networkId);
        return true;
    }

    if (caller != null) {
        _accountMgr.checkAccess(caller, null, true, ips.toArray(new IPAddressVO[ips.size()]));
    }

    List<StaticNat> staticNats = new ArrayList<StaticNat>();
    for (IPAddressVO ip : ips) {
        // Get nic IP4 address
        //String dstIp = _networkModel.getIpInNetwork(ip.getAssociatedWithVmId(), networkId);
        StaticNatImpl staticNat = new StaticNatImpl(ip.getAllocatedToAccountId(), ip.getAllocatedInDomainId(), networkId, ip.getId(), ip.getVmIp(), false);
        staticNats.add(staticNat);
    }

    try {
        if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, false)) {
            return false;
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Failed to create static nat for network due to ", ex);
        return false;
    }

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

示例4: 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

示例5: createFirewallRule

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@DB
protected FirewallRule createFirewallRule(final Long ipAddrId, final Account caller, final String xId, final Integer portStart, final Integer portEnd,
                                          final String protocol, final List<String> sourceCidrList, final Integer icmpCode, final Integer icmpType, final Long relatedRuleId,
                                          final FirewallRule.FirewallRuleType type,
                                          final Long networkId, final FirewallRule.TrafficType trafficType, final Boolean forDisplay) throws NetworkRuleConflictException {

    IPAddressVO ipAddress = null;
    if (ipAddrId != null) {
        // this for ingress firewall rule, for egress id is null
        ipAddress = _ipAddressDao.findById(ipAddrId);
        // Validate ip address
        if (ipAddress == null && type == FirewallRule.FirewallRuleType.User) {
            throw new InvalidParameterValueException("Unable to create firewall rule; " + "couldn't locate IP address by id in the system");
        }
        _networkModel.checkIpForService(ipAddress, Service.Firewall, null);
    }

    validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type, networkId, trafficType);

    // icmp code and icmp type can't be passed in for any other protocol rather than icmp
    if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
        throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
    }

    if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
        throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
    }

    Long accountId = null;
    Long domainId = null;

    if (ipAddress != null) {
        //Ingress firewall rule
        accountId = ipAddress.getAllocatedToAccountId();
        domainId = ipAddress.getAllocatedInDomainId();
    } else if (networkId != null) {
        //egress firewall rule
        final Network network = _networkModel.getNetwork(networkId);
        accountId = network.getAccountId();
        domainId = network.getDomainId();
    }

    final Long accountIdFinal = accountId;
    final Long domainIdFinal = domainId;
    return Transaction.execute(new TransactionCallbackWithException<FirewallRuleVO, NetworkRuleConflictException>() {
        @Override
        public FirewallRuleVO doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException {
            FirewallRuleVO newRule =
                    new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId, accountIdFinal, domainIdFinal, Purpose.Firewall,
                            sourceCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
            newRule.setType(type);
            if (forDisplay != null) {
                newRule.setDisplay(forDisplay);
            }
            newRule = _firewallDao.persist(newRule);

            if (type == FirewallRuleType.User) {
                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());

            return newRule;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:70,代码来源:FirewallManagerImpl.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();

    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

示例7: createFirewallRule

import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@DB
   protected FirewallRule createFirewallRule(final Long ipAddrId, Account caller, final String xId, final Integer portStart, final Integer portEnd,
       final String protocol, final List<String> sourceCidrList, final List<String> destCidrList, final Integer icmpCode, final Integer icmpType, final Long relatedRuleId,
final FirewallRule.FirewallRuleType type,
           final Long networkId, final FirewallRule.TrafficType trafficType, final Boolean forDisplay) throws NetworkRuleConflictException {

       IPAddressVO ipAddress = null;
       if (ipAddrId != null) {
           // this for ingress firewall rule, for egress id is null
            ipAddress = _ipAddressDao.findById(ipAddrId);
       // Validate ip address
       if (ipAddress == null && type == FirewallRule.FirewallRuleType.User) {
               throw new InvalidParameterValueException("Unable to create firewall rule; " + "couldn't locate IP address by id in the system");
       }
       _networkModel.checkIpForService(ipAddress, Service.Firewall, null);
       }

       validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type, networkId, trafficType);

       // icmp code and icmp type can't be passed in for any other protocol rather than icmp
       if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
           throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
       }

       if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
           throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
       }

       Long accountId = null;
       Long domainId = null;

       if (ipAddress != null) {
           //Ingress firewall rule
           accountId = ipAddress.getAllocatedToAccountId();
           domainId = ipAddress.getAllocatedInDomainId();
       } else if (networkId != null) {
           //egress firewall rule
               Network network = _networkModel.getNetwork(networkId);
               accountId = network.getAccountId();
               domainId = network.getDomainId();
       }

       final Long accountIdFinal = accountId;
       final Long domainIdFinal = domainId;
       return Transaction.execute(new TransactionCallbackWithException<FirewallRuleVO, NetworkRuleConflictException>() {
           @Override
           public FirewallRuleVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {
               FirewallRuleVO newRule =
                       new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId, accountIdFinal, domainIdFinal, Purpose.Firewall,
                               sourceCidrList, destCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
               newRule.setType(type);
               if (forDisplay != null) {
                   newRule.setDisplay(forDisplay);
               }
               newRule = _firewallDao.persist(newRule);

               if (type == FirewallRuleType.User)
                   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());

               return newRule;
           }
       });
   }
 
开发者ID:apache,项目名称:cloudstack,代码行数:69,代码来源:FirewallManagerImpl.java


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