def tocimxml(self): classname = cim_xml.CLASSNAME(self.classname) if self.namespace is not None: localnsp = cim_xml.LOCALNAMESPACEPATH([ cim_xml.NAMESPACE(ns) for ns in string.split(self.namespace, '/') ]) if self.host is not None: # Classname + namespace + host = CLASSPATH return cim_xml.CLASSPATH( cim_xml.NAMESPACEPATH(cim_xml.HOST(self.host), localnsp), classname) # Classname + namespace = LOCALCLASSPATH return cim_xml.LOCALCLASSPATH(localnsp, classname) # Just classname = CLASSNAME return cim_xml.CLASSNAME(self.classname)
def imethodcall(self, methodname, namespace, **params): """Make an intrinsic method call. Returns a tupletree with a IRETURNVALUE element at the root. A CIMError exception is thrown if there was an error parsing the call response, or an ERROR element was returned. The parameters are automatically converted to the right CIM_XML objects. In general clients should call one of the method-specific methods of the connection, such as EnumerateInstanceNames, etc.""" # Create HTTP headers headers = ['CIMOperation: MethodCall', 'CIMMethod: %s' % methodname, cim_http.get_object_header(namespace)] # Create parameter list plist = map(lambda x: cim_xml.IPARAMVALUE(x[0], cim_obj.tocimxml(x[1])), params.items()) # Build XML request req_xml = cim_xml.CIM( cim_xml.MESSAGE( cim_xml.SIMPLEREQ( cim_xml.IMETHODCALL( methodname, cim_xml.LOCALNAMESPACEPATH( [cim_xml.NAMESPACE(ns) for ns in string.split(namespace, '/')]), plist)), '1001', '1.0'), '2.0', '2.0') if self.debug: self.last_raw_request = req_xml.toxml() self.last_request = req_xml.toprettyxml(indent=' ') self.last_reply = None self.last_raw_reply = None # Get XML response try: resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(), self.creds, headers, x509 = self.x509, verify_callback = self.verify_callback) except cim_http.AuthError: raise except cim_http.Error, arg: # Convert cim_http exceptions to CIMError exceptions raise CIMError(0, str(arg))
def tocimxml(self): # Generate an XML representation of the instance classname and # keybindings. if type(self.keybindings) == str: # Class with single key string property instancename_xml = cim_xml.INSTANCENAME( self.classname, cim_xml.KEYVALUE(self.keybindings, 'string')) elif isinstance(self.keybindings, (long, float, int)): # Class with single key numeric property instancename_xml = cim_xml.INSTANCENAME( self.classname, cim_xml.KEYVALUE(str(self.keybindings), 'numeric')) elif isinstance(self.keybindings, (dict, NocaseDict)): # Dictionary of keybindings # NOCASE_TODO should remove dict below. kbs = [] for kb in self.keybindings.items(): # Keybindings can be integers, booleans, strings or # value references. if hasattr(kb[1], 'tocimxml'): kbs.append( cim_xml.KEYBINDING( kb[0], cim_xml.VALUE_REFERENCE(kb[1].tocimxml()))) continue if type(kb[1]) == bool: _type = 'boolean' if kb[1]: value = 'TRUE' else: value = 'FALSE' elif isinstance(kb[1], (long, float, int)): # pywbem.cim_type.{Sint32, Real64, ... } derive from # long or float _type = 'numeric' value = str(kb[1]) elif type(kb[1]) == str or type(kb[1]) == unicode: _type = 'string' value = kb[1] else: raise TypeError('Invalid keybinding type for keybinding ' '%s: %s' % (kb[0], ` type(kb[1]) `)) kbs.append( cim_xml.KEYBINDING(kb[0], cim_xml.KEYVALUE(value, _type))) instancename_xml = cim_xml.INSTANCENAME(self.classname, kbs) else: # Value reference instancename_xml = cim_xml.INSTANCENAME( self.classname, cim_xml.VALUE_REFERENCE(self.keybindings.tocimxml())) # Instance name plus namespace = LOCALINSTANCEPATH if self.host is None and self.namespace is not None: return cim_xml.LOCALINSTANCEPATH( cim_xml.LOCALNAMESPACEPATH([ cim_xml.NAMESPACE(ns) for ns in string.split(self.namespace, '/') ]), instancename_xml) # Instance name plus host and namespace = INSTANCEPATH if self.host is not None and self.namespace is not None: return cim_xml.INSTANCEPATH( cim_xml.NAMESPACEPATH( cim_xml.HOST(self.host), cim_xml.LOCALNAMESPACEPATH([ cim_xml.NAMESPACE(ns) for ns in string.split(self.namespace, '/') ])), instancename_xml) # Just a regular INSTANCENAME return instancename_xml