Search in sources :

Example 6 with NetworkAsa1000vMapVO

use of com.cloud.network.cisco.NetworkAsa1000vMapVO in project cloudstack by apache.

the class CiscoVnmcElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.StaticNat, Provider.CiscoVnmc)) {
        s_logger.error("Static NAT service is not provided by Cisco Vnmc device on network " + network.getName());
        return false;
    }
    // Find VNMC host for physical network
    List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Cisco Vnmc device on network " + network.getName());
        return true;
    }
    // Find if ASA 1000v is associated with network
    NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
    if (asaForNetwork == null) {
        s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName());
        return true;
    }
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External firewall was asked to apply static NAT rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
    HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
    List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
    for (StaticNat rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        StaticNatRuleTO ruleTO = new StaticNatRuleTO(rule.getSourceIpAddressId(), sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
        rulesTO.add(ruleTO);
    }
    if (!rulesTO.isEmpty()) {
        SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null);
        cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, BroadcastDomainType.getValue(network.getBroadcastUri()));
        cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, network.getCidr());
        Answer answer = _agentMgr.easySend(ciscoVnmcHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply static NAT rules to Cisco ASA 1000v appliance due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) StaticNat(com.cloud.network.rules.StaticNat) Answer(com.cloud.agent.api.Answer) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Example 7 with NetworkAsa1000vMapVO

use of com.cloud.network.cisco.NetworkAsa1000vMapVO in project cloudstack by apache.

the class CiscoVnmcElement method assignAsa1000vToNetwork.

@Override
public CiscoAsa1000vDevice assignAsa1000vToNetwork(Network network) {
    List<CiscoAsa1000vDeviceVO> asaList = _ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    for (CiscoAsa1000vDeviceVO asa : asaList) {
        NetworkAsa1000vMapVO assignedToNetwork = _networkAsa1000vMapDao.findByAsa1000vId(asa.getId());
        if (assignedToNetwork == null) {
            NetworkAsa1000vMapVO networkAsaMap = new NetworkAsa1000vMapVO(network.getId(), asa.getId());
            _networkAsa1000vMapDao.persist(networkAsaMap);
            return asa;
        }
    }
    return null;
}
Also used : CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO)

Aggregations

NetworkAsa1000vMapVO (com.cloud.network.cisco.NetworkAsa1000vMapVO)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 HostVO (com.cloud.host.HostVO)4 IpAddress (com.cloud.network.IpAddress)4 PublicIpAddress (com.cloud.network.PublicIpAddress)4 CiscoVnmcControllerVO (com.cloud.network.cisco.CiscoVnmcControllerVO)4 ArrayList (java.util.ArrayList)4 Answer (com.cloud.agent.api.Answer)3 CiscoAsa1000vDeviceVO (com.cloud.network.cisco.CiscoAsa1000vDeviceVO)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 SetFirewallRulesCommand (com.cloud.agent.api.routing.SetFirewallRulesCommand)1 SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)1 SetStaticNatRulesCommand (com.cloud.agent.api.routing.SetStaticNatRulesCommand)1 FirewallRuleTO (com.cloud.agent.api.to.FirewallRuleTO)1 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)1 StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)1 CiscoAsa1000vResourceResponse (com.cloud.api.response.CiscoAsa1000vResourceResponse)1 ClusterVO (com.cloud.dc.ClusterVO)1 ClusterVSMMapVO (com.cloud.dc.ClusterVSMMapVO)1