def FetchSoap(self, moid, version, prop): # Lookup moid try: mo = GetMoManager().LookupObject(moid) except KeyError: raise vmodl.fault.InvalidArgument(invalidProperty="moid") # Get the version string from version uri. urn:vim25/5.5 -> vim.version.version9 try: version = GetVersionFromVersionUri(version) except KeyError: raise vmodl.fault.InvalidArgument(invalidProperty="version") # Lookup property try: moProp = mo._GetPropertyInfo(p.name) except AttributeError: raise vmodl.fault.InvalidArgument(invalidProperty="prop") if not IsChildVersion(version, moProp.version): raise vmodl.fault.InvalidArgument(invalidProperty="prop") # Using local adapter to invoke method instead of direct method call as # it can provide additional vmomi functions like privilege validation, localization, etc localStub = SoapServerStubAdapter(version, GetMoManager()) # Invoke the property accessor return self._ExecuteCommon(localStub.InvokeAccessor, mo, moProp)
def __VersionIsSupported(desiredVersion, serviceVersionDescription): """ Private method that returns true if the service version description document indicates that the desired version is supported @param desiredVersion: The version we want to see if the server supports (e.g. vim.version.version2) @type desiredVersion: string @param serviceVersionDescription: An ElementTree for vimServiceVersions.xml or vimService.wsdl. @type serviceVersionDescription: ElementTree """ root = serviceVersionDescription.getroot() if root.tag == 'namespaces': # serviceVersionDescription appears to be a vimServiceVersions.xml # document version = root.get('version') if version != '1.0': raise RuntimeError('vimServiceVersions.xml has version %s,' ' which is not understood' % version) desiredVersionId = versionIdMap[desiredVersion] for namespace in root.findall('namespace'): versionId = namespace.findtext('version') if versionId == desiredVersionId: return True else: for versionId in namespace.findall('priorVersions/version'): if versionId.text == desiredVersionId: return True else: # serviceVersionDescription must be a vimService.wsdl document wsdlNS = 'http://schemas.xmlsoap.org/wsdl/' importElement = serviceVersionDescription.find('.//{%s}import' % wsdlNS) supportedVersion = versionMap[importElement.get('namespace')[4:]] if IsChildVersion(supportedVersion, desiredVersion): return True return False
def ExecuteSoap(self, moid, version, method, argument): # Lookup moid try: mo = GetMoManager().LookupObject(moid) except KeyError: raise vmodl.fault.InvalidArgument(invalidProperty="moid") # Get the version string from version uri. urn:vim25/5.5 -> vim.version.version9 try: version = GetVersionFromVersionUri(version) except KeyError: raise vmodl.fault.InvalidArgument(invalidProperty="version") # Cannot invoke method on ManagedMethodExecuter if isinstance(mo, type(self)): raise vmodl.fault.InvalidArgument(invalidProperty="moid") # Lookup Vmodl method methodName = method.rsplit(".", 1)[-1] try: methodInfo = mo._GetMethodInfo(methodName) except AttributeError: # Try again with uncapitalized method name in case of older Python clients try: methodInfo = mo._GetMethodInfo(Uncapitalize(methodName)) except AttributeError: raise vmodl.fault.InvalidArgument(invalidProperty="method") if not IsChildVersion(version, methodInfo.version): raise vmodl.fault.InvalidArgument(invalidProperty="method") # Verify and deserialize args if len(argument) > methodInfo.params: raise vmodl.fault.InvalidArgument(invalidProperty="argument") params = [] iArg = 0 for i in range(0, len(methodInfo.params)): paramInfo = methodInfo.params[i] # Add None param if param is not visible to this version if not IsChildVersion(version, paramInfo.version): params.append(None) continue if iArg >= len(argument): # No incoming args left # Ok if param is optional if paramInfo.flags & F_OPTIONAL: params.append(None) continue # Missing required param raise vmodl.fault.InvalidArgument(invalidProperty="argument") if paramInfo.name != argument[iArg].name: # Check if param is optional if paramInfo.flags & F_OPTIONAL: params.append(None) continue # Name mismatch *** raise vmodl.fault.InvalidArgument(invalidProperty="argument") # Deserialize soap arg to pyVmomi Object try: obj = Deserialize(argument[iArg].val, paramInfo.type) except Exception: raise vmodl.fault.InvalidArgument(invalidProperty="argument") params.append(obj) iArg = iArg + 1 # Using local adapter to invoke method instead of direct method call as # it can provide additional vmomi functions like privilege validation, localization, etc localStub = SoapServerStubAdapter(version, GetMoManager()) # Invoke the method return self._ExecuteCommon(localStub.InvokeMethod, mo, methodInfo, params)