use of com.emc.storageos.vcentercontroller.VcenterApiClient in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method removeVcenterCluster.
@Override
public void removeVcenterCluster(URI datacenterUri, URI clusterUri) throws InternalException {
VcenterApiClient vcenterApiClient = null;
try {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to remove cluster " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
vcenterApiClient.removeCluster(vcenterDataCenter.getLabel(), cluster.getExternalId());
} catch (VcenterObjectConnectionException e) {
throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("removeVcenterCluster exception " + e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.vcentercontroller.VcenterApiClient in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method exitMaintenanceMode.
@Override
public void exitMaintenanceMode(URI datacenterUri, URI clusterUri, URI hostUri) throws InternalException {
VcenterApiClient vcenterApiClient = null;
try {
Host host = _dbClient.queryObject(Host.class, hostUri);
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to exit maintenance mode for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel() + "/" + host.getHostName());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
vcenterApiClient.exitMaintenanceMode(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
} catch (VcenterObjectConnectionException e) {
throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("exitMaintenanceMode exception " + e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.vcentercontroller.VcenterApiClient in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method getVirtualMachines.
private List<String> getVirtualMachines(URI datacenterUri, URI clusterUri, boolean runningOnly) throws InternalException {
VcenterApiClient vcenterApiClient = null;
try {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to get virtual machines for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
return runningOnly ? vcenterApiClient.getRunningVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId()) : vcenterApiClient.getVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId());
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("getVirtualMachines exception " + e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.vcentercontroller.VcenterApiClient in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method vcenterClusterRemoveHostOperation.
public void vcenterClusterRemoveHostOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI hostId, String stepId) {
VcenterApiClient vcenterApiClient = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
Host host = _dbClient.queryObject(Host.class, hostId);
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
vcenterApiClient.removeHost(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
_log.info("Successfully removed host " + host.getHostName());
host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
_dbClient.updateObject(host);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("vcenterClusterRemoveHostOperation exception ", e);
WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.vcentercontroller.VcenterApiClient in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method checkVMsOnHostBootVolume.
@Override
public boolean checkVMsOnHostBootVolume(URI datacenterUri, URI clusterUri, URI hostId, URI bootVolumeId) {
VcenterApiClient vcenterApiClient = null;
boolean isVMsPresent = false;
try {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
Host host = _dbClient.queryObject(Host.class, hostId);
Volume volume = _dbClient.queryObject(Volume.class, bootVolumeId);
_log.info("Request to check VMs on boot volume {} of host {}", volume.getLabel() + " - " + bootVolumeId, host.getLabel());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
isVMsPresent = vcenterApiClient.checkVMsOnHostVolume(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), volume.getWWN());
} catch (VcenterObjectConnectionException e) {
throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("checkVMsOnHostBootVolume exception ", e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
return isVMsPresent;
}
Aggregations