11-02-2017 12:37 PM - edited 03-01-2019 04:02 AM
module nso-acl-python {
namespace "http://example.com/nso-acl-python";
prefix nso-acl-python;
import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}
import tailf-ncs {
prefix ncs;
}
description
"Bla bla...";
revision 2016-01-01 {
description
"Initial revision.";
}
augment /ncs:services{
list nso-acl-python {
uses ncs:service-data;
//ncs:servicepoint nso-acl-python-servicepoint;
description "ACL NAME";
key "acl_name";
leaf acl_name {
type string;
}
list CR_ID_QUEUE{
key "CR_ID";
uses ncs:service-data;
ncs:servicepoint nso-acl-cr-python-servicepoint;
leaf CR_ID{
type string;
}
leaf Source_IP{
type inet:ipv4-address;
}
leaf Source_Subnet{
type inet:ipv4-address;
}
// may replace this with other ways of refering to the devices.
leaf-list device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
description "WAN GWs for a particular site";
}
leaf-list acl_rule_ip{
type string;
}
leaf-list acl_rule_hostname{
type string;
}
tailf:action hostnametoip {
tailf:actionpoint nso-acl-python-hostnametoip-action;
tailf:info "Convert Hostname to IPS";
input {
leaf-list rule_hostname{
type string;
}
}
output {
leaf-list rule_ip{
type string;
}
}
}
}
}
}
}
I would like to save data returned from action "hostnametoip" in the service yang model acl_rule_ip. But I am not able to figure out Python code which would be able to call the Service from Action class.
It will be great if someone could help me figure out this ![]()
Thanks
11-02-2017 12:47 PM
So the output rule_ip should go into acl_rule_ip?
Why do you do this as an action and not in the service?
Maybe something like this in the action callback:
ip_addresses = XX, I assume you have the code in the action
service_instance_name = kp[N]
You'd have to figure out what index to use, maybe N=1
with maapi.single_write_transaction(uinfo.username, 'test') as th:
root = maagic.get_root(th)
svc = root.services.nso_acl_python[svc_instance_name]
svc.acl_rule_ip = ip_addresses
th.apply()
11-02-2017 02:32 PM
Thanks , it did help
I was trying to create an action for converting hostname to ip in ACL since a user may want to add/delete a hostname before pushing.
with ncs.maapi.single_write_trans('admin', 'python') as th:
root = maagic.get_root(th)
svc = root.services.nso_acl_python[kp[2][0]].CR_ID_QUEUE[kp[0][0]]
self.log.info("svc",svc)
svc.acl_rule_ip = output.acl_rule_ip
th.apply()
it worked for me ![]()
11-02-2017 02:37 PM
ok, glad you got it to work!
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