Search in sources :

Example 1 with CiscoVnmcControllerVO

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

the class CiscoVnmcElement method listCiscoVnmcResources.

@Override
public List<CiscoVnmcControllerVO> listCiscoVnmcResources(ListCiscoVnmcResourcesCmd cmd) {
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    Long ciscoVnmcResourceId = cmd.getCiscoVnmcResourceId();
    List<CiscoVnmcControllerVO> responseList = new ArrayList<CiscoVnmcControllerVO>();
    if (physicalNetworkId == null && ciscoVnmcResourceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or vnmc device Id must be specified");
    }
    if (ciscoVnmcResourceId != null) {
        CiscoVnmcControllerVO ciscoVnmcResource = _ciscoVnmcDao.findById(ciscoVnmcResourceId);
        if (ciscoVnmcResource == null) {
            throw new InvalidParameterValueException("Could not find Cisco Vnmc device with id: " + ciscoVnmcResource);
        }
        responseList.add(ciscoVnmcResource);
    } else {
        PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
        }
        responseList = _ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId);
    }
    return responseList;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Example 2 with CiscoVnmcControllerVO

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

the class CiscoVnmcElement method applyPFRules.

@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)) {
        s_logger.error("Port forwarding 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 port forwarding 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<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        rulesTO.add(ruleTO);
    }
    if (!rulesTO.isEmpty()) {
        SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rulesTO);
        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 port forwarding 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 : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) 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 3 with CiscoVnmcControllerVO

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

the class CiscoVnmcElement method applyFWRules.

@Override
public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Firewall, Provider.CiscoVnmc)) {
        s_logger.error("Firewall 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 firewall 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<FirewallRuleTO> rulesTO = new ArrayList<FirewallRuleTO>();
    for (FirewallRule rule : rules) {
        String address = "0.0.0.0";
        if (rule.getTrafficType() == TrafficType.Ingress) {
            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            address = sourceIp.getAddress().addr();
        }
        FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, address, rule.getPurpose(), rule.getTrafficType());
        rulesTO.add(ruleTO);
    }
    if (!rulesTO.isEmpty()) {
        SetFirewallRulesCommand cmd = new SetFirewallRulesCommand(rulesTO);
        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 firewall 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 : ArrayList(java.util.ArrayList) FirewallRuleTO(com.cloud.agent.api.to.FirewallRuleTO) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) HostVO(com.cloud.host.HostVO) 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) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 4 with CiscoVnmcControllerVO

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

the class CiscoVnmcElement method deleteCiscoVnmcResource.

@Override
public boolean deleteCiscoVnmcResource(DeleteCiscoVnmcResourceCmd cmd) {
    Long vnmcResourceId = cmd.getCiscoVnmcResourceId();
    CiscoVnmcControllerVO vnmcResource = _ciscoVnmcDao.findById(vnmcResourceId);
    if (vnmcResource == null) {
        throw new InvalidParameterValueException("Could not find a Cisco VNMC appliance with id " + vnmcResourceId);
    }
    // Check if there any ASA 1000v appliances
    Long physicalNetworkId = vnmcResource.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        List<CiscoAsa1000vDeviceVO> responseList = _ciscoAsa1000vDao.listByPhysicalNetwork(physicalNetworkId);
        if (responseList.size() > 0) {
            throw new CloudRuntimeException("Cisco VNMC appliance with id " + vnmcResourceId + " cannot be deleted as there Cisco ASA 1000v appliances using it");
        }
    }
    HostVO vnmcHost = _hostDao.findById(vnmcResource.getHostId());
    Long hostId = vnmcHost.getId();
    vnmcHost.setResourceState(ResourceState.Maintenance);
    _hostDao.update(hostId, vnmcHost);
    _resourceMgr.deleteHost(hostId, false, false);
    _ciscoVnmcDao.remove(vnmcResourceId);
    return true;
}
Also used : CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) HostVO(com.cloud.host.HostVO)

Example 5 with CiscoVnmcControllerVO

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

the class CiscoVnmcElementTest method implementTest.

@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    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.getGateway()).thenReturn("1.1.1.1");
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(1L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination dest = mock(DeployDestination.class);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("d1");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("a1");
    ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    DataCenter dc = mock(DataCenter.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
    when(asaVO.getInPortProfile()).thenReturn("foo");
    when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
    List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
    asaList.add(asaVO);
    when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
    when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)).thenReturn(true);
    ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
    when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
    CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
    when(vsmDevice.getUserName()).thenReturn("foo");
    when(vsmDevice.getPassword()).thenReturn("bar");
    when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
    when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    PublicIp publicIp = mock(PublicIp.class);
    when(publicIp.getAddress()).thenReturn(ip);
    when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
    when(publicIp.getAccountId()).thenReturn(1L);
    when(publicIp.isSourceNat()).thenReturn(true);
    when(publicIp.getVlanTag()).thenReturn("123");
    when(publicIp.getGateway()).thenReturn("1.1.1.1");
    when(publicIp.getNetmask()).thenReturn("1.1.1.1");
    when(publicIp.getMacAddress()).thenReturn(null);
    when(publicIp.isOneToOneNat()).thenReturn(true);
    when(_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
    List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
    when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) AssociateAsaWithLogicalEdgeFirewallCommand(com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) NetworkOffering(com.cloud.offering.NetworkOffering) PublicIp(com.cloud.network.addr.PublicIp) ConfigureNexusVsmForAsaCommand(com.cloud.agent.api.ConfigureNexusVsmForAsaCommand) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) CreateLogicalEdgeFirewallCommand(com.cloud.agent.api.CreateLogicalEdgeFirewallCommand) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) 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