dropbox / nsot

Network Source of Truth is an open source IPAM and network inventory database
https://nsot.readthedocs.io
Other
399 stars 66 forks source link

Question: Create attribute dictionary #207

Open phil-dileo opened 8 years ago

phil-dileo commented 8 years ago

Hi - I've just started playing with nsot and I'm curious how you would do something like this:

Create attribute called 'vlans' where each item is a dict.

vlans: [
  { 
    'vlanid': '1',
    'name': 'production',
    'trunk_groups': [ 'tg1', 'tg2', 'tg3' ]
    'enable': 'true'
  },
  { 
    'vlanid': '2',
    'name': 'app',
    'trunk_groups': [ 'tg4', 'tg5', 'tg6' ]
    'enable': 'false'
  }
]
jathanism commented 8 years ago

This is not currently possible. Attribute values are currently limited to only strings, or a list of strings if multi=True. You could store the value of an attribute as a JSON-encoded string, but that's about it for now.

phil-dileo commented 8 years ago

Is it of interest? I could help contribute some code to do this if the framework of nsot can fit something like this in.

jathanism commented 8 years ago

Well, what are your thoughts on how you might use nested attribute data like this? Would you want to be able to search for nested values?

phil-dileo commented 8 years ago

I'd like to keep all data models in nsot and then pull it into Ansible which implements the configuration template via Jinja.

jathanism commented 8 years ago

If you're just using it for data storage, it seems having it designated as a JSON "type" could be a relatively quick win.

Perhaps a first step could be if that pattern works for you on the client side? And if it does we can talk about how it might work on the server side?

Currently, however, the value is limited to 255 bytes in length (it's a varchar(255)). That will also need to be taken into consideration.

coxley commented 8 years ago

Having this flexibility could be nice I think. It could help people who don't want to use attribute name prefixing to do similar grouping.

As far as querying, attr.key but that would need to restrict . from attribute names or at least dict type attribute names. A json type like you say could be easy too - let the user handle parsing/querying the return with jq and such.

[get value of vlans attribute] | jq '[].name'

lampwins commented 8 years ago

I would also like to put in my support for arbitrary model storage. I am looking to use NSOT as a one stop shop for device inventory and openconfig storage.

It would also be nice to leverage the interface and network objects from NSOT in the models too. This would probably call for some kind of openconfig generation built in though.