0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Genie Modelsで実現するModel Driven Pprogrammability

Last updated at Posted at 2021-08-28

初めに

DevNet Sandboxを使って簡単にpyATS/Genieを試すことができる非常に良い記事があるので、その記事を参考にしながらGenieのModelsを使ってDevices’ featuresの構造化アウトプットを試してみました。
(参考記事)

- DevNet Sandboxを使ってpyATS/XPRESSOをCML2と始めよう

Genieとは

Genieとは、pyATSフレームワークのモジュラーアーキテクチャにバンドルされているネットワークテスト自動化に必要なすべてのツールを含むpyATS用のPythonライブラリ。

Devices’ featuresの構造化出力

GenieのModelsを使用すると、Peasersで一度にいくつかのCLIを学習する代わりに、BGPやOSPF、INTERFACEなど各機能(feature)の全体を学習して、1つの構造化された出力(Json / Dictionary)にまとめることができます。 各機能(feature)はModelsによって抽象化され、すべてのOSに対して適用することができます。

testbed.yamlファイル

DevNet Sandboxの「Cisco pyATS XPRESSO」の環境でデモを実行します。
GenieのParsers、Models、Apisなどの各ライブラリを使用するためには、testbedというネットワーク構成を記載したyamlファイルが必要です。参考記事にもあるようにSandbox内にtestbed.yamlは準備されています。
また、前回記事にも掲載しています。
- Genie Parsersで実現するDevices’ outputsの構造化

pythonでの interfaceモデルを使用した構造化出力

interfaceモデルを使用して、CML2内の「core-rtr01」のインターフェースステータスを確認してみます。

(py3venv) [developer@devbox ~]$ python
Python 3.6.8 (default, Sep 14 2019, 14:33:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> from genie import testbed
>>> testbed = testbed.load('testbed.yaml')
>>> router_xr = testbed.devices['xr01']
>>> router_xr.connect()

2021-08-28 06:14:20,403: %UNICON-INFO: +++ core-rtr01 logfile /tmp/core-rtr01-cli-20210828T061420402.log +++

2021-08-28 06:14:20,404: %UNICON-INFO: +++ Unicon plugin iosxr +++
Trying 10.10.20.173...


2021-08-28 06:14:20,415: %UNICON-INFO: +++ connection to spawn: telnet 10.10.20.173 23, id: 139855480764288 +++

2021-08-28 06:14:20,415: %UNICON-INFO: connection to core-rtr01
Connected to 10.10.20.173.
Escape character is '^]'.



IMPORTANT:  READ CAREFULLY
Welcome to the Demo Version of Cisco IOS XRv (the "Software").
The Software is subject to and governed by the terms and conditions
of the End User License Agreement and the Supplemental End User
License Agreement accompanying the product, made available at the
time of your order, or posted on the Cisco website at
www.cisco.com/go/terms (collectively, the "Agreement").
As set forth more fully in the Agreement, use of the Software is
strictly limited to internal use in a non-production environment
solely for demonstration and evaluation purposes.  Downloading,
installing, or using the Software constitutes acceptance of the
Agreement, and you are binding yourself and the business entity
that you represent to the Agreement.  If you do not agree to all
of the terms of the Agreement, then Cisco is unwilling to license
the Software to you and (a) you may not download, install or use the
Software, and (b) you may return the Software as more fully set forth
in the Agreement.


Please login with any configured user/password, or cisco/cisco


User Access Verification

Username:
Username: cisco
Password:


RP/0/0/CPU0:core-rtr01#

2021-08-28 06:14:22,658: %UNICON-INFO: +++ initializing handle +++

2021-08-28 06:14:22,660: %UNICON-INFO: +++ core-rtr01: executing command 'terminal length 0' +++
terminal length 0
Sat Aug 28 13:14:21.758 UTC
RP/0/0/CPU0:core-rtr01#

2021-08-28 06:14:23,057: %UNICON-INFO: +++ core-rtr01: executing command 'terminal width 0' +++
terminal width 0
Sat Aug 28 13:14:22.148 UTC
RP/0/0/CPU0:core-rtr01#

2021-08-28 06:14:23,258: %UNICON-INFO: +++ core-rtr01: configure +++
configure terminal
Sat Aug 28 13:14:22.348 UTC
RP/0/0/CPU0:core-rtr01(config)#no logging console
RP/0/0/CPU0:core-rtr01(config)#logging console disable
RP/0/0/CPU0:core-rtr01(config)#line console
RP/0/0/CPU0:core-rtr01(config-line)#exec-timeout 0 0
RP/0/0/CPU0:core-rtr01(config-line)#absolute-timeout 0
RP/0/0/CPU0:core-rtr01(config-line)#session-timeout 0
RP/0/0/CPU0:core-rtr01(config-line)#line default
RP/0/0/CPU0:core-rtr01(config-line)#exec-timeout 0 0
RP/0/0/CPU0:core-rtr01(config-line)#absolute-timeout 0
RP/0/0/CPU0:core-rtr01(config-line)#session-timeout 0
RP/0/0/CPU0:core-rtr01(config-line)#commit
Sat Aug 28 13:14:23.447 UTC
RP/0/0/CPU0:core-rtr01(config-line)#end
RP/0/0/CPU0:core-rtr01#
>>>
>>>
>>>
>>> output = router_xr.learn('interface')

2021-08-28 06:15:01,702: %UNICON-INFO: +++ core-rtr01: executing command 'show vrf all detail' +++
show vrf all detail
Sat Aug 28 13:15:00.815 UTC

VRF Mgmt-intf; RD not set; VPN ID not set
VRF mode: Regular
Description not set
Interfaces:
  MgmtEth0/0/CPU0/0
Address family IPV4 Unicast
  No import VPN route-target communities
  No export VPN route-target communities
  No import route policy
  No export route policy
Address family IPV6 Unicast
  No import VPN route-target communities
  No export VPN route-target communities
  No import route policy
  No export route policy
RP/0/0/CPU0:core-rtr01#

2021-08-28 06:15:01,997: %UNICON-INFO: +++ core-rtr01: executing command 'show interface detail' +++
show interface detail
Sat Aug 28 13:15:01.085 UTC
Loopback0 is administratively down, line protocol is administratively down
  Interface state transitions: 2
  Hardware is Loopback interface(s)
  Description: to
  Internet address is Unknown
  MTU 1500 bytes, BW 0 Kbit
     reliability Unknown, txload Unknown, rxload Unknown
  Encapsulation Loopback,  loopback not set,
  Last link flapped 00:58:02
  Last input Unknown, output Unknown
  Last clearing of "show interface" counters Unknown
  Input/output data rate is disabled.

Null0 is up, line protocol is up
  Interface state transitions: 1
  Hardware is Null interface
  Internet address is Unknown
  MTU 1500 bytes, BW 0 Kbit
     reliability 255/255, txload Unknown, rxload Unknown
  Encapsulation Null,  loopback not set,
  Last link flapped 00:59:04
  Last input never, output never
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     0 packets input, 0 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 0 broadcast packets, 0 multicast packets
     0 packets output, 0 bytes, 0 total output drops
     Output 0 broadcast packets, 0 multicast packets

MgmtEth0/0/CPU0/0 is up, line protocol is up
  Interface state transitions: 1
  Hardware is Management Ethernet, address is 5254.001c.6715 (bia 5254.001c.6715)
  Description: to port4.sandbox-backend
  Internet address is 10.10.20.173/24
  MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit)
     reliability 255/255, txload 0/255, rxload 0/255
  Encapsulation ARPA,
  Duplex unknown, 1000Mb/s, unknown, link type is autonegotiation
  output flow control is off, input flow control is off
  Carrier delay (up) is 10 msec
  loopback not set,
  Last link flapped 00:58:05
  ARP type ARPA, ARP timeout 04:00:00
  Last input 00:00:00, output 00:00:00
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     216 packets input, 33771 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 28 broadcast packets, 140 multicast packets
              0 runts, 0 giants, 0 throttles, 0 parity
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     46 packets output, 5140 bytes, 0 total output drops
     Output 1 broadcast packets, 0 multicast packets
     0 output errors, 0 underruns, 0 applique, 0 resets
     0 output buffer failures, 0 output buffers swapped out
     1 carrier transitions

GigabitEthernet0/0/0/0 is up, line protocol is up
  Interface state transitions: 1
  Hardware is GigabitEthernet, address is 5254.0006.5ac0 (bia 5254.0006.5ac0)
  Description: L3 Link to core-rtr02
  Internet address is 172.16.252.37/30
  MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit)
     reliability 255/255, txload 0/255, rxload 0/255
  Encapsulation ARPA,
  Full-duplex, 1000Mb/s, unknown, link type is force-up
  output flow control is off, input flow control is off
  Carrier delay (up) is 10 msec
  loopback not set,
  Last link flapped 00:58:05
  ARP type ARPA, ARP timeout 04:00:00
  Last input 00:00:02, output 00:00:02
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     393 packets input, 42340 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 0 broadcast packets, 388 multicast packets
              0 runts, 0 giants, 0 throttles, 0 parity
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     406 packets output, 43816 bytes, 0 total output drops
     Output 2 broadcast packets, 397 multicast packets
     0 output errors, 0 underruns, 0 applique, 0 resets
     0 output buffer failures, 0 output buffers swapped out
     1 carrier transitions

GigabitEthernet0/0/0/1 is up, line protocol is up
  Interface state transitions: 1
  Hardware is GigabitEthernet, address is 5254.0001.78cb (bia 5254.0001.78cb)
  Description: L3 Link to edge-sw01
  Internet address is 172.16.253.2/29
  MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit)
     reliability 255/255, txload 0/255, rxload 0/255
  Encapsulation ARPA,
  Full-duplex, 1000Mb/s, unknown, link type is force-up
  output flow control is off, input flow control is off
  Carrier delay (up) is 10 msec
  loopback not set,
  Last link flapped 00:58:05
  ARP type ARPA, ARP timeout 04:00:00
  Last input 00:00:00, output 00:00:02
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 1 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     2509 packets input, 188426 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 1 broadcast packets, 2490 multicast packets
              0 runts, 0 giants, 0 throttles, 0 parity
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     407 packets output, 45770 bytes, 0 total output drops
     Output 2 broadcast packets, 386 multicast packets
     0 output errors, 0 underruns, 0 applique, 0 resets
     0 output buffer failures, 0 output buffers swapped out
     1 carrier transitions

GigabitEthernet0/0/0/2 is up, line protocol is up
  Interface state transitions: 1
  Hardware is GigabitEthernet, address is 5254.0015.f50f (bia 5254.0015.f50f)
  Description: L3 Link to dist-rtr01
  Internet address is 172.16.252.22/30
  MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit)
     reliability 255/255, txload 0/255, rxload 0/255
  Encapsulation ARPA,
  Full-duplex, 1000Mb/s, unknown, link type is force-up
  output flow control is off, input flow control is off
  Carrier delay (up) is 10 msec
  loopback not set,
  Last link flapped 00:58:05
  ARP type ARPA, ARP timeout 04:00:00
  Last input 00:00:02, output 00:00:02
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     388 packets input, 44774 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 1 broadcast packets, 384 multicast packets
              0 runts, 0 giants, 0 throttles, 0 parity
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     388 packets output, 41668 bytes, 0 total output drops
     Output 1 broadcast packets, 384 multicast packets
     0 output errors, 0 underruns, 0 applique, 0 resets
     0 output buffer failures, 0 output buffers swapped out
     1 carrier transitions

GigabitEthernet0/0/0/3 is up, line protocol is up
  Interface state transitions: 1
  Hardware is GigabitEthernet, address is 5254.0008.0346 (bia 5254.0008.0346)
  Description: L3 Link to dist-rtr02
  Internet address is 172.16.252.30/30
  MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit)
     reliability 255/255, txload 0/255, rxload 0/255
  Encapsulation ARPA,
  Full-duplex, 1000Mb/s, unknown, link type is force-up
  output flow control is off, input flow control is off
  Carrier delay (up) is 10 msec
  loopback not set,
  Last link flapped 00:58:05
  ARP type ARPA, ARP timeout 04:00:00
  Last input 00:00:00, output 00:00:02
  Last clearing of "show interface" counters never
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     392 packets input, 45318 bytes, 0 total input drops
     0 drops for unrecognized upper-level protocol
     Received 1 broadcast packets, 388 multicast packets
              0 runts, 0 giants, 0 throttles, 0 parity
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     394 packets output, 42360 bytes, 0 total output drops
     Output 1 broadcast packets, 390 multicast packets
     0 output errors, 0 underruns, 0 applique, 0 resets
     0 output buffer failures, 0 output buffers swapped out
     1 carrier transitions


RP/0/0/CPU0:core-rtr01#

2021-08-28 06:15:02,627: %UNICON-INFO: +++ core-rtr01: executing command 'show ethernet tags' +++
show ethernet tags
Sat Aug 28 13:15:01.715 UTC
St:    AD - Administratively Down, Dn - Down, Up - Up
Ly:    L2 - Switched layer 2 service, L3 = Terminated layer 3 service,
Xtra   C - Match on Cos, E  - Match on Ethertype, M - Match on source MAC
-,+:   Ingress rewrite operation; number of tags to pop and push respectively

Interface               St  MTU  Ly Outer            Inner            Xtra -,+
RP/0/0/CPU0:core-rtr01#

2021-08-28 06:15:02,960: %UNICON-INFO: +++ core-rtr01: executing command 'show interfaces accounting' +++
show interfaces accounting
Sat Aug 28 13:15:02.065 UTC
No accounting statistics available for Loopback0
No accounting statistics available for Null0
GigabitEthernet0/0/0/0
  Protocol              Pkts In         Chars In     Pkts Out        Chars Out
  IPV4_UNICAST              392            42280            6              840
  ARP                         1               60            2               84

GigabitEthernet0/0/0/1
  Protocol              Pkts In         Chars In     Pkts Out        Chars Out
  IPV4_UNICAST              801            85946           17             1920
  ARP                         2              120            3              126

GigabitEthernet0/0/0/2
  Protocol              Pkts In         Chars In     Pkts Out        Chars Out
  IPV4_UNICAST              386            44604            2              512
  ARP                         1               60            2               84

GigabitEthernet0/0/0/3
  Protocol              Pkts In         Chars In     Pkts Out        Chars Out
  IPV4_UNICAST              390            45148            2              492
  ARP                         1               60            2               84


MgmtEth0/0/CPU0/0
  Protocol              Pkts In         Chars In     Pkts Out        Chars Out
  IPV4_UNICAST               87             5527           78            14397
  ARP                        27             1620            5              210



RP/0/0/CPU0:core-rtr01#

2021-08-28 06:15:03,590: %UNICON-INFO: +++ core-rtr01: executing command 'show ipv4 vrf all interface' +++
show ipv4 vrf all interface
Sat Aug 28 13:15:02.685 UTC
Loopback0 is Shutdown, ipv4 protocol is Down
  Vrf is default (vrfid 0x60000000)
  Internet protocol processing disabled
MgmtEth0/0/CPU0/0 is Up, ipv4 protocol is Up
  Vrf is Mgmt-intf (vrfid 0x60000001)
  Internet address is 10.10.20.173/24
  MTU is 1514 (1500 is available to IP)
  Helper address is not set
  Multicast reserved groups joined: 224.0.0.2 224.0.0.1
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0xe0000010
GigabitEthernet0/0/0/0 is Up, ipv4 protocol is Up
  Vrf is default (vrfid 0x60000000)
  Internet address is 172.16.252.37/30
  MTU is 1514 (1500 is available to IP)
  Helper address is not set
  Multicast reserved groups joined: 224.0.0.2 224.0.0.1 224.0.0.5
      224.0.0.6
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0xe0000000
GigabitEthernet0/0/0/1 is Up, ipv4 protocol is Up
  Vrf is default (vrfid 0x60000000)
  Internet address is 172.16.253.2/29
  MTU is 1514 (1500 is available to IP)
  Helper address is not set
  Multicast reserved groups joined: 224.0.0.2 224.0.0.1 224.0.0.5
      224.0.0.6
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0xe0000000
GigabitEthernet0/0/0/2 is Up, ipv4 protocol is Up
  Vrf is default (vrfid 0x60000000)
  Internet address is 172.16.252.22/30
  MTU is 1514 (1500 is available to IP)
  Helper address is not set
  Multicast reserved groups joined: 224.0.0.2 224.0.0.1 224.0.0.5
      224.0.0.6
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0xe0000000
GigabitEthernet0/0/0/3 is Up, ipv4 protocol is Up
  Vrf is default (vrfid 0x60000000)
  Internet address is 172.16.252.30/30
  MTU is 1514 (1500 is available to IP)
  Helper address is not set
  Multicast reserved groups joined: 224.0.0.2 224.0.0.1 224.0.0.5
      224.0.0.6
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0xe0000000
RP/0/0/CPU0:core-rtr01#

2021-08-28 06:15:03,989: %UNICON-INFO: +++ core-rtr01: executing command 'show ipv6 vrf all interface' +++
show ipv6 vrf all interface
Sat Aug 28 13:15:03.085 UTC
Loopback0 is Shutdown, ipv6 protocol is Down, Vrfid is default (0x60000000)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
MgmtEth0/0/CPU0/0 is Up, ipv6 protocol is Up, Vrfid is Mgmt-intf (0x60000001)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
GigabitEthernet0/0/0/0 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
GigabitEthernet0/0/0/1 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
GigabitEthernet0/0/0/2 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
GigabitEthernet0/0/0/3 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000)
  IPv6 is disabled, link-local address unassigned
  No global unicast address is configured
RP/0/0/CPU0:core-rtr01#
>>>
>>>
>>>
>>> import pprint
>>> pprint.pprint(output.info)
{'GigabitEthernet0/0/0/0': {'accounting': {'arp': {'chars_in': 60,
                                                   'chars_out': 84,
                                                   'pkts_in': 1,
                                                   'pkts_out': 2},
                                           'ipv4_unicast': {'chars_in': 42280,
                                                            'chars_out': 840,
                                                            'pkts_in': 392,
                                                            'pkts_out': 6}},
                            'auto_negotiate': False,
                            'bandwidth': 1000000,
                            'counters': {'in_broadcast_pkts': 0,
                                         'in_crc_errors': 0,
                                         'in_discards': 0,
                                         'in_multicast_pkts': 388,
                                         'in_octets': 42340,
                                         'in_pkts': 393,
                                         'last_clear': 'never',
                                         'out_broadcast_pkts': 2,
                                         'out_errors': 0,
                                         'out_multicast_pkts': 397,
                                         'out_octets': 43816,
                                         'out_pkts': 406,
                                         'rate': {'in_rate': 0,
                                                  'in_rate_pkts': 0,
                                                  'load_interval': 300,
                                                  'out_rate': 0,
                                                  'out_rate_pkts': 0}},
                            'description': 'L3 Link to core-rtr02',
                            'duplex_mode': 'full',
                            'enabled': True,
                            'encapsulation': {'encapsulation': 'arpa'},
                            'flow_control': {'flow_control_receive': False,
                                             'flow_control_send': False},
                            'ipv4': {'172.16.252.37/30': {'ip': '172.16.252.37',
                                                          'prefix_length': '30'}},
                            'ipv6': {'enabled': True},
                            'mac_address': '5254.0006.5ac0',
                            'mtu': 1514,
                            'oper_status': 'up',
                            'phys_address': '5254.0006.5ac0',
                            'port_speed': '1000Mb/s',
                            'type': 'gigabitethernet'},
 'GigabitEthernet0/0/0/1': {'accounting': {'arp': {'chars_in': 120,
                                                   'chars_out': 126,
                                                   'pkts_in': 2,
                                                   'pkts_out': 3},
                                           'ipv4_unicast': {'chars_in': 85946,
                                                            'chars_out': 1920,
                                                            'pkts_in': 801,
                                                            'pkts_out': 17}},
                            'auto_negotiate': False,
                            'bandwidth': 1000000,
                            'counters': {'in_broadcast_pkts': 1,
                                         'in_crc_errors': 0,
                                         'in_discards': 0,
                                         'in_multicast_pkts': 2490,
                                         'in_octets': 188426,
                                         'in_pkts': 2509,
                                         'last_clear': 'never',
                                         'out_broadcast_pkts': 2,
                                         'out_errors': 0,
                                         'out_multicast_pkts': 386,
                                         'out_octets': 45770,
                                         'out_pkts': 407,
                                         'rate': {'in_rate': 0,
                                                  'in_rate_pkts': 1,
                                                  'load_interval': 300,
                                                  'out_rate': 0,
                                                  'out_rate_pkts': 0}},
                            'description': 'L3 Link to edge-sw01',
                            'duplex_mode': 'full',
                            'enabled': True,
                            'encapsulation': {'encapsulation': 'arpa'},
                            'flow_control': {'flow_control_receive': False,
                                             'flow_control_send': False},
                            'ipv4': {'172.16.253.2/29': {'ip': '172.16.253.2',
                                                         'prefix_length': '29'}},
                            'ipv6': {'enabled': True},
                            'mac_address': '5254.0001.78cb',
                            'mtu': 1514,
                            'oper_status': 'up',
                            'phys_address': '5254.0001.78cb',
                            'port_speed': '1000Mb/s',
                            'type': 'gigabitethernet'},
 'GigabitEthernet0/0/0/2': {'accounting': {'arp': {'chars_in': 60,
                                                   'chars_out': 84,
                                                   'pkts_in': 1,
                                                   'pkts_out': 2},
                                           'ipv4_unicast': {'chars_in': 44604,
                                                            'chars_out': 512,
                                                            'pkts_in': 386,
                                                            'pkts_out': 2}},
                            'auto_negotiate': False,
                            'bandwidth': 1000000,
                            'counters': {'in_broadcast_pkts': 1,
                                         'in_crc_errors': 0,
                                         'in_discards': 0,
                                         'in_multicast_pkts': 384,
                                         'in_octets': 44774,
                                         'in_pkts': 388,
                                         'last_clear': 'never',
                                         'out_broadcast_pkts': 1,
                                         'out_errors': 0,
                                         'out_multicast_pkts': 384,
                                         'out_octets': 41668,
                                         'out_pkts': 388,
                                         'rate': {'in_rate': 0,
                                                  'in_rate_pkts': 0,
                                                  'load_interval': 300,
                                                  'out_rate': 0,
                                                  'out_rate_pkts': 0}},
                            'description': 'L3 Link to dist-rtr01',
                            'duplex_mode': 'full',
                            'enabled': True,
                            'encapsulation': {'encapsulation': 'arpa'},
                            'flow_control': {'flow_control_receive': False,
                                             'flow_control_send': False},
                            'ipv4': {'172.16.252.22/30': {'ip': '172.16.252.22',
                                                          'prefix_length': '30'}},
                            'ipv6': {'enabled': True},
                            'mac_address': '5254.0015.f50f',
                            'mtu': 1514,
                            'oper_status': 'up',
                            'phys_address': '5254.0015.f50f',
                            'port_speed': '1000Mb/s',
                            'type': 'gigabitethernet'},
 'GigabitEthernet0/0/0/3': {'accounting': {'arp': {'chars_in': 60,
                                                   'chars_out': 84,
                                                   'pkts_in': 1,
                                                   'pkts_out': 2},
                                           'ipv4_unicast': {'chars_in': 45148,
                                                            'chars_out': 492,
                                                            'pkts_in': 390,
                                                            'pkts_out': 2}},
                            'auto_negotiate': False,
                            'bandwidth': 1000000,
                            'counters': {'in_broadcast_pkts': 1,
                                         'in_crc_errors': 0,
                                         'in_discards': 0,
                                         'in_multicast_pkts': 388,
                                         'in_octets': 45318,
                                         'in_pkts': 392,
                                         'last_clear': 'never',
                                         'out_broadcast_pkts': 1,
                                         'out_errors': 0,
                                         'out_multicast_pkts': 390,
                                         'out_octets': 42360,
                                         'out_pkts': 394,
                                         'rate': {'in_rate': 0,
                                                  'in_rate_pkts': 0,
                                                  'load_interval': 300,
                                                  'out_rate': 0,
                                                  'out_rate_pkts': 0}},
                            'description': 'L3 Link to dist-rtr02',
                            'duplex_mode': 'full',
                            'enabled': True,
                            'encapsulation': {'encapsulation': 'arpa'},
                            'flow_control': {'flow_control_receive': False,
                                             'flow_control_send': False},
                            'ipv4': {'172.16.252.30/30': {'ip': '172.16.252.30',
                                                          'prefix_length': '30'}},
                            'ipv6': {'enabled': True},
                            'mac_address': '5254.0008.0346',
                            'mtu': 1514,
                            'oper_status': 'up',
                            'phys_address': '5254.0008.0346',
                            'port_speed': '1000Mb/s',
                            'type': 'gigabitethernet'},
 'Loopback0': {'bandwidth': 0,
               'description': 'to',
               'enabled': False,
               'encapsulation': {'encapsulation': 'loopback'},
               'ipv6': {'enabled': False},
               'mtu': 1500,
               'oper_status': 'down'},
 'MgmtEth0/0/CPU0/0': {'accounting': {'arp': {'chars_in': 1620,
                                              'chars_out': 210,
                                              'pkts_in': 27,
                                              'pkts_out': 5},
                                      'ipv4_unicast': {'chars_in': 5527,
                                                       'chars_out': 14397,
                                                       'pkts_in': 87,
                                                       'pkts_out': 78}},
                       'auto_negotiate': True,
                       'bandwidth': 1000000,
                       'counters': {'in_broadcast_pkts': 28,
                                    'in_crc_errors': 0,
                                    'in_discards': 0,
                                    'in_multicast_pkts': 140,
                                    'in_octets': 33771,
                                    'in_pkts': 216,
                                    'last_clear': 'never',
                                    'out_broadcast_pkts': 1,
                                    'out_errors': 0,
                                    'out_multicast_pkts': 0,
                                    'out_octets': 5140,
                                    'out_pkts': 46,
                                    'rate': {'in_rate': 0,
                                             'in_rate_pkts': 0,
                                             'load_interval': 300,
                                             'out_rate': 0,
                                             'out_rate_pkts': 0}},
                       'description': 'to port4.sandbox-backend',
                       'duplex_mode': 'duplex unknown',
                       'enabled': True,
                       'encapsulation': {'encapsulation': 'arpa'},
                       'flow_control': {'flow_control_receive': False,
                                        'flow_control_send': False},
                       'ipv4': {'10.10.20.173/24': {'ip': '10.10.20.173',
                                                    'prefix_length': '24'}},
                       'ipv6': {'enabled': True},
                       'mac_address': '5254.001c.6715',
                       'mtu': 1514,
                       'oper_status': 'up',
                       'phys_address': '5254.001c.6715',
                       'port_speed': '1000',
                       'type': 'management ethernet'},
 'Null0': {'bandwidth': 0,
           'counters': {'in_broadcast_pkts': 0,
                        'in_discards': 0,
                        'in_multicast_pkts': 0,
                        'in_octets': 0,
                        'in_pkts': 0,
                        'last_clear': 'never',
                        'out_broadcast_pkts': 0,
                        'out_multicast_pkts': 0,
                        'out_octets': 0,
                        'out_pkts': 0,
                        'rate': {'in_rate': 0,
                                 'in_rate_pkts': 0,
                                 'load_interval': 300,
                                 'out_rate': 0,
                                 'out_rate_pkts': 0}},
           'enabled': True,
           'encapsulation': {'encapsulation': 'null'},
           'mtu': 1500,
           'oper_status': 'up',
           'type': 'null'}}
>>>

インターフェースのステータスが辞書型に構造化され出力されました。一つの showコマンドを構造化するParsersとは違い、複数の showコマンドでステータスを確認していることがわかります。
このように各機能(feature)がまるでyangのようにモデル化されているので、プログラミング環境でモデル駆動的にステータスを出力することができます。さらに、各機能が全てのOSに対応するよう抽象的にモデル化されているので、OSを意識することなく活用でき非常に便利です。
なお、feature毎にサポートされているModelsはこちらです。

参考リンク

- DevNet Sandboxを使ってpyATS/XPRESSOをCML2と始めよう
- Genie Parsersで実現するDevices’ outputsの構造化
- Genie Documentation
- genie-feature-browser

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?