Java Code Examples for com.vmware.vim25.VimPortType#retrieveServiceContent()

The following examples show how to use com.vmware.vim25.VimPortType#retrieveServiceContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * Get access to the service content
 *
 * @param vimPortType
 * @return {@link ServiceContent}
 * @throws RuntimeFaultFaultMsg
 */
public static ServiceContent getServiceContent(VimPortType vimPortType)
        throws RuntimeFaultFaultMsg {
    // get the service content
    ManagedObjectReference serviceInstance = new ManagedObjectReference();
    serviceInstance.setType("ServiceInstance");
    serviceInstance.setValue("ServiceInstance");
    return vimPortType.retrieveServiceContent(serviceInstance);
}
 
Example 2
Source File: GetObjectProperties.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param propertyFilterSpecList
 * @return list of object content
 * @throws Exception
 */
private static List<ObjectContent> retrievePropertiesAllObjects(ConnectionResources connectionResources,
                                                               List<PropertyFilterSpec> propertyFilterSpecList)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {

    VimPortType vimPort = connectionResources.getVimPortType();
    ManagedObjectReference serviceInstance = connectionResources.getServiceInstance();
    ServiceContent serviceContent = vimPort.retrieveServiceContent(serviceInstance);
    ManagedObjectReference propertyCollectorReference = serviceContent.getPropertyCollector();
    RetrieveOptions propertyObjectRetrieveOptions = new RetrieveOptions();
    List<ObjectContent> objectContentList = new ArrayList<>();

    RetrieveResult results = vimPort.retrievePropertiesEx(propertyCollectorReference,
            propertyFilterSpecList,
            propertyObjectRetrieveOptions);

    if (results != null && results.getObjects() != null && !results.getObjects().isEmpty()) {
        objectContentList.addAll(results.getObjects());
    }

    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }

    while (token != null && !token.isEmpty()) {
        results = vimPort.continueRetrievePropertiesEx(propertyCollectorReference, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null && !results.getObjects().isEmpty()) {
                objectContentList.addAll(results.getObjects());
            }
        }
    }

    return objectContentList;
}
 
Example 3
Source File: VMwareClient.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Establish a connection to the vCenter.
 */
public void connect() throws Exception {
    // FIXME what to do?
    HostnameVerifier hv = new HostnameVerifier() {
        @Override
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };

    int numFailedLogins = 0;
    boolean repeatLogin = true;

    while (repeatLogin) {
        try {
            HttpsURLConnection.setDefaultHostnameVerifier(hv);

            VimService vimService = new VimService();
            VimPortType vimPort = vimService.getVimPort();
            Map<String, Object> ctxt = ((BindingProvider) vimPort)
                    .getRequestContext();

            ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
            ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
                    Boolean.TRUE);

            ManagedObjectReference morSvcInstance = new ManagedObjectReference();
            morSvcInstance.setType("ServiceInstance");
            morSvcInstance.setValue("ServiceInstance");
            ServiceContent serviceContent = vimPort
                    .retrieveServiceContent(morSvcInstance);
            vimPort.login(serviceContent.getSessionManager(), user,
                    password, null);
            connection = new ServiceConnection(vimPort, serviceContent);
            LOG.debug("Established connection to vSphere. URL: " + url
                    + ", UserId: " + user);

            repeatLogin = false;
        } catch (Exception e) {
            LOG.error("Failed to establish connection to vSphere. URL: "
                    + url + ", UserId: " + user, e);
            if (numFailedLogins > 2) {
                throw e;
            }
            numFailedLogins++;
            repeatLogin = true;
            try {
                Thread.sleep(3000);
            } catch (@SuppressWarnings("unused") InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
 
Example 4
Source File: DeployOvfTemplateService.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
private ManagedObjectReference getOvfManager(final ConnectionResources connectionResources) throws RuntimeFaultFaultMsg {
    final VimPortType vimPort = connectionResources.getVimPortType();
    final ManagedObjectReference serviceInstance = connectionResources.getServiceInstance();
    final ServiceContent serviceContent = vimPort.retrieveServiceContent(serviceInstance);
    return serviceContent.getOvfManager();
}
 
Example 5
Source File: VMwareUtil.java    From cloudstack with Apache License 2.0 3 votes vote down vote up
public static VMwareConnection getVMwareConnection(LoginInfo loginInfo) throws Exception {
    trustAllHttpsCertificates();

    HostnameVerifier hv = new HostnameVerifier() {
        @Override
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };

    HttpsURLConnection.setDefaultHostnameVerifier(hv);

    ManagedObjectReference serviceInstanceRef = new ManagedObjectReference();

    final String serviceInstanceName = "ServiceInstance";

    serviceInstanceRef.setType(serviceInstanceName);
    serviceInstanceRef.setValue(serviceInstanceName);

    VimService vimService = new VimService();

    VimPortType vimPortType = vimService.getVimPort();

    Map<String, Object> ctxt = ((BindingProvider)vimPortType).getRequestContext();

    ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://" + loginInfo.getHost() + "/sdk");
    ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

    ServiceContent serviceContent = vimPortType.retrieveServiceContent(serviceInstanceRef);

    vimPortType.login(serviceContent.getSessionManager(), loginInfo.getUsername(), loginInfo.getPassword(), null);

    return new VMwareConnection(vimPortType, serviceContent);
}