use of com.iwave.ext.vmware.VCenterAPI in project coprhd-controller by CoprHD.
the class ConnectToVCenter method executeTask.
@Override
public VCenterAPI executeTask() throws Exception {
debug("Executing: %s", getDetail());
String host = vcenter.getIpAddress();
int port = vcenter.getPortNumber() != null ? vcenter.getPortNumber() : 443;
URL url = new URL("https", host, port, "/sdk");
VCenterAPI vcenterAPI = new VCenterAPI(url);
vcenterAPI.login(vcenter.getUsername(), vcenter.getPassword());
logInfo("connect.vcenter.logged", vcenter.getLabel(), vcenterAPI.getAboutInfo().getFullName());
return vcenterAPI;
}
use of com.iwave.ext.vmware.VCenterAPI in project coprhd-controller by CoprHD.
the class TestVcenter method getVcenterApi.
public static VCenterAPI getVcenterApi(String hostname, String user, String password) throws MalformedURLException {
// Physical vmware is 443. Usually the simulator is on 7230
URL url = new URL("https", hostname, simulator ? 7230 : 443, "/sdk");
VCenterAPI vcenterAPI = new VCenterAPI(url);
vcenterAPI.login(user, password);
return vcenterAPI;
}
use of com.iwave.ext.vmware.VCenterAPI in project coprhd-controller by CoprHD.
the class TestVcenter method main.
public static void main(String[] args) throws MalformedURLException, InvalidProperty, RuntimeFault, RemoteException {
VCenterAPI vcenterAPI = getVcenterApi("lglw1045.lss.emc.com", "root", "vmware");
try {
Datastore ds = vcenterAPI.findDatastore("DC-Simulator-1", "ds-1");
DatastoreInfo dsInfo = ds.getInfo();
if (dsInfo != null) {
return;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.iwave.ext.vmware.VCenterAPI in project coprhd-controller by CoprHD.
the class VCenterConnectionValidator method validateVCenterAPIConnection.
protected static String validateVCenterAPIConnection(String hostname, VcenterParam vcenterParam) {
try {
URL url = new URL("https", hostname, vcenterParam.getPortNumber(), "/sdk");
VCenterAPI vcenterAPI = new VCenterAPI(url);
try {
vcenterAPI.login(vcenterParam.getUserName(), vcenterParam.getPassword());
AboutInfo aboutInfo = vcenterAPI.getAboutInfo();
if (!StringUtils.equals(VCenterAPI.VCENTER_API_TYPE, aboutInfo.getApiType())) {
throw APIException.badRequests.invalidNotAVCenter(hostname, aboutInfo.getFullName());
}
log.info(String.format("vCenter version: %s", aboutInfo.getVersion()));
} finally {
vcenterAPI.logout();
}
} catch (Exception e) {
return getVcenterAPIMessage(e);
}
return null;
}
use of com.iwave.ext.vmware.VCenterAPI in project coprhd-controller by CoprHD.
the class ClusterService method validateVcenterClusterHosts.
/**
* Validate that the hosts in the cluster in our database matches the vCenter environment
*
* @param cluster the cluster to check
*/
public void validateVcenterClusterHosts(Cluster cluster) {
if (null == cluster) {
_log.error("Validation cluster is not set, not performing vCenter cluster validation");
return;
}
// We can only proceed if this cluster belongs to a datacenter
if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
_log.info("Cluster is not synced to vcenter");
return;
}
// Get a list of the cluster's hosts that are in our database.
List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, cluster.getId(), Host.class, "cluster");
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
// If the datacenter is not in our database, we must fail the validation.
if (vcenterDataCenter == null) {
throw APIException.badRequests.vCenterDataCenterNotFound(cluster.getVcenterDataCenter());
}
// If the datacenter has a null vCenter reference, we must fail the validation.
if (NullColumnValueGetter.isNullURI(vcenterDataCenter.getVcenter())) {
throw APIException.badRequests.vCenterDataCenterHasNullVcenter(vcenterDataCenter.forDisplay());
}
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
// If the vCenter is not in our database, we must fail the validation.
if (vcenter == null) {
throw APIException.badRequests.vCenterNotFound(vcenterDataCenter.getVcenter());
}
List<Host> dbHosts = _dbClient.queryObject(Host.class, clusterHosts);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
try {
// Query the vCenter to get a reference to the cluster so that we can compare the hosts between the actual
// environment and our database representation of the cluster.
ClusterComputeResource vcenterCluster = api.findCluster(vcenterDataCenter.getLabel(), cluster.getLabel());
// The cluster may not have been pushed to vCenter yet.
if (vcenterCluster == null) {
_log.info("Unable to find cluster %s in datacenter %s in vCenter environment %s", cluster.getLabel(), vcenterDataCenter.getLabel(), vcenter.getLabel());
return;
}
// Gather a set of all the host UUIDs in this vCenter cluster.
Set<String> vCenterHostUuids = Sets.newHashSet();
for (HostSystem hostSystem : vcenterCluster.getHosts()) {
if (hostSystem != null && hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
}
}
// Gather a set of all the host UUIDs in our database.
Set<String> dbHostUuids = Sets.newHashSet();
for (Host host : dbHosts) {
dbHostUuids.add(host.getUuid());
}
// If there are hosts in vCenter that are not in our database, fail the validation
if (!dbHostUuids.containsAll(vCenterHostUuids)) {
throw APIException.badRequests.clusterHostMismatch(cluster.forDisplay());
}
} finally {
if (api != null) {
api.logout();
}
}
}
Aggregations