Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look_up for values with minus character #55

Open
TribuneX opened this issue Jun 22, 2020 · 4 comments
Open

look_up for values with minus character #55

TribuneX opened this issue Jun 22, 2020 · 4 comments

Comments

@TribuneX
Copy link

Hi,

how can I lookup values with have a minus character in their key field?

E.g.

list user {
    key "user-name";

    leaf user-name {
        type string;
    }
}

Something like value = instance_value.look_up(username=admin) does not work obviously.

Thanks!

@iwanb
Copy link

iwanb commented Jun 22, 2020

You can still pass invalid Python identifiers like this:

value = instance_value.look_up(**{'user_name': 'admin'})

@TribuneX
Copy link
Author

Thanks. This works. However, the interface feels complex.
Why not provide a simpler version? Something like that:

value = instance_value.look_up(key='user-name', value='admin')

@metaswitch-colin-haywood
Copy link

metaswitch-colin-haywood commented Jan 5, 2021

Thanks. This works. However, the interface feels complex.
Why not provide a simpler version? Something like that:

value = instance_value.look_up(key='user-name', value='admin')

YANG lists can have multiple fields in their primary key, e.g.

list mylist {
  key "field1 field2";
...
}

As such the look_up function needs to take multiple key/value pairs at the same time, hence it taking a dict/kwargs. It's not specified in the docs, but I'd expect that it would indeed reject any dict that doesn't contain all the relevant key fields that the list in question has.

@llhotka
Copy link
Member

llhotka commented Jan 5, 2021

Actually, as it is implemented, the keys argument needn't contain all keys, and they even needn't be keys as defined in YANG. The first entry found that matches the specified lookup keys is returned. I am not sure if it is good or bad, but at least a lookup is possible also for non-config lists that have no keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants