Example #1
0
 def render_POST(self, request):
     tt = pywbem.parse_cim(pywbem.xml_to_tupletree(request.content.read()))
     # Get the instance from CIM-XML, copied from
     # http://sf.net/apps/mediawiki/pywbem/?title=Indications_Tutorial
     insts = [x[1] for x in tt[2][2][0][2][2]]
     for inst in insts:
         self.callback(inst)
     return ''
Example #2
0
 def render_POST(self, request):
     tt = pywbem.parse_cim(pywbem.xml_to_tupletree(request.content.read()))
     insts = [x[1] for x in tt[2][2][0][2][2]]
     for inst in insts:
         self.callback(inst)
     return ""
Example #3
0
 def render_POST(self, request):
     tt = pywbem.parse_cim(pywbem.xml_to_tupletree(request.content.read()))
     insts = [x[1] for x in tt[2][2][0][2][2]]
     for inst in insts:
         self.callback(inst)
     return ''
    def do_POST(self):
        """
        Overridden method, which is called, when a indication is received. It
        parses the indication message and searches for a matching handler for
        the indication name.  Each subscribed indication should have it's
        Destination set something similar:

        ``<schema>://<destination>/<indication_name>``

        where the ``indication_name`` is a string, which properly defines the
        indication.
        """
        # If HTTP/1.1 used, try to get a message body length. If Content-Length
        # header is not present, set length to -1; rfile.read() will block,
        # until the connection is closed. Knowing the exact content length
        # makes the routine to finish early, even if the TCP connection is not
        # closed.
        length = int(self.headers.get("Content-Length", "-1"))
        msg = self.rfile.read(length)
        tt = pywbem.parse_cim(pywbem.xml_to_tupletree(msg))
        message = tt[2]
        export_methods = {}
        if message[0].upper() != "MESSAGE":
            return

        message_params = message[2]
        if not message_params:
            return

        for param in message_params:
            if param[0].upper() != "SIMPLEEXPREQ":
                continue
            export_method_call = param[2]
            export_method_name = export_method_call[1]["NAME"]
            exp_params = export_method_call[2]
            export_method_params = {}
            for method_param in exp_params:
                export_method_params[method_param[0]] = method_param[1]
            export_methods[export_method_name] = export_method_params

        ind = None
        if export_methods:
            ind_dict = export_methods.values()[0]
            if "NewIndication" in ind_dict:
                ind = ind_dict["NewIndication"]

        # Inform the CIMOM, that we got the indication.
        cim_version = tt[1]["CIMVERSION"]
        dtd_version = tt[1]["DTDVERSION"]
        message_id = message[1]["ID"]
        protocol_version = message[1]["PROTOCOLVERSION"]
        self.send_indication_response(
            self.make_indication_response(
                cim_version, dtd_version, message_id, protocol_version))

        path = self.path
        cimlistener_ind = path.find(self.CIMLISTENER_PREFIX)
        if cimlistener_ind != -1:
            # We got an indication with lmiwbem's CIMListener substring
            # present. We are using pywbem now, so it's necessary to strip the
            # prefix also with the substring (from the beginning). We try to
            # mimic Pegasus::CIMListener behavior here.
            path = path[cimlistener_ind + len(self.CIMLISTENER_PREFIX):]

        if path[0] == '/':
            # Path of the received indication may be prefixed by additional
            # slash. Drop it then.
            path = path[1:]

        if path in self.server._handlers:
            # We found the indication handler. Execute the callback.
            cb = self.server._handlers[path]
            cb.callback(ind, *cb.args, **cb.kwargs)