Skip to content

Where to find examples of using API to update objects? #5850

Answered by DCAuto
lonelyadmin asked this question in Q&A
Discussion options

You must be logged in to vote

pynetbox is for sure the way to go for updating. It's quick and easy.

  1. Query the object you want to update
        nb_interface = nb.dcim.interfaces.get(
            name=interface,
            device_id=nb_device.id
        )
  1. Update fields you want to (I think there's an easier way to do this part but this works so I never looked)
            new_vlan_id = 10
           # add existing vlans and new vlan to a list
           for vlan in nb_interface.tagged_vlans:
                tagged_vlans.append(vlan.id)
           tagged_vlans.append(new_vlan_id)
            nb_interface.tagged_vlans = tagged_vlans
  1. Save the object
    nb_interface.save()

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ryanmerolle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants