本文整理汇总了Python中ydk.services.CRUDService.read_config方法的典型用法代码示例。如果您正苦于以下问题:Python CRUDService.read_config方法的具体用法?Python CRUDService.read_config怎么用?Python CRUDService.read_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ydk.services.CRUDService
的用法示例。
在下文中一共展示了CRUDService.read_config方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SanityTest
# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import read_config [as 别名]
class SanityTest(unittest.TestCase):
@classmethod
def setUpClass(self):
# Need to keep a local reference for repo to keep it alive,
# as the first argument for OpenDaylightServiceProvider in libydk
# is a reference.
repo_path = os.path.dirname(__file__)
repo_path = os.path.join(repo_path, '..', '..', '..', 'cpp', 'core', 'tests', 'models')
self.repo = Repository(repo_path)
self.odl = OpenDaylightServiceProvider(self.repo, 'localhost', 'admin', 'admin', 12306, EncodingFormat.JSON)
self.crud = CRUDService()
def test_read_ODL(self):
bgp_filter = oc_bgp.Bgp()
node_provider = self.odl.get_node_provider('xr')
bgp_read = self.crud.read_config(node_provider, bgp_filter)
self.assertEqual(bgp_read.global_.config.as_, 65172)
self.assertEqual(bgp_read.global_.config.router_id, '1.2.3.4')
def test_create_ODL(self):
bgp = oc_bgp.Bgp()
bgp.global_.config.as_ = 65172
bgp.global_.config.router_id = '1.2.3.4'
neighbor = oc_bgp.Bgp.Neighbors.Neighbor()
neighbor.neighbor_address = '6.7.8.9'
neighbor.config.neighbor_address = '6.7.8.9'
neighbor.config.peer_as = 65001
neighbor.config.local_as = 65001
neighbor.config.peer_group = 'IBGP'
bgp.neighbors.neighbor.append(neighbor)
peer_group = oc_bgp.Bgp.PeerGroups.PeerGroup()
peer_group.peer_group_name = 'IBGP'
peer_group.config.peer_group_name = 'IBGP'
peer_group.config.description = 'test description'
peer_group.config.peer_as = 65001
peer_group.config.local_as = 65001
bgp.peer_groups.peer_group.append(peer_group)
node_provider = self.odl.get_node_provider('xr')
self.crud.create(node_provider, bgp)
bgp_read = self.crud.read_config(node_provider, oc_bgp.Bgp())
self.assertEqual(bgp_read, bgp)
示例2: device
# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import read_config [as 别名]
parser.add_argument("-v", "--verbose", help="print debugging messages",
action="store_true")
parser.add_argument("device",
help="gNMI device (ssh://user:[email protected]:port)")
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.DEBUG)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
repo = Repository("/usr/local/share/ydk/0.0.0.0:50051/")
# create gNMI provider
provider = gNMIServiceProvider(repo, address="pavarotti:57400")
# create CRUD service
crud = CRUDService()
bgp = openconfig_bgp.Bgp() # create object
# read data from gNMI device
bgp = crud.read_config(provider, bgp)
process_bgp(bgp) # process object data
exit()
# End of script
示例3: SanityGnmiCrud
# 需要导入模块: from ydk.services import CRUDService [as 别名]
# 或者: from ydk.services.CRUDService import read_config [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])