- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2020 09:20 AM
Trying in Python iterate over an list in service_01
I get this error:
errors: reason: Python cb_create error. 'ListElement' object has no attribute 'loopback'
--Python_
for i in (root.services.nso_dev_hop_01[service.service_01_name].loopback):
variables.add('loopback_ip', f' {loopback_ip}')
--Yang--
module service_01 {
namespace "http://example.com/service_01";
prefix service_01;
import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}
import tailf-ncs {
prefix ncs;
}
description
"Hand-Over-Point Service Model";
revision 2020-08-17 {
description
"Initial revision.";
}
augment /ncs:services {
list service_01 {
description "This is a service for Hand-Over-Point definition.";
key service_01_name;
leaf service_01_name {
tailf:info "Unique name of the Hand-Over-Point.";
type string;
mandatory true;
}
uses ncs:service-data;
ncs:servicepoint service_01-servicepoint;
// may replace this with other ways of refering to the devices.
leaf device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
mandatory true;
}
list loopback {
key loopback_id;
leaf loopback_id {
type uint16{
range "1000..10000";
}
mandatory true;
}
leaf loopback_ip {
type inet:ipv4-address;
mandatory true;
}
}
}
}
}
Solved! Go to Solution.
- Labels:
-
Other NSO Topics
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 05:33 AM - edited 08-23-2020 03:43 PM
Thanks again. Works now perfectly.
Indeed. The template wasn't applied under the for loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2020 10:54 AM
Hello,
So on the cb_create() callback, the service parameter points to root of the service instance that you are creating. So you don't need to use the key [service.service_01_name]
Would be more like this:
for i in service.loopback:
lbid = i.loopback_id
lbip = i.loopback_ip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2020 08:17 AM - edited 08-21-2020 08:19 AM
Thank you, is working now.
one more thing, it generate one loopback(last leaf values) only and not all three!
services service_01 AT
device ios0
loopback 444
loopback_ip 4.4.4.4
!
loopback 555
loopback_ip 5.5.5.5
!
loopback 777
loopback_ip 7.7.7.7
!
interface {
+ Loopback 777 {
+ ip-vrf {
+ ip {
+ vrf {
+ forwarding 33;
+ }
+ }
+ }
+ ip {
+ address {
+ primary {
+ address 7.7.7.7;
+ mask 255.255.255.255;
+ }
+ }
+ }
+ }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2020 09:39 AM
How are you applying your template in your python code?
Are you applying it once for each time through your Loopback code?
What does your template look like?
If you are using your python code just to get the looback_ip value and fill the variable to pass to the template and aren't using your python code to modify it, the loopback_ip can be passed directly from the service instance data into the template and looped to achieve config for all list elements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 05:33 AM - edited 08-23-2020 03:43 PM
Thanks again. Works now perfectly.
Indeed. The template wasn't applied under the for loop.
