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