Search in sources :

Example 6 with SyncNuageVspCmsIdAnswer

use of com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer in project cloudstack by apache.

the class NuageVspManagerImpl method deleteNuageVspDevice.

@Override
public boolean deleteNuageVspDevice(DeleteNuageVspDeviceCmd cmd) {
    Long nuageDeviceId = cmd.getNuageVspDeviceId();
    NuageVspDeviceVO nuageVspDevice = _nuageVspDao.findById(nuageDeviceId);
    if (nuageVspDevice == null) {
        throw new InvalidParameterValueException("Could not find a Nuage Vsp device with id " + nuageDeviceId);
    }
    // Find the physical network we work for
    Long physicalNetworkId = nuageVspDevice.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        // Find the nuage networks on this physical network
        List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
        // Networks with broadcast type lswitch are ours
        for (NetworkVO network : networkList) {
            if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Vsp) {
                if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                    throw new CloudRuntimeException("This Nuage Vsp device can not be deleted as there are one or more logical networks provisioned by Cloudstack.");
                }
            }
        }
    }
    NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
    String nuageVspCmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
    if (matchingNuageVspDevice == null) {
        HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
        if (!auditDomainsOnVsp(host, false)) {
            return false;
        }
        SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.UNREGISTER, nuageVspCmsId);
        SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
        if (answer == null || !answer.getSuccess()) {
            return false;
        }
    }
    removeLegacyNuageVspDeviceCmsId(nuageVspDevice.getId());
    HostVO nuageHost = _hostDao.findById(nuageVspDevice.getHostId());
    Long hostId = nuageHost.getId();
    nuageHost.setResourceState(ResourceState.Maintenance);
    _hostDao.update(hostId, nuageHost);
    _resourceMgr.deleteHost(hostId, false, false);
    _nuageVspDao.remove(nuageDeviceId);
    return true;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand) HostVO(com.cloud.host.HostVO)

Aggregations

SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)6 NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)5 SyncNuageVspCmsIdCommand (com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)4 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 HostVO (com.cloud.host.HostVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ConfigurationException (javax.naming.ConfigurationException)2 NuageTest (com.cloud.NuageTest)1 DeleteNuageVspDeviceCmd (com.cloud.api.commands.DeleteNuageVspDeviceCmd)1 DetailVO (com.cloud.host.DetailVO)1 Host (com.cloud.host.Host)1 Status (com.cloud.host.Status)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1 NuageVspResource (com.cloud.network.resource.NuageVspResource)1 NuageVspResourceConfiguration (com.cloud.network.resource.NuageVspResourceConfiguration)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 ExecutionException (java.util.concurrent.ExecutionException)1 NuageVspManagerClient (net.nuage.vsp.acs.client.api.NuageVspManagerClient)1