cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
789
Views
0
Helpful
2
Replies

NCS create function, key question

hwatson
Cisco Employee
Cisco Employee

Hi,

 

I wanted to create an nso db entry using create()  but had a question regarding the keys.

 

here's part of the yang model:

      list devices {                
          key "device_name";
          leaf device_name {
            type leafref {
              path "/ncs:devices/ncs:device/ncs:name";
            }
          }
          list flow_interfaces {
            key "interface_type interface_number";
            leaf interface_type{ type string;}
            leaf interface_number{ type string;}
            leaf interface_description{ type string;}
          }
        }

 

I have interface_type and interface_number as a combined key of two leaf entries.

when I use a create method on this path I can do the following:

 

new_row = root.ncs__services.FlowMonitor__FlowMonitor['TestGroup'].devices['testDevice']
            new_row.flow_interfaces.create({flow_interface['interface_type'],flow_interface['interface_number']}).interface_description = flow_interface['interface_description']

 

Most times this works, but now and then with 4.5.2  it places the interface_type and interface_number into different columns.    Is there a way to ensure the first key entry uses this order? is there some additional switch I can add?

Below is an example table I have where 1 entry is added in a different order.

 

interface_type interface_number interface_description
TenGigabitEthernet 1/0/0 some descr
TenGigabitEthernet 0/0/0 some descr
Tunnel 88 some descr
0/2/0 GigabitEthernet some descr

 

Thanks

Harry

2 Replies 2

vleijon
Cisco Employee
Cisco Employee

My guess would be that it depends on how the `set` that you are passing hashes, it ought to be 50/50 in the long run.

 

The documentation for create says:
```

create(self, *keys)Create and return a new list item with the key '*keys'.
 
Arguments can be a single 'maapi.Key' object or one value for each key
in the list. For a keyless in-memory list (eg in action parameters),
no argument should be given.

```

 

So, I would suggest doing that, that is trying:

```

new_row = root.ncs__services.FlowMonitor__FlowMonitor['TestGroup'].devices['testDevice']
            new_row.flow_interfaces.create(flow_interface['interface_type'],flow_interface['interface_number']).

```

thanks for getting back, much appreciated.

Indeed it was creating key with {} which causes the issue.

 

When removing that, the order is consistent.

 

Thanks again,

Harry