Search in sources :

Example 11 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method auditHost.

private void auditHost(HostVO host) {
    if (host == null)
        return;
    _hostDao.loadDetails(host);
    boolean validateDomains = true;
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
    if (!CollectionUtils.isEmpty(nuageVspDevices)) {
        for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
            String nuageVspCmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.AUDIT, nuageVspCmsId);
            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            if (answer != null && !answer.getSuccess()) {
                s_logger.error("Nuage VSP Device with ID " + nuageVspDevice.getId() + " is configured with an unknown CMS ID!");
                validateDomains = false;
            } else if (answer != null && answer.getSyncType() == SyncType.REGISTER) {
                registerNewNuageVspDevice(nuageVspDevice.getHostId(), answer.getNuageVspCmsId());
            }
        }
    }
    if (validateDomains) {
        auditDomainsOnVsp(host, true);
    }
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)

Example 12 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO 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)

Example 13 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method getNuageVspHost.

@Override
public HostVO getNuageVspHost(long physicalNetworkId) {
    HostVO nuageVspHost;
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    if (CollectionUtils.isEmpty(nuageVspDevices)) {
        // Perhaps another physical network is passed from within the same zone, find the VSP physical network in that case
        PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
        List<PhysicalNetworkVO> physicalNetworksInZone = _physicalNetworkDao.listByZone(physicalNetwork.getDataCenterId());
        for (PhysicalNetworkVO physicalNetworkInZone : physicalNetworksInZone) {
            if (physicalNetworkInZone.getIsolationMethods().contains(PhysicalNetwork.IsolationMethod.VSP.name())) {
                nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkInZone.getId());
                break;
            }
        }
    }
    if (CollectionUtils.isNotEmpty(nuageVspDevices)) {
        NuageVspDeviceVO config = nuageVspDevices.iterator().next();
        nuageVspHost = _hostDao.findById(config.getHostId());
        _hostDao.loadDetails(nuageVspHost);
    } else {
        throw new CloudRuntimeException("There is no Nuage VSP device configured on physical network " + physicalNetworkId);
    }
    return nuageVspHost;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO)

Example 14 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method auditDomainsOnVsp.

private boolean auditDomainsOnVsp(HostVO host, boolean add) {
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
    if (CollectionUtils.isEmpty(nuageVspDevices)) {
        return true;
    }
    final SyncDomainCommand.Type action = add ? SyncDomainCommand.Type.ADD : SyncDomainCommand.Type.REMOVE;
    _hostDao.loadDetails(host);
    List<DomainVO> allDomains = _domainDao.listAll();
    for (DomainVO domain : allDomains) {
        if (action == SyncDomainCommand.Type.REMOVE) {
            VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
            CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
            Answer answer = _agentMgr.easySend(host.getId(), cmd);
            if (!answer.getResult()) {
                return false;
            }
        }
        VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
        SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, action);
        Answer answer = _agentMgr.easySend(host.getId(), cmd);
        if (!answer.getResult()) {
            return false;
        }
    }
    return true;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) DomainVO(com.cloud.domain.DomainVO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand)

Example 15 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method listNuageVspDevices.

@Override
public List<NuageVspDeviceVO> listNuageVspDevices(ListNuageVspDevicesCmd cmd) {
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    Long nuageVspDeviceId = cmd.getNuageVspDeviceId();
    List<NuageVspDeviceVO> responseList = new ArrayList<NuageVspDeviceVO>();
    if (physicalNetworkId == null && nuageVspDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or Nuage device Id must be specified");
    }
    if (nuageVspDeviceId != null) {
        NuageVspDeviceVO nuageVspDevice = _nuageVspDao.findById(nuageVspDeviceId);
        if (nuageVspDevice == null) {
            throw new InvalidParameterValueException("Could not find Nuage Vsp device with id: " + nuageVspDeviceId);
        }
        responseList.add(nuageVspDevice);
    } else {
        PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
        }
        responseList = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    }
    return responseList;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Aggregations

NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)23 HostVO (com.cloud.host.HostVO)11 NuageTest (com.cloud.NuageTest)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 Test (org.junit.Test)9 DomainVO (com.cloud.domain.DomainVO)8 Answer (com.cloud.agent.api.Answer)7 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ArrayList (java.util.ArrayList)6 Network (com.cloud.network.Network)5 PhysicalNetwork (com.cloud.network.PhysicalNetwork)5 SyncNuageVspCmsIdCommand (com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)4 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)4 NuageVspDeviceResponse (com.cloud.api.response.NuageVspDeviceResponse)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 Account (com.cloud.user.Account)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2