cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1170
Views
1
Helpful
2
Replies

create a key value pair in python maagic

peter.z.larsson
Level 1
Level 1

I can't figure out how to create a key value pair via python maagic api.

I have an ciso ios-xr device and want to add a community-set. Like this:

community-set CS-CORE_REGION_ID-LOCAL

  39651:1099

end-set

I have the community-set defined in ncs but without any value:

admin@ncs% show devices device sth0-ser0 config cisco-ios-xr:community-set CS-CORE_REGION_ID-LOCAL | display json

{

  "data": {

    "tailf-ncs:devices": {

      "device": [

        {

          "name": "sth0-ser0",

          "config": {

            "tailf-ned-cisco-ios-xr:community-set": [

              {

                "name": "CS-CORE_REGION_ID-LOCAL"

              }

            ]

          }

        }

      ]

    }

  }

}

[ok][2017-10-19 18:02:39]

I can create a new key "set" by:

                for cs in root.devices.device[bng_id[0]["name"]].config.cisco_ios_xr__community_set:

                    if cs.name == "CS-CORE_REGION_ID-LOCAL":

                        rt_val = "39651:" + bng_id[0]["region_cs"]

                        cs.set.create

                        cs.set["value"].create

                        cs.set.value = rt_val

                        print(cs.set)

I get te following output error when running the script:

Traceback (most recent call last):

  File "import-sp-data-itux-bng-ver1.py", line 153, in <module>

    main()

  File "import-sp-data-itux-bng-ver1.py", line 149, in main

    set_sp_id(bng_id)

  File "import-sp-data-itux-bng-ver1.py", line 75, in set_sp_id

    cs.set["value"].create

  File "/home/peter/ncs-4.4.2/src/ncs/pyapi/ncs/maagic.py", line 1037, in __getitem__

    raise KeyError('%s not in %s' % (keystr, self._path))

KeyError: '{value} not in /ncs:devices/device{sth0-ser0}/config/cisco-ios-xr:community-set{CS-CORE_REGION_ID-LOCAL}/set'

Any idea what needs to be changed?

1 Accepted Solution

Accepted Solutions

Thanks Fredrik, you guided me in the correct direction.

s = cs.set.create(rt_val)

Did the work.

View solution in original post

2 Replies 2

frjansso
Cisco Employee
Cisco Employee

Not sure about the YANG model here, but I have two ideas:

cs.set.value = rt_val

- OR -

s = cs.set.create()

s.value = rt_val

Thanks Fredrik, you guided me in the correct direction.

s = cs.set.create(rt_val)

Did the work.

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?