示例#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
示例#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
示例#3
0
 def test_gi_get_pbcmd_from_xpath(self):
     xpath = "D,/rw-base:colony[rw-base:name='trafgen']"
     schema = RwFpathDYang.get_schema()
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony().retrieve_descriptor())
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony_BundleEther().retrieve_descriptor())
     #container
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']/rw-fpath:lacp"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony_BundleEther_Lacp().retrieve_descriptor())
     #leaf, should give error
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']/rw-fpath:open"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertFalse(pbcmd);
示例#4
0
 def test_gi_get_pbcmd_from_xpath(self):
     xpath = "D,/rw-base:colony[rw-base:name='trafgen']"
     schema = RwFpathDYang.get_schema()
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony().retrieve_descriptor())
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony_BundleEther().retrieve_descriptor())
     #container
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']/rw-fpath:lacp"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertTrue(pbcmd)
     self.assertEqual(pbcmd, RwFpathDYang.ConfigColony_BundleEther_Lacp().retrieve_descriptor())
     #leaf, should give error
     xpath = "/rw-base:colony[rw-base:name='trafgen']/rw-fpath:bundle-ether[rw-fpath:name='bundle1']/rw-fpath:open"
     pbcmd = RwKeyspec.get_pbcmd_from_xpath(xpath, schema)
     self.assertFalse(pbcmd);
示例#5
0
文件: util.py 项目: RIFTIO/RIFT.ware
def get_protobuf_type(xpath, protobuf_schema):
    '''
    Given the protobuf schema, return the python type corresponding to the given xpath.
    '''

    desc = RwKeyspec.get_pbcmd_from_xpath(xpath, protobuf_schema)
    module_name, obj_type = desc.get_gi_typename().split(".", 1)

    try:
        gi_module = getattr(gi.repository, module_name)
    except AttributeError:
        # first time we've tried to construct something from this module, so load the python overrides
        gi_module_name = "gi.repository.%s" % module_name
        importlib.import_module(gi_module_name)
        gi_module = getattr(gi.repository, module_name)

    protobuf_type = getattr(gi_module, obj_type)

    return protobuf_type