Skip to content

Assign IP to an Interface - Netbox #7870

Answered by candlerb
ISAYLG asked this question in Q&A
Discussion options

You must be logged in to vote

This is a generic relation, because an IP address can be assigned to either an Interface (on a Device) or a VMInterface. You need to set assigned_object_type and assigned_object_id

Here is some code which creates a virtual machine + interface + primary IPv4 + primary IPv6

#!/usr/bin/python3
import pynetbox
import sys

name=sys.argv[1]
domain=sys.argv[2]
ipv4=sys.argv[3]
ipv6=sys.argv[4]
CLUSTER = "mycluster"
domain_name = None
if domain:
    domain_name="%s.%s" % (name,domain)

nb = pynetbox.api('https://netbox.example.com',
        token='XXXXXXXX',
    )
vm = nb.virtualization.virtual_machines.create(dict(
        name=name,
        cluster={"name": CLUSTER},
    ))
intf = nb.virtualiza…

Replies: 1 comment

Comment options

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