Search in sources :

Example 1 with ClusterVSMMapVO

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

the class CiscoNexusVSMDeviceManagerImpl method addCiscoNexusVSM.

@DB
public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, String vCenterIpaddr, String vCenterDcName) {
    // In this function, we associate this VSM with each host
    // in the clusterId specified.
    // First check if the cluster is of type vmware. If not,
    // throw an exception. VSMs are tightly integrated with vmware clusters.
    ClusterVO cluster = _clusterDao.findById(clusterId);
    if (cluster == null) {
        throw new InvalidParameterValueException("Cluster with specified ID not found!");
    }
    if (cluster.getHypervisorType() != HypervisorType.VMware) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Cluster with specified id is not a VMWare hypervisor cluster");
        throw ex;
    }
    if (_clusterVSMDao.findByClusterId(clusterId) != null) {
        // We can't have two VSMs for the same cluster. Throw exception.
        throw new InvalidParameterValueException("Cluster with specified id already has a VSM tied to it. Please remove that first and retry the operation.");
    }
    // TODO: Confirm whether we should be checking for VSM reachability here.
    // Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to
    // the VSM.
    //NetconfHelper (String ip, String username, String password)
    NetconfHelper netconfClient;
    try {
        netconfClient = new NetconfHelper(ipaddress, username, password);
    } catch (CloudRuntimeException e) {
        String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username;
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    // Disconnect from the VSM. A VSM has a default of 8 maximum parallel connections that it allows.
    netconfClient.disconnect();
    // Now, go ahead and associate the cluster with this VSM.
    // First, check if VSM already exists in the table "virtual_supervisor_module".
    // If it's not there already, create it.
    // If it's there already, return success.
    // TODO - Right now, we only check if the ipaddress matches for both requests.
    // We must really check whether every field of the VSM matches. Anyway, the
    // advantage of our approach for now is that existing infrastructure using
    // the existing VSM won't be affected if the new request to add the VSM
    // assumed different information on the VSM (mgmt vlan, username, password etc).
    CiscoNexusVSMDeviceVO VSMObj;
    try {
        VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress);
    } catch (Exception e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    if (VSMObj == null) {
        // Create the VSM record. For now, we aren't using the vsmName field.
        VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
        _ciscoNexusVSMDeviceDao.persist(VSMObj);
    }
    // At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
    long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
    ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
    _clusterVSMDao.persist(connectorObj);
    return VSMObj;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) DB(com.cloud.utils.db.DB)

Example 2 with ClusterVSMMapVO

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

the class CiscoNexusVSMElement method validateAndAddVsm.

@Override
@DB
public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
    CiscoNexusVSMDeviceVO vsm = null;
    boolean vsmAdded = false;
    Long vsmId = 0L;
    if (vsmIp != null && vsmUser != null && vsmPassword != null) {
        NetconfHelper netconfClient;
        try {
            netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
            netconfClient.disconnect();
        } catch (CloudRuntimeException e) {
            String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
            s_logger.error(msg);
            _clusterDao.remove(clusterId);
            throw new CloudRuntimeException(msg);
        }
        // If VSM already exists and is mapped to a cluster, fail this operation.
        vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
        if (vsm != null) {
            List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
            if (clusterList != null && !clusterList.isEmpty()) {
                s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
                ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
                // get clusterUuid to report error
                ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
                ex.addProxyObject(cluster.getUuid());
                _clusterDao.remove(clusterId);
                throw ex;
            }
        }
        // persist credentials to database if the VSM entry is not already in the db.
        vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {

            @Override
            public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
                CiscoNexusVSMDeviceVO vsm = null;
                if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
                    vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
                    _vsmDao.persist(vsm);
                }
                // Create a mapping between the cluster and the vsm.
                vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
                if (vsm != null) {
                    ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
                    _clusterVSMDao.persist(connectorObj);
                }
                return vsm;
            }
        });
    } else {
        String msg;
        msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + " is set to \"true\". Following mandatory parameters are not specified. ";
        if (vsmIp == null) {
            msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
        }
        if (vsmUser == null) {
            msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
        }
        if (vsmPassword == null) {
            if (vsmUser != null) {
                msg += "vsmpassword: Password of user account " + vsmUser + ". ";
            } else {
                msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
            }
        }
        s_logger.error(msg);
        // Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch.
        _clusterDao.remove(clusterId);
        throw new CloudRuntimeException(msg);
    }
    if (vsm != null) {
        vsmAdded = true;
        vsmId = vsm.getId();
    }
    return new Pair<Boolean, Long>(vsmAdded, vsmId);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallback(com.cloud.utils.db.TransactionCallback) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 3 with ClusterVSMMapVO

use of com.cloud.dc.ClusterVSMMapVO 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)

Example 4 with ClusterVSMMapVO

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

the class VmwareManagerImpl method hasNexusVSM.

@Override
public boolean hasNexusVSM(Long clusterId) {
    ClusterVSMMapVO vsmMapVo = null;
    vsmMapVo = _vsmMapDao.findByClusterId(clusterId);
    if (vsmMapVo == null) {
        s_logger.info("There is no instance of Nexus 1000v VSM associated with this cluster [Id:" + clusterId + "] yet.");
        return false;
    } else {
        s_logger.info("An instance of Nexus 1000v VSM [Id:" + vsmMapVo.getVsmId() + "] associated with this cluster [Id:" + clusterId + "]");
        return true;
    }
}
Also used : ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO)

Example 5 with ClusterVSMMapVO

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

the class ClusterVSMMapDaoImpl method remove.

@Override
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    ClusterVSMMapVO cluster = createForUpdate();
    //cluster.setClusterId(null);
    //cluster.setVsmId(null);
    update(id, cluster);
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO)

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