Example #1
0
   def rpc(self, input_obj, module):
       if self.session.ncclient_manager is None:
          yield from self.session.connect()

       request_xml = input_obj.to_xml_v2(self.model)
       netconf_response = yield from self.session.ncclient_manager.dispatch(
                                     etree.fromstring(request_xml)) 

       self._log.info("netconf rpc response: %s", netconf_response.xml)
       output_obj = None

       if netconf_response.ok is True:
          in_desc = input_obj.retrieve_descriptor()
          rpc_output_xpath = 'O,/{}'.format(in_desc.xml_element_name())
          out_desc = RwKeyspec.get_pbcmd_from_xpath(rpc_output_xpath, self.schema)
          (module_name, obj_type) = out_desc.get_gi_typename().split(".", 1)
          create_object = getattr(module, obj_type)
          output_obj = create_object()
        
          output_obj.from_xml_v2(self.model, 
                                 Proxy._rpc_fix_root(xml=Proxy._xml_strip_rpc_reply(netconf_response.xml),
                                 rpc_name=out_desc.xml_element_name(),
                                 prefix=out_desc.xml_prefix(),
                                 namespace=out_desc.xml_ns()))

       return output_obj
Example #2
0
    def rpc(self, input_obj, module):
        if self.session.ncclient_manager is None:
            yield from self.session.connect()

        request_xml = input_obj.to_xml_v2(self.model)
        netconf_response = yield from self.session.ncclient_manager.dispatch(
            etree.fromstring(request_xml))

        self._log.info("netconf rpc response: %s", netconf_response.xml)
        output_obj = None

        if netconf_response.ok is True:
            in_desc = input_obj.retrieve_descriptor()
            rpc_output_xpath = 'O,/{}'.format(in_desc.xml_element_name())
            out_desc = RwKeyspec.get_pbcmd_from_xpath(rpc_output_xpath,
                                                      self.schema)
            (module_name, obj_type) = out_desc.get_gi_typename().split(".", 1)
            create_object = getattr(module, obj_type)
            output_obj = create_object()

            output_obj.from_xml_v2(
                self.model,
                Proxy._rpc_fix_root(xml=Proxy._xml_strip_rpc_reply(
                    netconf_response.xml),
                                    rpc_name=out_desc.xml_element_name(),
                                    prefix=out_desc.xml_prefix(),
                                    namespace=out_desc.xml_ns()))

        return output_obj
Example #3
0
   def get(self, xpath, module):
       if self.session.ncclient_manager is None:
          yield from self.session.connect()

       netconf_response = yield from self.session.ncclient_manager.get(('xpath', xpath)) 
       self._log.info("netconf get response: %s", netconf_response.xml)
      
       response_obj = None
       if netconf_response.ok is True:
          response_obj = Proxy._create_gi_from_xpath(xpath, module)
          response_obj.from_xml_v2(self.model, Proxy._xml_strip_rpc_reply(netconf_response.xml))

       return response_obj
Example #4
0
    def get(self, xpath, module):
        if self.session.ncclient_manager is None:
            yield from self.session.connect()

        netconf_response = yield from self.session.ncclient_manager.get(
            ('xpath', xpath))
        self._log.info("netconf get response: %s", netconf_response.xml)

        response_obj = None
        if netconf_response.ok is True:
            response_obj = Proxy._create_gi_from_xpath(xpath, module)
            response_obj.from_xml_v2(
                self.model, Proxy._xml_strip_rpc_reply(netconf_response.xml))

        return response_obj
Example #5
0
 def _add_attribute(self, xpath, xml, operation):
     xpath = xpath.lstrip('/')
     xpath = Proxy._xpath_strip_keys(xpath)
     xpath_elems = xpath.split('/')
     pos = 0
     for elem in xpath_elems:
         pos = xml.index(elem, pos)
         pos = xml.index('>', pos)
     if xml[pos-1] == '/':
        pos -= 1
     xml = xml[:pos] + " xc:operation='{}'".format(operation) + xml[pos:]
     return xml
Example #6
0
 def _add_attribute(self, xpath, xml, operation):
     xpath = xpath.lstrip('/')
     xpath = Proxy._xpath_strip_keys(xpath)
     xpath_elems = xpath.split('/')
     pos = 0
     for elem in xpath_elems:
         pos = xml.index(elem, pos)
         pos = xml.index('>', pos)
     if xml[pos - 1] == '/':
         pos -= 1
     xml = xml[:pos] + " xc:operation='{}'".format(operation) + xml[pos:]
     return xml