Search in sources :

Example 6 with ClusterVSMMapVO

use of com.cloud.dc.ClusterVSMMapVO in project cloudstack by apache.

the class CiscoNexusVSMDeviceManagerImpl method getCiscoVSMbyClusId.

@DB
public CiscoNexusVSMDeviceVO getCiscoVSMbyClusId(long clusterId) {
    ClusterVSMMapVO mapVO = _clusterVSMDao.findByClusterId(clusterId);
    if (mapVO == null) {
        s_logger.info("Couldn't find a VSM associated with the specified cluster Id");
        return null;
    }
    // Else, pull out the VSM associated with the VSM id in mapVO.
    CiscoNexusVSMDeviceVO result = _ciscoNexusVSMDeviceDao.findById(mapVO.getVsmId());
    return result;
}
Also used : ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) DB(com.cloud.utils.db.DB)

Example 7 with ClusterVSMMapVO

use of com.cloud.dc.ClusterVSMMapVO in project cloudstack by apache.

the class CiscoVnmcElement method implement.

@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Basic) {
        s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);
        return false;
    }
    if (!canHandle(network)) {
        return false;
    }
    final List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Cisco Vnmc device on network " + network.getName());
        return false;
    }
    List<CiscoAsa1000vDeviceVO> asaList = _ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (asaList.isEmpty()) {
        s_logger.debug("No Cisco ASA 1000v device on network " + network.getName());
        return false;
    }
    NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
    if (asaForNetwork != null) {
        s_logger.debug("Cisco ASA 1000v device already associated with network " + network.getName());
        return true;
    }
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)) {
        s_logger.error("SourceNat service is not provided by Cisco Vnmc device on network " + network.getName());
        return false;
    }
    try {
        // ensure that there is an ASA 1000v assigned to this network
        CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network);
        if (assignedAsa == null) {
            s_logger.error("Unable to assign ASA 1000v device to network " + network.getName());
            throw new CloudRuntimeException("Unable to assign ASA 1000v device to network " + network.getName());
        }
        ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId());
        ClusterVSMMapVO clusterVsmMap = _clusterVsmMapDao.findByClusterId(assignedAsa.getClusterId());
        if (clusterVsmMap == null) {
            s_logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
            throw new CloudRuntimeException("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
        }
        CiscoNexusVSMDeviceVO vsmDevice = _vsmDeviceDao.findById(clusterVsmMap.getVsmId());
        if (vsmDevice == null) {
            s_logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
            throw new CloudRuntimeException("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
        }
        CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
        HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
        _hostDao.loadDetails(ciscoVnmcHost);
        Account owner = context.getAccount();
        PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
        long vlanId = Long.parseLong(BroadcastDomainType.getValue(network.getBroadcastUri()));
        List<VlanVO> vlanVOList = _vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId());
        List<String> publicGateways = new ArrayList<String>();
        for (VlanVO vlanVO : vlanVOList) {
            publicGateways.add(vlanVO.getVlanGateway());
        }
        // due to VNMC limitation of not allowing source NAT ip as the outside ip of firewall,
        // an additional public ip needs to acquired for assigning as firewall outside ip.
        // In case there are already additional ip addresses available (network restart) use one
        // of them such that it is not the source NAT ip
        IpAddress outsideIp = null;
        List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
        for (IPAddressVO ip : publicIps) {
            if (!ip.isSourceNat()) {
                outsideIp = ip;
                break;
            }
        }
        if (outsideIp == null) {
            // none available, acquire one
            try {
                Account caller = CallContext.current().getCallingAccount();
                long callerUserId = CallContext.current().getCallingUserId();
                outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone, true);
            } catch (ResourceAllocationException e) {
                s_logger.error("Unable to allocate additional public Ip address. Exception details " + e);
                throw new CloudRuntimeException("Unable to allocate additional public Ip address. Exception details " + e);
            }
            try {
                outsideIp = _ipAddrMgr.associateIPToGuestNetwork(outsideIp.getId(), network.getId(), true);
            } catch (ResourceAllocationException e) {
                s_logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e);
                throw new CloudRuntimeException("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e);
            }
        }
        // create logical edge firewall in VNMC
        String gatewayNetmask = NetUtils.getCidrNetmask(network.getCidr());
        // all public ip addresses must be from same subnet, this essentially means single public subnet in zone
        if (!createLogicalEdgeFirewall(vlanId, network.getGateway(), gatewayNetmask, outsideIp.getAddress().addr(), sourceNatIp.getNetmask(), publicGateways, ciscoVnmcHost.getId())) {
            s_logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
            throw new CloudRuntimeException("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
        }
        // create stuff in VSM for ASA device
        if (!configureNexusVsmForAsa(vlanId, network.getGateway(), vsmDevice.getUserName(), vsmDevice.getPassword(), vsmDevice.getipaddr(), assignedAsa.getInPortProfile(), ciscoVnmcHost.getId())) {
            s_logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName());
            throw new CloudRuntimeException("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName());
        }
        // configure source NAT
        if (!configureSourceNat(vlanId, network.getCidr(), sourceNatIp, ciscoVnmcHost.getId())) {
            s_logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
            throw new CloudRuntimeException("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
        }
        // associate Asa 1000v instance with logical edge firewall
        if (!associateAsaWithLogicalEdgeFirewall(vlanId, assignedAsa.getManagementIp(), ciscoVnmcHost.getId())) {
            s_logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName());
            throw new CloudRuntimeException("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName());
        }
    } catch (CloudRuntimeException e) {
        unassignAsa1000vFromNetwork(network);
        s_logger.error("CiscoVnmcElement failed", e);
        return false;
    } catch (Exception e) {
        unassignAsa1000vFromNetwork(network);
        ExceptionUtil.rethrowRuntime(e);
        ExceptionUtil.rethrow(e, InsufficientAddressCapacityException.class);
        ExceptionUtil.rethrow(e, ResourceUnavailableException.class);
        throw new IllegalStateException(e);
    }
    return true;
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) CiscoAsa1000vDevice(com.cloud.network.cisco.CiscoAsa1000vDevice) VlanVO(com.cloud.dc.VlanVO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ClusterVO(com.cloud.dc.ClusterVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) PublicIp(com.cloud.network.addr.PublicIp) HostVO(com.cloud.host.HostVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) EntityExistsException(javax.persistence.EntityExistsException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 8 with ClusterVSMMapVO

use of com.cloud.dc.ClusterVSMMapVO in project cloudstack by apache.

the class VmwareManagerImpl method getNexusVSMCredentialsByClusterId.

@Override
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
    CiscoNexusVSMDeviceVO nexusVSM = null;
    ClusterVSMMapVO vsmMapVO = null;
    vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
    long vsmId = 0;
    if (vsmMapVO != null) {
        vsmId = vsmMapVO.getVsmId();
        s_logger.info("vsmId is " + vsmId);
        nexusVSM = _nexusDao.findById(vsmId);
        s_logger.info("Fetching nexus vsm credentials from database.");
    } else {
        s_logger.info("Found empty vsmMapVO.");
        return null;
    }
    Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
    if (nexusVSM != null) {
        nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
        nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
        nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
        s_logger.info("Successfully fetched the credentials of Nexus VSM.");
    }
    return nexusVSMCredentials;
}
Also used : CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) HashMap(java.util.HashMap)

Example 9 with ClusterVSMMapVO

use of com.cloud.dc.ClusterVSMMapVO in project cloudstack by apache.

the class CiscoNexusVSMDeviceManagerImpl method deleteCiscoNexusVSM.

@DB
public boolean deleteCiscoNexusVSM(final long vsmId) throws ResourceInUseException {
    CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
    if (cisconexusvsm == null) {
        // This entry is already not present. Return success.
        return true;
    }
    // First, check whether this VSM is part of any non-empty cluster.
    // Search ClusterVSMMap's table for a list of clusters using this vsmId.
    List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId);
    if (clusterList != null) {
        for (ClusterVSMMapVO record : clusterList) {
            // If this cluster id has any hosts in it, fail this operation.
            Long clusterId = record.getClusterId();
            List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
            if (hosts != null && hosts.size() > 0) {
                for (Host host : hosts) {
                    if (host.getType() == Host.Type.Routing) {
                        s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
                        throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
                    }
                }
            }
        }
    }
    // Iterate through the cluster list again, this time, delete the VSM.
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
            _ciscoNexusVSMDeviceDao.remove(vsmId);
            // Remove the current record as well from ClusterVSMMapVO's table.
            _clusterVSMDao.removeByVsmId(vsmId);
        }
    });
    return true;
}
Also used : ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) ResourceInUseException(com.cloud.exception.ResourceInUseException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) HostVO(com.cloud.host.HostVO) DB(com.cloud.utils.db.DB)

Aggregations

ClusterVSMMapVO (com.cloud.dc.ClusterVSMMapVO)9 CiscoNexusVSMDeviceVO (com.cloud.network.CiscoNexusVSMDeviceVO)4 DB (com.cloud.utils.db.DB)4 ClusterVO (com.cloud.dc.ClusterVO)3 ResourceInUseException (com.cloud.exception.ResourceInUseException)3 HostVO (com.cloud.host.HostVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DataCenter (com.cloud.dc.DataCenter)2 VlanVO (com.cloud.dc.VlanVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PublicIp (com.cloud.network.addr.PublicIp)2 CiscoAsa1000vDeviceVO (com.cloud.network.cisco.CiscoAsa1000vDeviceVO)2 CiscoVnmcControllerVO (com.cloud.network.cisco.CiscoVnmcControllerVO)2 NetworkAsa1000vMapVO (com.cloud.network.cisco.NetworkAsa1000vMapVO)2 Account (com.cloud.user.Account)2 NetconfHelper (com.cloud.utils.cisco.n1kv.vsm.NetconfHelper)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 ArrayList (java.util.ArrayList)2 Answer (com.cloud.agent.api.Answer)1 AssociateAsaWithLogicalEdgeFirewallCommand (com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand)1