@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()); 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(); } }
private List<String> getVirtualMachines( URI datacenterUri, URI clusterUri, URI hostUri, boolean runningOnly) 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 get virtual machines for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel() + "/" + host.getHostName()); vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo()); vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword()); return runningOnly ? vcenterApiClient.getRunningVirtualMachines( vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName()) : vcenterApiClient.getVirtualMachines( 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("getVirtualMachines exception " + e); throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e); } finally { if (vcenterApiClient != null) vcenterApiClient.destroy(); } }