当前位置: 首页>>代码示例>>Python>>正文


Python CRUDService.update方法代码示例

本文整理汇总了Python中ydk.services.CRUDService.update方法的典型用法代码示例。如果您正苦于以下问题:Python CRUDService.update方法的具体用法?Python CRUDService.update怎么用?Python CRUDService.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ydk.services.CRUDService的用法示例。


在下文中一共展示了CRUDService.update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SanityTest

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
class SanityTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(
            "127.0.0.1",
            "admin",
            "admin",
            12022,
            )
        self.crud = CRUDService()

    def setUp(self):
        runner = Runner()
        self.crud.delete(self.ncc, runner)

    def test_delete_on_list_with_identitykey(self):
        a1 = Runner.OneList.IdentityList()
        a1.config.id = ChildIdentity()
        a1.id_ref =  a1.config.id
        self.crud.create(self.ncc, a1)

        k = Runner.OneList.IdentityList()
        k.config.id = ChildIdentity()
        k.id_ref = k.config.id
        k.yfilter = YFilter.delete
        self.crud.update(self.ncc, k)

        runner_read = self.crud.read(self.ncc, Runner())
        self.assertIsNone(runner_read)

    def test_iden_list(self):
        # CREATE
        il = Runner.OneList.IdentityList()
        il.config.id = ChildIdentity()
        il.id_ref = ChildIdentity()
        self.crud.create(self.ncc, il)

        # READ & VALIDATE
        runner_filter = Runner.OneList()
        read_one = self.crud.read(self.ncc, runner_filter)
        self.assertIsNotNone(read_one)

        read_il = read_one.identity_list.get(ChildIdentity().to_string())
        self.assertIsNotNone(read_il)
        read_il.parent = None
        self.assertEqual(read_il, il)

        # DELETE & VALIDATE
        self.crud.delete(self.ncc, il)
        runner_read = self.crud.read(self.ncc, Runner())
        self.assertIsNone(runner_read)
开发者ID:111pontes,项目名称:ydk-gen,代码行数:54,代码来源:test_non_top_operations.py

示例2: SanityYang

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
class SanityYang(unittest.TestCase):
    PROVIDER_TYPE = "non-native"

    @classmethod
    def setUpClass(self):
        if SanityYang.PROVIDER_TYPE == "native":
            self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                    username='admin',
                                                    password='admin',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='admin',
                                              password='admin',
                                              protocol='ssh',
                                              port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def tearDown(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def test_one_level_pos(self):
        # READ
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.one.number, r_1.one.name = 1, 'runner:one:name'
        self.crud.create(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.one.number, r_1.one.name = 10, 'runner/one/name'
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)

    def test_two_level_pos(self):
        # READ
        r_1 = ysanity.Runner()
        r_1.two.number, r_1.two.name, r_1.two.sub1.number = 2, 'runner:two:name', 21
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.two.number, r_1.two.name, r_1.two.sub1.number = 20, 'runner/two/name', 210
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)

    def test_three_level_pos(self):
        # READ
        r_1 = ysanity.Runner()
        r_1.three.number, r_1.three.name, \
            r_1.three.sub1.number, r_1.three.sub1.sub2.number = 3, 'runner:three:name', 31, 311
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.three.number, r_1.three.name, \
            r_1.three.sub1.number, r_1.three.sub1.sub2.number = 30, 'runner/three/name', 310, 3110
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)


    def test_onelist_neg_dupkey(self):
        # netsim/enxr not complaining
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        e_1, e_2 = ysanity.Runner.OneList.Ldata(), ysanity.Runner.OneList.Ldata()
        e_1.number = 1
        e_2.name = 'foo'
        e_2.number = 1
#.........这里部分代码省略.........
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:103,代码来源:test_sanity_levels.py

示例3: SanityYang

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
class SanityYang(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(
            address='127.0.0.1', username='admin', 
            password='admin', protocol='ssh', port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)
        print '\nIn method', self._testMethodName + ':'

    def tearDown(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def test_delete_object_on_leaf(self):
        # create runner with two leaves, one and two
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'
        runner_create.two.name = 'two'
        self.crud.create(self.ncc, runner_create)

        runner_read_filter = ysanity.Runner()
        runner_read = self.crud.read(self.ncc, runner_read_filter)

        # use DELETE object to remove leaf one
        runner_delete = runner_read
        runner_delete.one.name = DELETE()
        self.crud.update(self.ncc, runner_delete)

        # manually create remaining runner with leaf two
        runner_read = self.crud.read(self.ncc, runner_read_filter)
        runner_left = runner_create
        runner_left.one.name = None

        self.assertEqual(is_equal(runner_read, runner_left), True)

    @unittest.skip('DELETE object for leaf-list')
    def test_delete_object_on_leaflist(self):
        # create runner with a leaf and a leaflist
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'
        runner_create.ytypes.built_in_t.llstring = [str(i) for i in range(5)]
        self.crud.create(self.ncc, runner_create)

        runner_read_filter = ysanity.Runner()
        runner_read = self.crud.read(self.ncc, runner_read_filter)

        # user DELETE object to remove leaflist
        runner_delete = runner_read
        runner_delete.ytypes.built_in_t.llstring = DELETE()
        self.crud.update(self.ncc, runner_delete)

        # manually create remaining runner with leaf one
        runner_read = self.crud.read(self.ncc, runner_read_filter)
        runner_left = runner_create
        del runner_left.ytypes.built_in_t.llstring[:]

        self.assertEqual(is_equal(runner_read, runner_left), True)

    def test_delete_operation_on_container(self):
        # create runner with a container
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'
        runner_create.two.name = 'two'
        self.crud.create(self.ncc, runner_create)

        runner_read_filter = ysanity.Runner()
        runner_read = self.crud.read(self.ncc, runner_read_filter)

        # delete contianer two
        self.crud.delete(self.ncc, runner_read.two)

        runner_read = self.crud.read(self.ncc, runner_read_filter)
        runner_left = runner_create
        runner_left.two.name = None

        self.assertEqual(is_equal(runner_read, runner_left), True)

    def test_delete_operation_on_list(self):
        # create runner with a container and a list
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'

        elem1 = ysanity.Runner.OneList.Ldata()
        elem2 = ysanity.Runner.OneList.Ldata()
        elem1.number = 1
        elem2.name = 'foo'
        elem2.number = 1
        elem2.name = 'bar'
        runner_create.one_list.ldata.extend([elem1, elem2])

        self.crud.create(self.ncc, runner_create)
#.........这里部分代码省略.........
开发者ID:waffle-iron,项目名称:ydk-gen,代码行数:103,代码来源:test_sanity_delete.py

示例4: SanityTest

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]

#.........这里部分代码省略.........
    def test_empty_invalid(self):
        runner = self._create_runner()
        runner.ytypes.built_in_t.emptee = 0
        # self.crud.create(self.ncc, runner)
        self.assertRaises(YPYDataValidationError,
            self.crud.create, self.ncc, runner)

        # OLD
        # Read into Runner2
        # runner1 = ysanity.Runner()
        # self.assertRaises(YPYDataValidationError,
            # self.crud.create, self.ncc, runner)
        # runner1 = self.crud.read(self.ncc, runner1)

        # Compare runners
        # result = is_equal(runner, runner1)
        # self.assertEqual(result, False)

    def test_boolean(self):
        runner = self._create_runner()
        runner.ytypes.built_in_t.bool_value = True
        self.crud.create(self.ncc, runner)

        # Read into Runner2
        runner1 = ysanity.Runner()
        runner1 = self.crud.read(self.ncc, runner1)

        # Compare runners
        result = is_equal(runner, runner1)
        self.assertEqual(result, True)

        runner = self._create_runner()
        runner.ytypes.built_in_t.bool_value = False
        self.crud.update(self.ncc, runner)

        # Read into Runner2
        runner1 = ysanity.Runner()
        runner1 = self.crud.read(self.ncc, runner1)

        # Compare runners
        result = is_equal(runner, runner1)
        self.assertEqual(result, True)


    @unittest.skip('boolean type will convert empty string to false')
    def test_boolean_invalid(self):
        runner = self._create_runner()
        runner.ytypes.built_in_t.bool_value = ''
        # self.crud.create(self.ncc, runner)
        self.assertRaises(YPYDataValidationError,
            self.crud.create, self.ncc, runner)

        # OLD
        # # Read into Runner2
        # runner1 = ysanity.Runner()
        # runner1 = self.crud.read(self.ncc, runner1)

        # # Compare runners
        # result = is_equal(runner, runner1)
        # self.assertEqual(result, True)

    def test_enum(self):
        runner = self._create_runner()
        runner.ytypes.built_in_t.enum_value = YdkEnumTestEnum.NONE
        self.crud.create(self.ncc, runner)
开发者ID:waffle-iron,项目名称:ydk-gen,代码行数:69,代码来源:test_sanity_types.py

示例5: urlparse

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
    args = parser.parse_args()
    device = urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create NETCONF provider
    provider = NetconfServiceProvider(address=device.hostname,
                                      port=device.port,
                                      username=device.username,
                                      password=device.password,
                                      protocol=device.scheme)
    # create CRUD service
    crud = CRUDService()

    host_names = xr_shellutil_cfg.HostNames()  # create object
    config_host_names(host_names)  # add object configuration

    # update configuration on NETCONF device
    crud.update(provider, host_names)

    exit()
# End of script
开发者ID:111pontes,项目名称:ydk-py-samples,代码行数:32,代码来源:nc-update-xr-shellutil-cfg-20-ydk.py

示例6: SanityYang

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
class SanityYang(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(
            address='127.0.0.1',
            username='admin',
            password='admin',
            protocol='ssh',
            port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)
        print '\nIn method', self._testMethodName + ':'

    def tearDown(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def read_from_empty_filter(self):
        empty_runner = ysanity.Runner()
        return self.crud.read(self.ncc, empty_runner)

    def get_nested_object(self):
        # return nested object with selected list elements
        runner_create = ysanity.Runner()
        e_1 = ysanity.Runner.InbtwList.Ldata()
        e_2 = ysanity.Runner.InbtwList.Ldata()
        e_1.number = 11
        e_1.name = 'runner:inbtwlist:['+str(e_1.number)+']:name'
        e_1.subc.number = 111
        e_1.subc.name = 'runner:inbtwlist:['+str(e_1.number)+']:subc:name'
        e_2.number = 12
        e_2.name = 'runner:inbtwlist:['+str(e_2.number)+']:name'
        e_2.subc.number = 121
        e_2.subc.name = 'runner:inbtwlist:['+str(e_2.number)+']:name'
        e_11 = ysanity.Runner.InbtwList.Ldata.Subc.SubcSubl1()
        e_11.number = 111
        e_11.name = 'runner:inbtwlist:['+str(e_1.number)+']:subc:subcsubl1['+str(e_11.number)+']:name'
        e_12 = ysanity.Runner.InbtwList.Ldata.Subc.SubcSubl1()
        e_12.number = 112
        e_12.name = 'runner:inbtwlist:['+str(e_1.number)+']:subc:subcsubl1['+str(e_12.number)+']:name'
        e_1.subc.subc_subl1.extend([e_11, e_12])
        e_21 = ysanity.Runner.InbtwList.Ldata.Subc.SubcSubl1()
        e_21.number = 121
        e_21.name = 'runner:inbtwlist:['+str(e_2.number)+']:subc:subcsubl1['+str(e_21.number)+']:name'
        e_22 = ysanity.Runner.InbtwList.Ldata.Subc.SubcSubl1()
        e_22.number = 122
        e_22.name = 'runner:inbtwlist:['+str(e_2.number)+']:subc:subcsubl1['+str(e_22.number)+']:name'
        e_2.subc.subc_subl1.extend([e_21, e_22])
        runner_create.inbtw_list.ldata.extend([e_1, e_2])

        return runner_create, e_2, e_22

    def test_delete_object_on_leaf(self):
        # create runner with two leaves, one and two
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'
        runner_create.two.name = 'two'
        self.crud.create(self.ncc, runner_create)

        runner_read_filter = ysanity.Runner()
        runner_read = self.crud.read(self.ncc, runner_read_filter)

        # use DELETE object to remove leaf one
        runner_delete = runner_read
        runner_delete.one.name = DELETE()
        self.crud.update(self.ncc, runner_delete)

        # manually create remaining runner with leaf two
        runner_read = self.crud.read(self.ncc, runner_read_filter)
        runner_left = runner_create
        runner_left.one.name = None

        self.assertEqual(is_equal(runner_read, runner_left), True)


    def test_delete_on_leaflist_slice(self):
        runner_create = ysanity.Runner()
        runner_create.one.name = 'one'
        runner_create.ytypes.built_in_t.llstring.extend([str(i) for i in range(5)])

        self.crud.create(self.ncc, runner_create)

        elements_to_delete = runner_create.ytypes.built_in_t.llstring[0:2]
        self.crud.delete(self.ncc, elements_to_delete)

        runner_read = self.read_from_empty_filter()
        runner_left = runner_create
        del runner_left.ytypes.built_in_t.llstring[0:2]

        self.assertEqual(is_equal(runner_read, runner_create), True)

    def test_delete_on_leaflist(self):
#.........这里部分代码省略.........
开发者ID:ReignInChaos,项目名称:ydk-gen,代码行数:103,代码来源:test_sanity_delete.py

示例7: SanityGnmiCrud

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
class SanityGnmiCrud(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.codec_provider = CodecServiceProvider()
        self.codec = CodecService()
        self.repo = Repository(get_local_repo_dir())
        self.provider = gNMIServiceProvider( self.repo, "127.0.0.1", 50051, "admin", "admin")
        self.schema = self.provider.get_session().get_root_schema()
        self.crud = CRUDService()

    def test_gnmi_crud_all_operations(self):
        # Configure interface
        lo10 = openconfig_interfaces.Interfaces.Interface()
        lo10.name = 'Loopback10'
        lo10.config.name = 'Loopback10'

        # Configure BGP
        bgp_global_config = openconfig_bgp.Bgp.Global.Config()
        bgp_global_config.as_ = 65172
        neighbor = openconfig_bgp.Bgp.Neighbors.Neighbor()
        neighbor.neighbor_address = '172.16.255.2'
        neighbor.config.neighbor_address = '172.16.255.2'
        neighbor.config.peer_as = 65172

        res = self.crud.create(self.provider, [lo10, bgp_global_config, neighbor])

        # Update configuration
        lo10.config.description = 'Test'
        res = self.crud.update(self.provider, lo10)
        self.assertTrue(res)
 
        # Read all
        read_list = self.crud.read(self.provider, [openconfig_interfaces.Interfaces(), openconfig_bgp.Bgp()])

        # Read config
        ifc_filter = openconfig_interfaces.Interfaces.Interface()
        ifc_filter.name = 'Loopback10'
        bgp_neighbor_filter = openconfig_bgp.Bgp.Neighbors.Neighbor()
        bgp_neighbor_filter.neighbor_address = '172.16.255.2'

        read_list = self.crud.read_config(self.provider, [ifc_filter, bgp_neighbor_filter])
        self.assertIsNotNone(read_list)
        self.assertEqual(isinstance(read_list, list), True)
        self.assertEqual(len(read_list), 2)
        #for entity in read_list:
        #    print_entity(entity, self.schema)
 
        # Read single container
        lo10 = openconfig_interfaces.Interfaces.Interface()
        lo10.name = 'Loopback10'
        lo10.config = YFilter.read
        ifc_config = self.crud.read(self.provider, lo10)
        #print_entity(ifc_config, self.schema)
        expected = '''<interface>
  <name>Loopback10</name>
  <config>
    <name>Loopback10</name>
    <description>Test</description>
  </config>
</interface>
'''
        self.assertEqual( entity_to_string(ifc_config, self.schema), expected)
 
        # Read single leaf
        ifcs = openconfig_interfaces.Interfaces()
        lo10 = openconfig_interfaces.Interfaces.Interface()
        lo10.name = 'Loopback10'
        lo10.config.description = YFilter.read
        ifcs.interface.append(lo10)
        read_descr = self.crud.read(self.provider, lo10)
        #print_entity(read_descr, self.schema)
        expected = '''<interface>
  <name>Loopback10</name>
  <config>
    <description>Test</description>
  </config>
</interface>
'''
        self.assertEqual( entity_to_string(read_descr, self.schema), expected)
         
        # Delete configuration
        ifc = openconfig_interfaces.Interfaces.Interface()
        ifc.name = 'Loopback10'
        bgp = openconfig_bgp.Bgp()
        res = self.crud.delete(self.provider, [ifc, bgp])
开发者ID:111pontes,项目名称:ydk-gen,代码行数:88,代码来源:test_gnmi_crud.py

示例8: NetconfServiceProvider

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
    device = urllib.parse.urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create NETCONF provider
    provider = NetconfServiceProvider(address=device.hostname,
                                      port=device.port,
                                      username=device.username,
                                      password=device.password,
                                      protocol=device.scheme)
    # create CRUD service
    crud = CRUDService()

    # BGP configuration filter
    bgp = oc_bgp.Bgp()
    bgp_peer_remove_filter(bgp, args.local_as, args.peer_address)

    # update configuration on NETCONF device
    crud.update(provider, bgp)

    exit()
# End of script
开发者ID:111pontes,项目名称:ydk-py-samples,代码行数:32,代码来源:remove_bgp_peer.py

示例9: NetconfServiceProvider

# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import update [as 别名]
    device = urllib.parse.urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create NETCONF provider
    provider = NetconfServiceProvider(address=device.hostname,
                                      port=device.port,
                                      username=device.username,
                                      password=device.password,
                                      protocol=device.scheme)
    # create CRUD service
    crud = CRUDService()

    # interface configuration filter
    interfaces = oc_interfaces.Interfaces()
    peer_interface_remove_filter(interfaces, args.name)

    # update configuration on NETCONF device
    crud.update(provider, interfaces)

    exit()
# End of script
开发者ID:111pontes,项目名称:ydk-py-samples,代码行数:32,代码来源:remove_peer_interface.py


注:本文中的ydk.services.CRUDService.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。