-
Notifications
You must be signed in to change notification settings - Fork 0
/
nb-test.py
30 lines (22 loc) · 693 Bytes
/
nb-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3
import os
import pynetbox
from dotenv import load_dotenv
def connect_to_netbox(netbox_url=None, api_token=None):
if api_token is None and netbox_url is None:
load_dotenv()
netbox_url = os.environ['Netbox_URL']
api_token = os.environ['Netbox__APIToken']
return(pynetbox.api(url=netbox_url, token=api_token))
nb = connect_to_netbox()
device_name = 'dc2-mgmt02'
interface_name = 'Managment'
device_ip = "9.9.9.9/32"
ip = nb.ipam.ip_addresses.create(
address='192.0.2.1/32',
status='active',
description='Example IP',
assigned_object_type='dcim.interface',
assigned_object_id=123,
tags=['foo', 'bar']
)