Created
December 14, 2017 19:49
-
-
Save 111pontes/2c5ea165683524dc44e401b619bfa6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Copyright 2016 Cisco Systems, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
""" | |
Read all data for model Cisco-IOS-XR-plat-chas-invmgr-oper. | |
usage: nc-read-xr-plat-chas-invmgr-oper-11-ydk.py [-h] [-v] device | |
positional arguments: | |
device NETCONF device (ssh://user:password@host:port) | |
optional arguments: | |
-h, --help show this help message and exit | |
-v, --verbose print debugging messages | |
""" | |
from argparse import ArgumentParser | |
from urlparse import urlparse | |
from ydk.services import CRUDService, CodecService | |
from ydk.providers import NetconfServiceProvider, CodecServiceProvider | |
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_plat_chas_invmgr_oper \ | |
as xr_plat_chas_invmgr_oper | |
import logging | |
def process_platform_inventory(platform_inventory): | |
"""Process data in platform_inventory object.""" | |
pass | |
if __name__ == "__main__": | |
"""Execute main program.""" | |
parser = ArgumentParser() | |
parser.add_argument("-v", "--verbose", help="print debugging messages", | |
action="store_true") | |
parser.add_argument("device", | |
help="NETCONF device (ssh://user:password@host: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.INFO) | |
handler = logging.StreamHandler() | |
formatter = logging.Formatter(("%(asctime)s - %(name)s - " | |
"%(levelname)s - %(message)s")) | |
handler.setFormatter(formatter) | |
logger.addHandler(handler) | |
# create NETCONF provider | |
nc_provider = NetconfServiceProvider(address=device.hostname, | |
port=device.port, | |
username=device.username, | |
password=device.password, | |
protocol=device.scheme) | |
# create CRUD service | |
crud = CRUDService() | |
# create codec provider | |
cd_provider = CodecServiceProvider(type="xml") | |
# create codec service | |
codec = CodecService() | |
platform_inventory = xr_plat_chas_invmgr_oper.PlatformInventory() # create object | |
# read data from NETCONF device | |
platform_inventory = crud.read(nc_provider, platform_inventory) | |
# encode and print object | |
print(codec.encode(cd_provider, platform_inventory)) | |
#process_platform_inventory(platform_inventory) # process object data | |
exit() | |
# End of script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<platform-inventory xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-plat-chas-invmgr-oper"> | |
<racks> | |
<rack> | |
<name>0</name> | |
<attributes> | |
<basic-info> | |
<firmware-revision/> | |
<hardware-revision>V01</hardware-revision> | |
<software-revision>6.3.2.21I | |
</software-revision> | |
<name>Rack 0</name> | |
<is-field-replaceable-unit>true</is-field-replaceable-unit> | |
<serial-number>F2297C4D403</serial-number> | |
<vendor-type>1.3.6.1.4.1.9.12.3.1.3.1304</vendor-type> | |
<model-name>R-IOSXRV9000-CC</model-name> | |
<description>Cisco XRv9K Centralized Virtual Router</description> | |
</basic-info> | |
<fru-info> | |
<module-operational-state>inv-card-unknown</module-operational-state> | |
<module-administrative-state>admin-down</module-administrative-state> | |
<module-reset-reason>module-reset-reason-unknown</module-reset-reason> | |
<module-power-administrative-state>admin-off</module-power-administrative-state> | |
<module-monitor-state>unmonitored</module-monitor-state> | |
<last-operational-state-change> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>0</time-in-seconds> | |
</last-operational-state-change> | |
<module-up-time> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>0</time-in-seconds> | |
</module-up-time> | |
</fru-info> | |
</attributes> | |
<slots> | |
<slot> | |
<name>0</name> | |
<attributes> | |
<basic-info> | |
<firmware-revision/> | |
<hardware-revision/> | |
<software-revision/> | |
<name>Rack 0-Line Card Slot 0</name> | |
<is-field-replaceable-unit>false</is-field-replaceable-unit> | |
<serial-number/> | |
<vendor-type>1.3.6.1.4.1.9.12.3.1.5.276</vendor-type> | |
<model-name>N/A</model-name> | |
<description>Cisco XRv9K Line Card Slot</description> | |
</basic-info> | |
</attributes> | |
<cards> | |
<card> | |
<name>0</name> | |
<attributes> | |
<basic-info> | |
<firmware-revision/> | |
<hardware-revision>V01</hardware-revision> | |
<software-revision>6.3.2.21I | |
</software-revision> | |
<name>0/0</name> | |
<is-field-replaceable-unit>true</is-field-replaceable-unit> | |
<serial-number>F88AABF74E7</serial-number> | |
<vendor-type>1.3.6.1.4.1.9.12.3.1.9.2.406</vendor-type> | |
<model-name>R-IOSXRV9000-LC-C</model-name> | |
<description>Cisco XRv9K Centralized Line Card</description> | |
</basic-info> | |
<fru-info> | |
<module-operational-state>inv-card-running-ena</module-operational-state> | |
<module-administrative-state>admin-up</module-administrative-state> | |
<module-reset-reason>module-reset-reason-powerup</module-reset-reason> | |
<module-power-administrative-state>admin-on</module-power-administrative-state> | |
<module-monitor-state>unmonitored</module-monitor-state> | |
<last-operational-state-change> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>1513132116</time-in-seconds> | |
</last-operational-state-change> | |
<module-up-time> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>1</time-in-seconds> | |
</module-up-time> | |
</fru-info> | |
</attributes> | |
</card> | |
</cards> | |
</slot> | |
<slot> | |
<name>16</name> | |
<attributes> | |
<basic-info> | |
<firmware-revision/> | |
<hardware-revision/> | |
<software-revision/> | |
<name>Rack 0-Route Processor Slot 0</name> | |
<is-field-replaceable-unit>false</is-field-replaceable-unit> | |
<serial-number/> | |
<vendor-type>1.3.6.1.4.1.9.12.3.1.5.275</vendor-type> | |
<model-name>N/A</model-name> | |
<description>Cisco XRv9K Route Processor Slot</description> | |
</basic-info> | |
</attributes> | |
<cards> | |
<card> | |
<name>0</name> | |
<attributes> | |
<basic-info> | |
<firmware-revision/> | |
<hardware-revision>V01</hardware-revision> | |
<software-revision>6.3.2.21I | |
</software-revision> | |
<name>0/RP0</name> | |
<is-field-replaceable-unit>true</is-field-replaceable-unit> | |
<serial-number>A8082B35B2B</serial-number> | |
<vendor-type>1.3.6.1.4.1.9.12.3.1.9.2.406</vendor-type> | |
<model-name>R-IOSXRV9000-RP-C</model-name> | |
<description>Cisco XRv9K Centralized Route Processor</description> | |
</basic-info> | |
<fru-info> | |
<module-operational-state>inv-card-running-ena</module-operational-state> | |
<module-administrative-state>admin-up</module-administrative-state> | |
<module-reset-reason>module-reset-reason-powerup</module-reset-reason> | |
<module-power-administrative-state>admin-on</module-power-administrative-state> | |
<module-monitor-state>unmonitored</module-monitor-state> | |
<last-operational-state-change> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>1513131811</time-in-seconds> | |
</last-operational-state-change> | |
<module-up-time> | |
<time-in-nano-seconds>0</time-in-nano-seconds> | |
<time-in-seconds>268</time-in-seconds> | |
</module-up-time> | |
</fru-info> | |
</attributes> | |
</card> | |
</cards> | |
</slot> | |
</slots> | |
</rack> | |
</racks> | |
</platform-inventory> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment