nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
36 stars 32 forks source link

Resolves #71 - updating to account for json type custom field #72

Closed whitej6 closed 2 years ago

whitej6 commented 2 years ago

I need someone with prior knowledge on this SDK to confirm we no longer need this function. as my local testing with nautobot v1.4.1 I cannot get that function to be triggered.

glennmatthews commented 2 years ago

Looking at the changed test, can we confirm that it still works with select/multi-select custom fields?

whitej6 commented 2 years ago

@glennmatthews I will look into that, I was wondering how/where that came into play.

whitej6 commented 2 years ago

@glennmatthews Here is an output of a JSON, text, select & multi-select CF on one device

In [1]: import pynautobot

In [2]: nautobot = pynautobot.api(url="https://nautobot.whitej6.com", token="0123456789abcdef0123456789abcdef01234567")

In [3]: device = nautobot.dcim.devices.all()[0]

In [4]: device.custom_fields
Out[4]: 
{'json_test': {'bar': 'baz', 'foo': 1},
 'multi_select': ['bar', 'baz'],
 'non_json': 'i am not json',
 'select': 'bar'}

In [5]: device.serialize()
Out[5]: 
{'id': '814b329b-970b-4fc5-b688-52a0db6a7839',
 'display': 'DFW-WAN00',
 'url': 'https://nautobot.whitej6.com/api/dcim/devices/814b329b-970b-4fc5-b688-52a0db6a7839/',
 'name': 'DFW-WAN00',
 'device_type': '2194fdb7-1bb3-4419-a78e-690607a04f4d',
 'device_role': '637f1db1-1656-4ebd-813c-0cf0f22d1747',
 'tenant': None,
 'platform': '76748b6b-6e3b-4a51-b998-df468031ec37',
 'serial': '',
 'asset_tag': None,
 'site': 'b3186e80-fc91-4f28-9674-d030cbc96865',
 'location': None,
 'rack': None,
 'position': None,
 'face': None,
 'parent_device': None,
 'status': 'active',
 'primary_ip': None,
 'primary_ip4': None,
 'primary_ip6': None,
 'secrets_group': None,
 'cluster': None,
 'virtual_chassis': None,
 'vc_position': None,
 'vc_priority': None,
 'comments': '',
 'local_context_schema': None,
 'local_context_data': None,
 'config_context': {},
 'created': '2022-08-29',
 'last_updated': '2022-08-29T19:33:01.960120Z',
 'tags': [],
 'notes_url': 'https://nautobot.whitej6.com/api/dcim/devices/814b329b-970b-4fc5-b688-52a0db6a7839/notes/',
 'custom_fields': {'json_test': {'bar': 'baz', 'foo': 1},
  'multi_select': ['bar', 'baz'],
  'non_json': 'i am not json',
  'select': 'bar'}}