Search in sources :

Example 11 with CiscoVnmcControllerVO

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

the class CiscoVnmcElement method addCiscoVnmcResource.

@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
    final String deviceName = Provider.CiscoVnmc.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoVnmcController ciscoVnmcResource = null;
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    if (_ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A Cisco Vnmc device is already configured on this physical network");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Cisco VNMC Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    ServerResource resource = new CiscoVnmcResource();
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {

                @Override
                public CiscoVnmcController doInTransaction(TransactionStatus status) {
                    CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    _ciscoVnmcDao.persist((CiscoVnmcControllerVO) ciscoVnmcResource);
                    DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
                    _hostDetailsDao.persist(detail);
                    return ciscoVnmcResource;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoVnmcResource(com.cloud.network.resource.CiscoVnmcResource) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Example 12 with CiscoVnmcControllerVO

use of com.cloud.network.cisco.CiscoVnmcControllerVO 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 13 with CiscoVnmcControllerVO

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

the class CiscoVnmcElementTest method shutdownTest.

@Test
public void shutdownTest() throws ConcurrentOperationException, ResourceUnavailableException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getBroadcastUri()).thenReturn(uri);
    ReservationContext context = mock(ReservationContext.class);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CleanupLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.shutdown(network, context, true));
}
Also used : Answer(com.cloud.agent.api.Answer) CleanupLogicalEdgeFirewallCommand(com.cloud.agent.api.CleanupLogicalEdgeFirewallCommand) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) ArrayList(java.util.ArrayList) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 14 with CiscoVnmcControllerVO

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

the class CiscoVnmcElementTest method applyStaticNatsTest.

@Test
public void applyStaticNatsTest() throws ResourceUnavailableException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    when(network.getState()).thenReturn(Network.State.Implemented);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    IpAddress ipAddress = mock(IpAddress.class);
    when(ipAddress.getAddress()).thenReturn(ip);
    when(ipAddress.getVlanId()).thenReturn(1L);
    when(_networkModel.getIp(anyLong())).thenReturn(ipAddress);
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.StaticNat, Provider.CiscoVnmc)).thenReturn(true);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanTag()).thenReturn(null);
    when(_vlanDao.findById(anyLong())).thenReturn(vlanVO);
    StaticNat rule = mock(StaticNat.class);
    when(rule.getSourceIpAddressId()).thenReturn(1L);
    when(rule.getDestIpAddress()).thenReturn("1.2.3.4");
    when(rule.isForRevoke()).thenReturn(false);
    List<StaticNat> rules = new ArrayList<StaticNat>();
    rules.add(rule);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(SetStaticNatRulesCommand.class))).thenReturn(answer);
    assertTrue(_element.applyStaticNats(network, rules));
}
Also used : SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) URI(java.net.URI) HostVO(com.cloud.host.HostVO) StaticNat(com.cloud.network.rules.StaticNat) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) IpAddress(com.cloud.network.IpAddress) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) Test(org.junit.Test)

Aggregations

CiscoVnmcControllerVO (com.cloud.network.cisco.CiscoVnmcControllerVO)14 HostVO (com.cloud.host.HostVO)11 ArrayList (java.util.ArrayList)11 NetworkAsa1000vMapVO (com.cloud.network.cisco.NetworkAsa1000vMapVO)9 Answer (com.cloud.agent.api.Answer)8 IpAddress (com.cloud.network.IpAddress)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 Network (com.cloud.network.Network)5 PublicIp (com.cloud.network.addr.PublicIp)5 URI (java.net.URI)5 Test (org.junit.Test)5 VlanVO (com.cloud.dc.VlanVO)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 PublicIpAddress (com.cloud.network.PublicIpAddress)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Ip (com.cloud.utils.net.Ip)4 CiscoAsa1000vDeviceVO (com.cloud.network.cisco.CiscoAsa1000vDeviceVO)3 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)3 SetFirewallRulesCommand (com.cloud.agent.api.routing.SetFirewallRulesCommand)2 SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)2