Java Code Examples for com.vmware.vim25.ManagedObjectReference#setType()
The following examples show how to use
com.vmware.vim25.ManagedObjectReference#setType() .
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: TaskHelper.java From vsphere-automation-sdk-java with MIT License | 6 votes |
/** * Waits for given Task to complete * * @param vim AuthenticationHelper for VMODL1 APIs * @param taskID ID for the performed task */ public static Boolean waitForTask(VimAuthenticationHelper vim, String taskID) { String[] taskIDParts= taskID.split(TASK_ID_SEPERATOR); String finalTaskID = taskIDParts[0]; ManagedObjectReference ref = new ManagedObjectReference(); ref.setType(TASK_TYPE_MO_REF); ref.setValue(finalTaskID); WaitForValues waitForValues = new WaitForValues(vim.getVimPort(), vim.getServiceContent()); try { if(waitForValues.getTaskResultAfterDone(ref)) { System.out.println("Successfully completed task [" + ref.getValue() + "]"); return true; } else { System.out.println("Failed to complete task [" + ref.getValue() + "]"); } } catch(Exception e) { System.out.println("Unable to execute task [" + ref.getValue() + "]"); System.out.println("Reason: " + e.getLocalizedMessage()); } return false; }
Example 2
Source File: MoConverter.java From nbp with Apache License 2.0 | 5 votes |
/** * get mob object from UID * @param moId string * @return ManagedObjectReference */ public static ManagedObjectReference getMoFromUId(String moId) { ManagedObjectReference moRef = new ManagedObjectReference(); String[] moData = moId.split(":"); if (moData.length < 2) { throw new IllegalArgumentException(String.format(Locale.ROOT, "The moId is not valid :{}", moId)); } String moType = moData[0]; String moValue = moData[1]; moRef.setType(moType); moRef.setValue(moValue); return moRef; }
Example 3
Source File: VimUtil.java From vsphere-automation-sdk-java with MIT License | 5 votes |
/** * 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 4
Source File: BasicConnection.java From cs-actions with Apache License 2.0 | 5 votes |
public ManagedObjectReference getServiceInstanceReference() { if (serviceInstanceReference == null) { ManagedObjectReference morRef = new ManagedObjectReference(); morRef.setType(ManagedObjectType.SERVICE_INSTANCE.getValue()); morRef.setValue(ManagedObjectType.SERVICE_INSTANCE.getValue()); serviceInstanceReference = morRef; } return serviceInstanceReference; }
Example 5
Source File: BaseMO.java From cloudstack with Apache License 2.0 | 5 votes |
public BaseMO(VmwareContext context, String morType, String morValue) { assert (context != null); assert (morType != null); assert (morValue != null); _context = context; _mor = new ManagedObjectReference(); _mor.setType(morType); _mor.setValue(morValue); }
Example 6
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public String getDvPortGroupName(VirtualEthernetCard nic) throws Exception { VirtualEthernetCardDistributedVirtualPortBackingInfo dvpBackingInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo)nic.getBacking(); DistributedVirtualSwitchPortConnection dvsPort = dvpBackingInfo.getPort(); String dvPortGroupKey = dvsPort.getPortgroupKey(); ManagedObjectReference dvPortGroupMor = new ManagedObjectReference(); dvPortGroupMor.setValue(dvPortGroupKey); dvPortGroupMor.setType("DistributedVirtualPortgroup"); return (String)_context.getVimClient().getDynamicProperty(dvPortGroupMor, "name"); }
Example 7
Source File: VMwareClient.java From development with Apache License 2.0 | 4 votes |
/** * 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 8
Source File: VmwareSecondaryStorageResourceHandler.java From cloudstack with Apache License 2.0 | 4 votes |
@Override public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { String guid = cmd.getContextParam("guid"); assert (guid != null); String[] tokens = guid.split("@"); assert (tokens != null && tokens.length == 2); ManagedObjectReference morHyperHost = new ManagedObjectReference(); String[] hostTokens = tokens[0].split(":"); if (hostTokens == null || hostTokens.length != 2) { s_logger.error("Invalid content in command context parameter guid"); return null; } morHyperHost.setType(hostTokens[0]); morHyperHost.setValue(hostTokens[1]); if (morHyperHost.getType().equalsIgnoreCase("HostSystem")) { HostMO hostMo = new HostMO(context, morHyperHost); try { ManagedObjectReference mor = hostMo.getHyperHostCluster(); ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor); List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts(); for (Pair<ManagedObjectReference, String> hostPair : hostsInCluster) { HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first()); VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole")); _resource.ensureOutgoingRuleForAddress(netSummary.getHostIp()); s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp()); } } catch (Throwable e) { s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]); } return hostMo; } assert (false); return new ClusterMO(context, morHyperHost); }
Example 9
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 3 votes |
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); }