Search in sources :

Example 11 with VCenterAPI

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;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) URL(java.net.URL)

Example 12 with 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;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) URL(java.net.URL)

Example 13 with 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();
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) DatastoreInfo(com.vmware.vim25.DatastoreInfo) Datastore(com.vmware.vim25.mo.Datastore) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 14 with VCenterAPI

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;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) AboutInfo(com.vmware.vim25.AboutInfo) URL(java.net.URL) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 15 with VCenterAPI

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();
        }
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Aggregations

VCenterAPI (com.iwave.ext.vmware.VCenterAPI)15 HostSystem (com.vmware.vim25.mo.HostSystem)8 Vcenter (com.emc.storageos.db.client.model.Vcenter)7 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)7 Host (com.emc.storageos.db.client.model.Host)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 URL (java.net.URL)5 RemoteException (java.rmi.RemoteException)5 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)4 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 ClientControllerException (com.emc.storageos.exceptions.ClientControllerException)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 WorkflowException (com.emc.storageos.workflow.WorkflowException)4 HostStorageAPI (com.iwave.ext.vmware.HostStorageAPI)4 Datastore (com.vmware.vim25.mo.Datastore)4 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)3 MalformedURLException (java.net.MalformedURLException)3