示例#1
0
    def _extract_parameters(self):
        try:
            rpc_node = self.request_xml.find(''.join(
                [qmap(C.VOLTHA),
                 self.request['command']])
            )
            self.request['params'] = {}
            if rpc_node is not None:
                for r in rpc_node:
                    self.request['params'][
                        r.tag.replace(qmap(C.VOLTHA), "")] = r.text

            # Remove the subclass element in the request if it is present as
            # it is not required for rpc calls
            if self.request.has_key('subclass'):
                self.request.pop('subclass', None)

            # Extract the service and method from the rpc command
            command = self.request['command'].split('-')
            if len(command) != 2:
                log.debug('invalid-format', command=self.request['command'])
                raise

            self.service = command[0]
            self.method = command[1]
            if self.request.has_key('metadata'):
                self.metadata = self.request['metadata']

        except Exception as e:
            self.rpc_response.is_error = True
            self.rpc_response.node = ncerror.BadMsg(self.request_xml)
            log.exception('params-parsing-error', xml=self.request_xml, e=e)
示例#2
0
    def parse_xml_request(self, node):
        request = {}
        if not len(node):
            return request
        for elem in node.iter():
            if elem.tag.find(qmap(C.NC)) != -1:  # found
                elem_name = elem.tag.replace(qmap(C.NC), "")
                if elem_name == 'rpc':
                    request['type'] = 'rpc'
                    request['message_id'] = self.get_attribute_value(
                        'message-id', elem.attrib)
                elif elem_name == 'filter':
                    request['filter'] = self.get_attribute_value('type',
                                                                 elem.attrib)
                    # Get the metadata
                    request['metadata'] = self.get_filtered_attributes(
                        ['type'],
                        elem.attrib)
                else:
                    request[
                        'command'] = elem_name  # attribute is empty for now
            elif elem.tag.find(qmap(C.VOLTHA)) != -1:  # found
                request['namespace'] = ns(C.VOLTHA)
                if request.has_key('class'):
                    request['subclass'] = elem.tag.replace(qmap(C.VOLTHA), "")
                else:
                    elem_name = elem.tag.replace(qmap(C.VOLTHA), "")
                    request['class'] = elem_name
                    if not request.has_key('command'):
                        request['command'] = elem_name
                        request['metadata'] = self.get_filtered_attributes(
                            ['xmlns'],
                            elem.attrib)
            elif elem.tag.find(qmap(C.HEALTH)) != -1:  # found
                request['namespace'] = ns(C.HEALTH)
                if request.has_key('class'):
                    request['subclass'] = elem.tag.replace(qmap(C.HEALTH), "")
                else:
                    elem_name = elem.tag.replace(qmap(C.HEALTH), "")
                    request['class'] = elem_name
                    if not request.has_key('command'):
                        request['command'] = elem_name
                        request['metadata'] = self.get_filtered_attributes(
                            ['xmlns'],
                            elem.attrib)
            elif elem.tag.find(qmap(C.NCM)) != -1:  # found
                request['namespace'] = ns(C.NCM)
                elem_name = elem.tag.replace(qmap(C.NCM), "")
                if elem_name == 'get-schema':
                    request['command'] = elem_name
                    request['class'] = elem_name
                elif request.has_key('class'):
                    request['subclass'] = elem_name
                elif elem_name == 'netconf-state':
                    request['command'] = 'get-schemas'
                    request['class'] = elem_name

        return request
示例#3
0
 def parse_schema_request(self, node):
     if not len(node):
         return
     schema_node = node.find(''.join([qmap(C.NCM), 'get-schema']))
     if schema_node is not None:
         for item in ['identifier', 'version', 'format']:
             elem = schema_node.find(''.join([qmap(C.NCM), item]))
             if elem is not None:
                 self.request[item] = elem.text
示例#4
0
 def parse_schema_request(self, node):
     if not len(node):
         return
     schema_node = node.find(''.join([qmap(C.NCM), 'get-schema']))
     if schema_node is not None:
         for item in ['identifier', 'version', 'format']:
             elem = schema_node.find(''.join([qmap(C.NCM), item]))
             if elem is not None:
                 self.request[item] = elem.text
示例#5
0
    def parse_xml_request(self, node):
        request = {}
        if not len(node):
            return request
        for elem in node.iter():
            if elem.tag.find(qmap(C.NC)) != -1:  # found
                elem_name = elem.tag.replace(qmap(C.NC), "")
                if elem_name == 'rpc':
                    request['type'] = 'rpc'
                    request['message_id'] = self.get_attribute_value(
                        'message-id', elem.attrib)
                elif elem_name == 'filter':
                    request['filter'] = self.get_attribute_value(
                        'type', elem.attrib)
                    # Get the metadata
                    request['metadata'] = self.get_filtered_attributes(
                        ['type'], elem.attrib)
                else:
                    request[
                        'command'] = elem_name  # attribute is empty for now
            elif elem.tag.find(qmap(C.VOLTHA)) != -1:  # found
                request['namespace'] = ns(C.VOLTHA)
                if request.has_key('class'):
                    request['subclass'] = elem.tag.replace(qmap(C.VOLTHA), "")
                else:
                    elem_name = elem.tag.replace(qmap(C.VOLTHA), "")
                    request['class'] = elem_name
                    if not request.has_key('command'):
                        request['command'] = elem_name
                        request['metadata'] = self.get_filtered_attributes(
                            ['xmlns'], elem.attrib)
            elif elem.tag.find(qmap(C.HEALTH)) != -1:  # found
                request['namespace'] = ns(C.HEALTH)
                if request.has_key('class'):
                    request['subclass'] = elem.tag.replace(qmap(C.HEALTH), "")
                else:
                    elem_name = elem.tag.replace(qmap(C.HEALTH), "")
                    request['class'] = elem_name
                    if not request.has_key('command'):
                        request['command'] = elem_name
                        request['metadata'] = self.get_filtered_attributes(
                            ['xmlns'], elem.attrib)
            elif elem.tag.find(qmap(C.NCM)) != -1:  # found
                request['namespace'] = ns(C.NCM)
                elem_name = elem.tag.replace(qmap(C.NCM), "")
                if elem_name == 'get-schema':
                    request['command'] = elem_name
                    request['class'] = elem_name
                elif request.has_key('class'):
                    request['subclass'] = elem_name
                elif elem_name == 'netconf-state':
                    request['command'] = 'get-schemas'
                    request['class'] = elem_name

        return request
示例#6
0
文件: voltha_rpc.py 项目: apoz/voltha
 def _parse_params(self, node):
     params = {}
     if node is not None:
         for r in node:
             children = r.getchildren()
             if children:
                 params[ r.tag.replace(qmap(C.VOLTHA), "")] = \
                     self._parse_params(children)
             else:
                 params[r.tag.replace(qmap(C.VOLTHA), "")] = r.text
     return params
示例#7
0
    def _extract_parameters(self):
        try:
            rpc_node = self.request_xml.find(''.join(
                [qmap(C.VOLTHA),
                 self.request['command']])
            )

            # Parse rpc the parameters
            self.request['params'] = self._parse_params(rpc_node)

            # Remove the subclass element in the request if it is present as
            # it is not required for rpc calls
            if self.request.has_key('subclass'):
                self.request.pop('subclass', None)

            # Extract the service and method from the rpc command
            command = self.request['command'].split('-')
            if len(command) != 2:
                log.debug('invalid-format', command=self.request['command'])
                raise

            self.service = command[0]
            self.method = command[1]
            if self.request.has_key('metadata'):
                self.metadata = self.request['metadata']

        except Exception as e:
            self.rpc_response.is_error = True
            self.rpc_response.node = ncerror.BadMsg(self.request_xml)
            log.exception('params-parsing-error', xml=self.request_xml, e=e)
 def send_custom_rpc_reply(self, rpc_reply, origmsg):
     reply = etree.Element(qmap(C.NC) + C.RPC_REPLY, attrib=origmsg.attrib,
                           nsmap=rpc_reply.nsmap)
     try:
         reply.extend(rpc_reply.getchildren())
     except AttributeError:
         reply.extend(rpc_reply)
     ucode = etree.tounicode(reply, pretty_print=True)
     log.info("Custom-RPC-Reply", reply=ucode)
     self.send_message(ucode)
示例#9
0
 def send_custom_rpc_reply(self, rpc_reply, origmsg):
     reply = etree.Element(qmap(C.NC) + C.RPC_REPLY,
                           attrib=origmsg.attrib,
                           nsmap=rpc_reply.nsmap)
     try:
         reply.extend(rpc_reply.getchildren())
     except AttributeError:
         reply.extend(rpc_reply)
     ucode = etree.tounicode(reply, pretty_print=True)
     log.info("Custom-RPC-Reply", reply=ucode)
     self.send_message(ucode)
示例#10
0
 def _parse_params(self, node):
     params = {}
     if node is not None:
         for r in node:
             children = r.getchildren()
             tag = r.tag.replace(qmap(C.VOLTHA), "")
             if children:
                 if tag in params:
                     if not isinstance(params[tag], list):
                         temp = []
                         temp.append(params[tag])
                         params[tag] = temp
                     params[tag].append(self._parse_params(children))
                 else:
                     params[tag] = self._parse_params(children)
             else:
                 # Convert string boolean to boolean
                 if r.text == 'true':
                     params[tag] = True
                 elif r.text == 'false':
                     params[tag] = False
                 else:
                     params[tag] = r.text
     return params
示例#11
0
 def _parse_params(self, node):
     params = {}
     if node is not None:
         for r in node:
             children = r.getchildren()
             tag = r.tag.replace(qmap(C.VOLTHA), "")
             if children:
                 if tag in params:
                     if not isinstance(params[tag], list):
                         temp = []
                         temp.append(params[tag])
                         params[tag] = temp
                     params[tag].append(self._parse_params(children))
                 else:
                     params[tag] = self._parse_params(children)
             else:
                 # Convert string boolean to boolean
                 if r.text == 'true':
                     params[tag] = True
                 elif r.text == 'false':
                     params[tag] = False
                 else:
                     params[tag] = r.text
     return params