02-17-2020 09:31 AM
Hi All,
I'm trying to configure the SRGB value in ISIS to set the lower and upper bounds of the global label pool for segment routing using YDK and Cisco-IOS-XR-clns-isis-cfg.
module: Cisco-IOS-XR-clns-isis-cfg
+--rw isis
+--rw instances
+--rw instance* [instance-name]
+--rw srgb!
| +--rw lower-bound uint32
| +--rw upper-bound uint32
To achieve this config:
router isis 1
segment-routing global-block <number> <number>
However getting the below error, and I have no idea why. Can anyone help? I am probably doing something very stupid, but it looks good to me per the pyang output. Cheers for any help.
>>> instance = cisco_isis.Isis.Instances.Instance()
>>> instance.srgb.lower_bound = 76800
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'lower_bound'
>>>
Solved! Go to Solution.
02-18-2020 07:06 PM - edited 02-18-2020 07:07 PM
See below a script that pushes that config. Note that SRGB is a presence container, so the object has to be instantiated explicitly.
#!/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.
#
"""
Create configuration for model Cisco-IOS-XR-clns-isis-cfg.
usage: nc-create-xr-clns-isis-cfg-60-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
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_clns_isis_cfg \
as xr_clns_isis_cfg
from ydk.types import Empty
import logging
def config_isis(isis):
"""Add config data to isis object."""
# global configuration
instance = isis.instances.Instance()
instance.instance_name = "1"
instance.running = Empty()
instance.srgb = instance.Srgb()
instance.srgb.lower_bound = 17000
instance.srgb.upper_bound = 27000
isis.instances.instance.append(instance)
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
provider = NetconfServiceProvider(address=device.hostname,
port=device.port,
username=device.username,
password=device.password,
protocol=device.scheme)
# create CRUD service
crud = CRUDService()
isis = xr_clns_isis_cfg.Isis() # create object
config_isis(isis) # add object configuration
# create configuration on NETCONF device
crud.create(provider, isis)
exit()
# End of script
Log:
$ ./nc-create-xr-clns-isis-cfg-99-ydk.py ssh://user:password@host -v
2020-02-18 19:01:50,955 - ydk - INFO - Path where models are to be downloaded: /home/saalvare/.ydk/pavarotti
2020-02-18 19:01:50,967 - ydk - INFO - Connected to pavarotti on port 830 using ssh with timeout of -1
2020-02-18 19:01:50,974 - ydk - INFO - Executing CRUD create operation on [Cisco-IOS-XR-clns-isis-cfg:isis]
2020-02-18 19:01:50,975 - ydk - INFO - Executing 'edit-config' RPC on [Cisco-IOS-XR-clns-isis-cfg:isis]
2020-02-18 19:01:51,001 - ydk - INFO - ============= Sending RPC to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<candidate/>
</target>
<config><isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-cfg" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<instances>
<instance>
<instance-name>1</instance-name>
<running/>
<srgb>
<lower-bound>17000</lower-bound>
<upper-bound>27000</upper-bound>
</srgb>
</instance>
</instances>
</isis>
</config>
</edit-config>
</rpc>
2020-02-18 19:01:51,303 - ydk - INFO - ============= Received RPC from device =============
<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
2020-02-18 19:01:51,303 - ydk - INFO - Executing 'commit' RPC
2020-02-18 19:01:51,304 - ydk - INFO - ============= Sending RPC to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><commit xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"/>
</rpc>
2020-02-18 19:01:52,362 - ydk - INFO - ============= Received RPC from device =============
<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>
2020-02-18 19:01:52,362 - ydk - INFO - Operation succeeded
2020-02-18 19:01:52,368 - ydk - INFO - Disconnected from device
$
02-17-2020 09:33 AM
Should've said, imported the yang file as cisco_isis as below as well:
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_clns_isis_cfg as cisco_isis
02-18-2020 09:37 AM
It is not clear from your post, how you are going to configure ISIS, what protocol and service your are going to use. Full script and DEBUG log would be helpful.
In the meanwhile, I think the main issue is that you did not define correctly the instance object. It is a member of the list from class Instances and must be defined properly. There are multiple examples published for you to help.
02-19-2020 08:59 AM
The alias used in the import statement irrelevant. Obviously, you need to make sure you're consistent throughout your script in all references. I like 'xr_clns_isis_cfg' in the following import statement.
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_clns_isis_cfg \
as xr_clns_isis_cfg
It strikes a balance between shortening the name a little bit and being descriptive and unambiguous.
02-18-2020 07:06 PM - edited 02-18-2020 07:07 PM
See below a script that pushes that config. Note that SRGB is a presence container, so the object has to be instantiated explicitly.
#!/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.
#
"""
Create configuration for model Cisco-IOS-XR-clns-isis-cfg.
usage: nc-create-xr-clns-isis-cfg-60-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
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_clns_isis_cfg \
as xr_clns_isis_cfg
from ydk.types import Empty
import logging
def config_isis(isis):
"""Add config data to isis object."""
# global configuration
instance = isis.instances.Instance()
instance.instance_name = "1"
instance.running = Empty()
instance.srgb = instance.Srgb()
instance.srgb.lower_bound = 17000
instance.srgb.upper_bound = 27000
isis.instances.instance.append(instance)
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
provider = NetconfServiceProvider(address=device.hostname,
port=device.port,
username=device.username,
password=device.password,
protocol=device.scheme)
# create CRUD service
crud = CRUDService()
isis = xr_clns_isis_cfg.Isis() # create object
config_isis(isis) # add object configuration
# create configuration on NETCONF device
crud.create(provider, isis)
exit()
# End of script
Log:
$ ./nc-create-xr-clns-isis-cfg-99-ydk.py ssh://user:password@host -v
2020-02-18 19:01:50,955 - ydk - INFO - Path where models are to be downloaded: /home/saalvare/.ydk/pavarotti
2020-02-18 19:01:50,967 - ydk - INFO - Connected to pavarotti on port 830 using ssh with timeout of -1
2020-02-18 19:01:50,974 - ydk - INFO - Executing CRUD create operation on [Cisco-IOS-XR-clns-isis-cfg:isis]
2020-02-18 19:01:50,975 - ydk - INFO - Executing 'edit-config' RPC on [Cisco-IOS-XR-clns-isis-cfg:isis]
2020-02-18 19:01:51,001 - ydk - INFO - ============= Sending RPC to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<candidate/>
</target>
<config><isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-cfg" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<instances>
<instance>
<instance-name>1</instance-name>
<running/>
<srgb>
<lower-bound>17000</lower-bound>
<upper-bound>27000</upper-bound>
</srgb>
</instance>
</instances>
</isis>
</config>
</edit-config>
</rpc>
2020-02-18 19:01:51,303 - ydk - INFO - ============= Received RPC from device =============
<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
2020-02-18 19:01:51,303 - ydk - INFO - Executing 'commit' RPC
2020-02-18 19:01:51,304 - ydk - INFO - ============= Sending RPC to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><commit xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"/>
</rpc>
2020-02-18 19:01:52,362 - ydk - INFO - ============= Received RPC from device =============
<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<ok/>
</rpc-reply>
2020-02-18 19:01:52,362 - ydk - INFO - Operation succeeded
2020-02-18 19:01:52,368 - ydk - INFO - Disconnected from device
$
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide