Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit c9a138f

Browse files
author
Yan
committed
Added samples for gnmi on XR
1 parent 1e183bd commit c9a138f

File tree

15 files changed

+1184
-702
lines changed

15 files changed

+1184
-702
lines changed
43 Bytes
Binary file not shown.

cisco-ios-xe/ydk/models/cisco_ios_xe/common_mpls_static.py

Lines changed: 632 additions & 632 deletions
Large diffs are not rendered by default.

cisco-ios-xe/ydk/models/cisco_ios_xe/nvo.py

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,24 @@ class NvoInstance(Entity):
8080
8181
**range:** 0..65535
8282
83-
.. attribute:: source_interface
84-
85-
Source interface name
86-
**type**\: str
87-
88-
**refers to**\: :py:class:`name <ydk.models.ietf.ietf_interfaces.Interfaces.Interface>`
83+
.. attribute:: overlay_encapsulation
8984
90-
**mandatory**\: True
85+
Encapsulation type
86+
**type**\: :py:class:`OverlayEncapType <ydk.models.cisco_ios_xe.nvo.OverlayEncapType>`
9187
9288
.. attribute:: virtual_network
9389
9490
VNI member attributes
9591
**type**\: list of :py:class:`VirtualNetwork <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork>`
9692
97-
.. attribute:: overlay_encapsulation
93+
.. attribute:: source_interface
9894
99-
Encapsulation type
100-
**type**\: :py:class:`OverlayEncapType <ydk.models.cisco_ios_xe.nvo.OverlayEncapType>`
95+
Source interface name
96+
**type**\: str
97+
98+
**refers to**\: :py:class:`name <ydk.models.ietf.ietf_interfaces.Interfaces.Interface>`
99+
100+
**mandatory**\: True
101101
102102
103103
@@ -117,20 +117,20 @@ def __init__(self):
117117
self._child_classes = OrderedDict([("virtual-network", ("virtual_network", NvoInstances.NvoInstance.VirtualNetwork))])
118118
self._leafs = OrderedDict([
119119
('nvo_id', (YLeaf(YType.uint16, 'nvo-id'), ['int'])),
120-
('source_interface', (YLeaf(YType.str, 'source-interface'), ['str'])),
121120
('overlay_encapsulation', (YLeaf(YType.identityref, 'overlay-encapsulation'), [('ydk.models.cisco_ios_xe.nvo', 'OverlayEncapType')])),
121+
('source_interface', (YLeaf(YType.str, 'source-interface'), ['str'])),
122122
])
123123
self.nvo_id = None
124-
self.source_interface = None
125124
self.overlay_encapsulation = None
125+
self.source_interface = None
126126

127127
self.virtual_network = YList(self)
128128
self._segment_path = lambda: "nvo-instance" + "[nvo-id='" + str(self.nvo_id) + "']"
129129
self._absolute_path = lambda: "nvo:nvo-instances/%s" % self._segment_path()
130130
self._is_frozen = True
131131

132132
def __setattr__(self, name, value):
133-
self._perform_setattr(NvoInstances.NvoInstance, ['nvo_id', 'source_interface', 'overlay_encapsulation'], name, value)
133+
self._perform_setattr(NvoInstances.NvoInstance, ['nvo_id', 'overlay_encapsulation', 'source_interface'], name, value)
134134

135135

136136
class VirtualNetwork(Entity):
@@ -162,16 +162,23 @@ class VirtualNetwork(Entity):
162162
163163
**refers to**\: :py:class:`name <ydk.models.ietf.ietf_routing.Routing.RoutingInstance>`
164164
165-
.. attribute:: peers
165+
.. attribute:: end_host_discovery
166166
167-
List of VTEP peers
168-
**type**\: list of :py:class:`Peers <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork.Peers>`
167+
How to peform endpoint discovery
168+
**type**\: :py:class:`EndHostDiscovery <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork.EndHostDiscovery>`
169+
170+
**default value**\: flood-and-learn
169171
170172
.. attribute:: multicast
171173
172174
Mulitcast group range associated with the VxLAN segment(s)
173175
**type**\: :py:class:`Multicast <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork.Multicast>`
174176
177+
.. attribute:: peers
178+
179+
List of VTEP peers
180+
**type**\: list of :py:class:`Peers <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork.Peers>`
181+
175182
.. attribute:: bgp
176183
177184
Use control protocol BGP to discover peers
@@ -182,13 +189,6 @@ class VirtualNetwork(Entity):
182189
Enable ARP request suppression for this VNI
183190
**type**\: :py:class:`Empty<ydk.types.Empty>`
184191
185-
.. attribute:: end_host_discovery
186-
187-
How to peform endpoint discovery
188-
**type**\: :py:class:`EndHostDiscovery <ydk.models.cisco_ios_xe.nvo.NvoInstances.NvoInstance.VirtualNetwork.EndHostDiscovery>`
189-
190-
**default value**\: flood-and-learn
191-
192192
193193
194194
"""
@@ -204,21 +204,21 @@ def __init__(self):
204204
self.is_top_level_class = False
205205
self.has_list_ancestor = True
206206
self.ylist_key_names = ['vni_start','vni_end']
207-
self._child_classes = OrderedDict([("peers", ("peers", NvoInstances.NvoInstance.VirtualNetwork.Peers)), ("multicast", ("multicast", NvoInstances.NvoInstance.VirtualNetwork.Multicast))])
207+
self._child_classes = OrderedDict([("multicast", ("multicast", NvoInstances.NvoInstance.VirtualNetwork.Multicast)), ("peers", ("peers", NvoInstances.NvoInstance.VirtualNetwork.Peers))])
208208
self._leafs = OrderedDict([
209209
('vni_start', (YLeaf(YType.uint32, 'vni-start'), ['int'])),
210210
('vni_end', (YLeaf(YType.uint32, 'vni-end'), ['int'])),
211211
('routing_instance', (YLeaf(YType.str, 'routing-instance'), ['str'])),
212+
('end_host_discovery', (YLeaf(YType.enumeration, 'end-host-discovery'), [('ydk.models.cisco_ios_xe.nvo', 'NvoInstances', 'NvoInstance.VirtualNetwork.EndHostDiscovery')])),
212213
('bgp', (YLeaf(YType.empty, 'bgp'), ['Empty'])),
213214
('suppress_arp', (YLeaf(YType.empty, 'suppress-arp'), ['Empty'])),
214-
('end_host_discovery', (YLeaf(YType.enumeration, 'end-host-discovery'), [('ydk.models.cisco_ios_xe.nvo', 'NvoInstances', 'NvoInstance.VirtualNetwork.EndHostDiscovery')])),
215215
])
216216
self.vni_start = None
217217
self.vni_end = None
218218
self.routing_instance = None
219+
self.end_host_discovery = None
219220
self.bgp = None
220221
self.suppress_arp = None
221-
self.end_host_discovery = None
222222

223223
self.multicast = NvoInstances.NvoInstance.VirtualNetwork.Multicast()
224224
self.multicast.parent = self
@@ -229,7 +229,7 @@ def __init__(self):
229229
self._is_frozen = True
230230

231231
def __setattr__(self, name, value):
232-
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork, ['vni_start', 'vni_end', 'routing_instance', 'bgp', 'suppress_arp', 'end_host_discovery'], name, value)
232+
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork, ['vni_start', 'vni_end', 'routing_instance', 'end_host_discovery', 'bgp', 'suppress_arp'], name, value)
233233

234234
class EndHostDiscovery(Enum):
235235
"""
@@ -255,22 +255,24 @@ class EndHostDiscovery(Enum):
255255

256256

257257

258-
class Peers(Entity):
258+
class Multicast(Entity):
259259
"""
260-
List of VTEP peers
260+
Mulitcast group range associated
261+
with the VxLAN segment(s)
261262
262-
.. attribute:: peer_ip (key)
263+
.. attribute:: multicast_group_min
263264
264-
VTEP peer IP address
265-
**type**\: union of the below types:
265+
Single IPV4 Multicast group address or start of range
266+
**type**\: str
266267
267-
**type**\: str
268+
**pattern:** (2((2[4\-9])\|(3[0\-9]))\\.)(([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){2}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])
268269
269-
**pattern:** (([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){3}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])(%[\\p{N}\\p{L}]+)?
270+
.. attribute:: multicast_group_max
270271
271-
**type**\: str
272+
End of IPV4 Multicast group address (leave unspecified for single value
273+
**type**\: str
272274
273-
**pattern:** ((\:\|[0\-9a\-fA\-F]{0,4})\:)([0\-9a\-fA\-F]{0,4}\:){0,5}((([0\-9a\-fA\-F]{0,4}\:)?(\:\|[0\-9a\-fA\-F]{0,4}))\|(((25[0\-5]\|2[0\-4][0\-9]\|[01]?[0\-9]?[0\-9])\\.){3}(25[0\-5]\|2[0\-4][0\-9]\|[01]?[0\-9]?[0\-9])))(%[\\p{N}\\p{L}]+)?
275+
**pattern:** (2((2[4\-9])\|(3[0\-9]))\\.)(([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){2}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])
274276
275277
276278
@@ -280,43 +282,43 @@ class Peers(Entity):
280282
_revision = '2015-06-02'
281283

282284
def __init__(self):
283-
super(NvoInstances.NvoInstance.VirtualNetwork.Peers, self).__init__()
285+
super(NvoInstances.NvoInstance.VirtualNetwork.Multicast, self).__init__()
284286

285-
self.yang_name = "peers"
287+
self.yang_name = "multicast"
286288
self.yang_parent_name = "virtual-network"
287289
self.is_top_level_class = False
288290
self.has_list_ancestor = True
289-
self.ylist_key_names = ['peer_ip']
291+
self.ylist_key_names = []
290292
self._child_classes = OrderedDict([])
291293
self._leafs = OrderedDict([
292-
('peer_ip', (YLeaf(YType.str, 'peer-ip'), ['str','str'])),
294+
('multicast_group_min', (YLeaf(YType.str, 'multicast-group-min'), ['str'])),
295+
('multicast_group_max', (YLeaf(YType.str, 'multicast-group-max'), ['str'])),
293296
])
294-
self.peer_ip = None
295-
self._segment_path = lambda: "peers" + "[peer-ip='" + str(self.peer_ip) + "']"
297+
self.multicast_group_min = None
298+
self.multicast_group_max = None
299+
self._segment_path = lambda: "multicast"
296300
self._is_frozen = True
297301

298302
def __setattr__(self, name, value):
299-
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork.Peers, ['peer_ip'], name, value)
303+
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork.Multicast, ['multicast_group_min', 'multicast_group_max'], name, value)
300304

301305

302-
class Multicast(Entity):
306+
class Peers(Entity):
303307
"""
304-
Mulitcast group range associated
305-
with the VxLAN segment(s)
308+
List of VTEP peers
306309
307-
.. attribute:: multicast_group_min
310+
.. attribute:: peer_ip (key)
308311
309-
Single IPV4 Multicast group address or start of range
310-
**type**\: str
312+
VTEP peer IP address
313+
**type**\: union of the below types:
311314
312-
**pattern:** (2((2[4\-9])\|(3[0\-9]))\\.)(([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){2}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])
315+
**type**\: str
313316
314-
.. attribute:: multicast_group_max
317+
**pattern:** (([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){3}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])(%[\\p{N}\\p{L}]+)?
315318
316-
End of IPV4 Multicast group address (leave unspecified for single value
317-
**type**\: str
319+
**type**\: str
318320
319-
**pattern:** (2((2[4\-9])\|(3[0\-9]))\\.)(([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])\\.){2}([0\-9]\|[1\-9][0\-9]\|1[0\-9][0\-9]\|2[0\-4][0\-9]\|25[0\-5])
321+
**pattern:** ((\:\|[0\-9a\-fA\-F]{0,4})\:)([0\-9a\-fA\-F]{0,4}\:){0,5}((([0\-9a\-fA\-F]{0,4}\:)?(\:\|[0\-9a\-fA\-F]{0,4}))\|(((25[0\-5]\|2[0\-4][0\-9]\|[01]?[0\-9]?[0\-9])\\.){3}(25[0\-5]\|2[0\-4][0\-9]\|[01]?[0\-9]?[0\-9])))(%[\\p{N}\\p{L}]+)?
320322
321323
322324
@@ -326,25 +328,23 @@ class Multicast(Entity):
326328
_revision = '2015-06-02'
327329

328330
def __init__(self):
329-
super(NvoInstances.NvoInstance.VirtualNetwork.Multicast, self).__init__()
331+
super(NvoInstances.NvoInstance.VirtualNetwork.Peers, self).__init__()
330332

331-
self.yang_name = "multicast"
333+
self.yang_name = "peers"
332334
self.yang_parent_name = "virtual-network"
333335
self.is_top_level_class = False
334336
self.has_list_ancestor = True
335-
self.ylist_key_names = []
337+
self.ylist_key_names = ['peer_ip']
336338
self._child_classes = OrderedDict([])
337339
self._leafs = OrderedDict([
338-
('multicast_group_min', (YLeaf(YType.str, 'multicast-group-min'), ['str'])),
339-
('multicast_group_max', (YLeaf(YType.str, 'multicast-group-max'), ['str'])),
340+
('peer_ip', (YLeaf(YType.str, 'peer-ip'), ['str','str'])),
340341
])
341-
self.multicast_group_min = None
342-
self.multicast_group_max = None
343-
self._segment_path = lambda: "multicast"
342+
self.peer_ip = None
343+
self._segment_path = lambda: "peers" + "[peer-ip='" + str(self.peer_ip) + "']"
344344
self._is_frozen = True
345345

346346
def __setattr__(self, name, value):
347-
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork.Multicast, ['multicast_group_min', 'multicast_group_max'], name, value)
347+
self._perform_setattr(NvoInstances.NvoInstance.VirtualNetwork.Peers, ['peer_ip'], name, value)
348348

349349
def clone_ptr(self):
350350
self._top_entity = NvoInstances()
-31 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

core/samples/hello-ydk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717
# hello-ydk.py
18-
# Read all data for model Cisco-IOS-XR-shellutil-oper.yang and print system uptime.
18+
# Read all data for model Cisco-IOS-XR-shellutil-oper.yang and print system name and uptime.
1919
#
2020
import logging
2121
from datetime import timedelta
@@ -39,7 +39,7 @@ def enable_logging(level):
3939
enable_logging(logging.INFO)
4040

4141
# create NETCONF session
42-
provider = NetconfServiceProvider(address="domingo",
42+
provider = NetconfServiceProvider(address="192.168.122.169",
4343
port=830,
4444
username="admin",
4545
password="admin",
@@ -54,7 +54,7 @@ def enable_logging(level):
5454
system_time = crud.read(provider, system_time)
5555

5656
# print system uptime
57-
print("System uptime is " +
57+
print("System '%s' uptime is "%system_time.uptime.host_name +
5858
str(timedelta(seconds=system_time.uptime.uptime)))
5959

6060
exit()

core/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
# Define and modify version number and package name here,
3333
# Namespace packages are share same prefix: "ydk-models"
3434
NAME = 'ydk'
35+
3536
VERSION = '0.8.0'
37+
3638
INSTALL_REQUIREMENTS = ['pybind11>=2.1.1']
3739

3840

gnmi/samples/bgp_gnmi_create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Read all data for model openconfig-bgp.
33
usage: nc-read-oc-bgp-10-ydk.py [-h] [-v] device
44
positional arguments:
5-
device NETCONF device (ssh://user:password@host:port)
5+
device gNMI device (ssh://user:password@host:port)
66
optional arguments:
77
-h, --help show this help message and exit
88
-v, --verbose print debugging messages
@@ -13,8 +13,7 @@
1313
from ydk.path import Repository
1414
from ydk.services import CRUDService
1515
from ydk.providers import gNMIServiceProvider
16-
from ydk.models.openconfig import openconfig_bgp \
17-
as oc_bgp
16+
from ydk.models.openconfig import openconfig_bgp as oc_bgp
1817
from ydk.models.openconfig import openconfig_bgp_types
1918
import logging
2019

@@ -56,9 +55,10 @@ def config_bgp(bgp_cfg):
5655
logger.addHandler(handler)
5756

5857
# create gNMI provider
59-
repository = Repository('/Users/abhirame/.ydk/pavarotti:830')
58+
repository = Repository('/home/ygorelik/ydk-gen/scripts/samples/repository/192.168.122.107")
6059
provider = gNMIServiceProvider(repo=repository,
6160
address=device.hostname,
61+
port=device.port,
6262
username=device.username,
6363
password=device.password)
6464
# create CRUD service

gnmi/samples/hello_ydk_gnmi.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2018 Cisco Systems, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# hello_ydk_gnmi.py
18+
# Read all data for model Cisco-IOS-XR-shellutil-oper.yang and print system name and uptime.
19+
#
20+
import logging
21+
from datetime import timedelta
22+
23+
# import providers, services and models
24+
from ydk.path import Repository
25+
from ydk.services import CRUDService
26+
from ydk.gnmi.providers import gNMIServiceProvider
27+
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_shellutil_oper as xr_shellutil_oper
28+
29+
def enable_logging(level):
30+
log = logging.getLogger('ydk')
31+
log.setLevel(level)
32+
handler = logging.StreamHandler()
33+
formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
34+
handler.setFormatter(formatter)
35+
log.addHandler(handler)
36+
37+
if __name__ == "__main__":
38+
"""Main execution path"""
39+
40+
enable_logging(logging.INFO)
41+
42+
# create NETCONF session
43+
repo = Repository('/home/ygorelik/.ydk/192.168.122.169_830')
44+
provider = gNMIServiceProvider(repo,
45+
address="192.168.122.169",
46+
port=57400,
47+
username="admin",
48+
password="admin")
49+
# create CRUD service
50+
crud = CRUDService()
51+
52+
# create system time object
53+
system_time = xr_shellutil_oper.SystemTime()
54+
55+
# read system time from device
56+
system_time = crud.read(provider, system_time)
57+
58+
# print system uptime
59+
print("System '%s' uptime is "%system_time.uptime.host_name +
60+
str(timedelta(seconds=system_time.uptime.uptime)))
61+
62+
exit()

0 commit comments

Comments
 (0)