cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
882
Views
5
Helpful
3
Replies

How to save data returned from Action in a Yang leaf-list of a service?

pranayk2
Cisco Employee
Cisco Employee

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

3 Replies 3

frjansso
Cisco Employee
Cisco Employee

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()

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

ok, glad you got it to work!