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;
}
Aggregations