Skip to content

Netbox Library

svc_netbox_lib.netbox

netbox_delete_interface(token, id)

Delete an interface from NetBox.

Parameters

token : str NetBox API token for authentication. id : int NetBox interface id to delete.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
def netbox_delete_interface(token, id):
    """Delete an interface from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    id : int
        NetBox interface id to delete.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.delete('http://netbox.solutionvalidation.center/api/dcim/interfaces/'+ str(id)+ '/', headers=myheaders)
    return data.status_code

netbox_delete_ip_address(token, ip_id)

Delete an IP address from NetBox.

Parameters

token : str NetBox API token for authentication. ip_id : int NetBox IP address object id to delete.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def netbox_delete_ip_address(token, ip_id):
    """Delete an IP address from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    ip_id : int
        NetBox IP address object id to delete.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.delete('http://netbox.solutionvalidation.center/api/ipam/ip-addresses/'+ str(ip_id)+ '/', headers=myheaders)
    return data.status_code

netbox_delete_vlan(token, id)

Delete a VLAN object from NetBox.

Parameters

token : str NetBox API token for authentication. id : int NetBox VLAN object id to delete.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def netbox_delete_vlan(token, id):
    """Delete a VLAN object from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    id : int
        NetBox VLAN object id to delete.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization' : 'Token '+ token, 'Content-Type': 'application/json'}
    data = requests.delete('http://netbox.solutionvalidation.center/api/ipam/vlans/'+ str(id)+ '/', headers=myheaders)
    return data.status_code

netbox_delete_vrf(token, vrf_id)

Delete a VRF from NetBox.

Parameters

token : str NetBox API token for authentication. vrf_id : int NetBox VRF object id to delete.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
def netbox_delete_vrf(token, vrf_id):
    """Delete a VRF from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    vrf_id : int
        NetBox VRF object id to delete.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.delete('http://netbox.solutionvalidation.center/api/ipam/vrfs/'+ str(vrf_id)+ '/', headers=myheaders)
    return data.status_code

netbox_get_device_platform(token, device_id)

Get the current platform name and upgrade flag for a device in NetBox.

Parameters

token : str NetBox API token for authentication. device_id : int NetBox device id.

Returns

tuple[str, Any] (platform_name, upgrade_flag) where platform_name is the platform name string or 'none' and upgrade_flag is the device's custom_fields['upgrade'] value or None.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
def netbox_get_device_platform(token, device_id):
    """Get the current platform name and upgrade flag for a device in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    device_id : int
        NetBox device id.

    Returns
    -------
    tuple[str, Any]
        (platform_name, upgrade_flag) where platform_name is the platform name string or 'none'
        and upgrade_flag is the device's custom_fields['upgrade'] value or None.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.get('http://netbox.solutionvalidation.center/api/dcim/devices/'+ str(device_id)+'/', headers=myheaders)
    data = data.json()
    if data['platform'] is not None:
        platform = data['platform']['name']
        upgrade = data['custom_fields']['upgrade']
    else:
        platform = 'none'
        upgrade = None
    return platform, upgrade

netbox_get_fqdn(token, site, device)

Query NetBox for a device and return its FQDN/name.

Parameters

token : str NetBox API token for authentication. site : str Site identifier to filter devices by. device : str Search string for the device (e.g. 'br1', 'csw1').

Returns

str Device FQDN/name if found, otherwise the string 'none'.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def netbox_get_fqdn(token, site, device):
    """Query NetBox for a device and return its FQDN/name.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    site : str
        Site identifier to filter devices by.
    device : str
        Search string for the device (e.g. 'br1', 'csw1').

    Returns
    -------
    str
        Device FQDN/name if found, otherwise the string 'none'.
    """
    myheaders = {'Authorization': 'Token ' + token}
    parameters = {'site': site, 'q': device}
    data = requests.get('http://netbox.solutionvalidation.center/api/dcim/devices/', headers=myheaders, params=parameters)
    data = data.json()
    try:
        fqdn = data['results'][0]['name']
    except:
        fqdn = 'none'
    return fqdn

netbox_get_id(token, location, device)

Return the NetBox device id for a device matching location and name.

Parameters

token : str NetBox API token for authentication. location : str Site/location code to filter devices by. device : str Search string for the device.

Returns

int NetBox device id (raises if no results are found).

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def netbox_get_id(token, location, device):
    """Return the NetBox device id for a device matching location and name.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    location : str
        Site/location code to filter devices by.
    device : str
        Search string for the device.

    Returns
    -------
    int
        NetBox device id (raises if no results are found).
    """
    myheaders = {'Authorization': 'Token ' + token}
    parameters = {'q': device, 'site': location, 'tenant' : 'svc'}
    data = requests.get('http://netbox.solutionvalidation.center/api/dcim/devices/', headers=myheaders, params=parameters)
    data = data.json()
    results = data['results'][0]['id']
    return results

netbox_get_interfaces(token, id)

Fetch interfaces for a NetBox device and return a structured mapping.

Parameters

token : str NetBox API token for authentication. id : int NetBox device id to list interfaces for.

Returns

dict[str, dict] Mapping of interface name -> dict containing: - 'id' (int): NetBox interface id - 'description' (str) - 'type' (str): one of 'SMF', 'MMF', 'copper', 'lag', 'No SFP', etc. - 'speed' (str): human-readable speed tag

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def netbox_get_interfaces(token, id):
    """Fetch interfaces for a NetBox device and return a structured mapping.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    id : int
        NetBox device id to list interfaces for.

    Returns
    -------
    dict[str, dict]
        Mapping of interface name -> dict containing:
        - 'id' (int): NetBox interface id
        - 'description' (str)
        - 'type' (str): one of 'SMF', 'MMF', 'copper', 'lag', 'No SFP', etc.
        - 'speed' (str): human-readable speed tag
    """
    myheaders = {'Authorization' : 'Token '+ token}
    parameters = {'q' : '', 'device_id' : id, 'limit' : 100000}
    data = requests.get('http://netbox.solutionvalidation.center/api/dcim/interfaces/', headers=myheaders, params=parameters)
    data = data.json()
    results = {}
    for i in range(len(data['results'])):
        if 'vcp' not in data['results'][i]['name'] and 'member' not in data['results'][i]['name'] and 'vlan' not in data['results'][i]['name']:
            results.update({data['results'][i]['name']:{'id':data['results'][i]['id'],'description':data['results'][i]['description'], 'type':'', 'speed':''}})
        for x in data['results'][i]['tags']:
            if x == 'SMF':
                results[data['results'][i]['name']]['type']='SMF'
            elif x == 'MMF':
                results[data['results'][i]['name']]['type'] = 'MMF'
            elif x == 'copper':
                results[data['results'][i]['name']]['type'] = 'copper'
            elif x == 'lag':
                results[data['results'][i]['name']]['type'] = 'lag'
            elif x == 'No SFP':
                results[data['results'][i]['name']]['type'] = 'No SFP'
            elif x == '100mbps':
                results[data['results'][i]['name']]['speed'] = '100mbps'
            elif x == '100 Mbps':
                results[data['results'][i]['name']]['speed'] = '100 Mbps'
            elif x == '1Gbps':
                results[data['results'][i]['name']]['speed'] = '1Gbps'
            elif x == '10Gbps':
                results[data['results'][i]['name']]['speed'] = '10Gbps'
            elif x == '20Gbps':
                results[data['results'][i]['name']]['speed'] = '20Gbps'
            elif x == '30Gbps':
                results[data['results'][i]['name']]['speed'] = '30Gbps'
            elif x == '40Gbps':
                results[data['results'][i]['name']]['speed'] = '40Gbps'
            elif x == 'Unspecified':
                results[data['results'][i]['name']]['speed'] = 'Unspecified'
            elif x == 'None':
                results[data['results'][i]['name']]['speed'] = 'None'
    return results

netbox_get_ipv4_public_prefix(token, site)

Return the IPv4 public prefix role entry for a given site.

Parameters

token : str NetBox API token for authentication. site : str Site identifier (used to construct the role filter: '-ipv4-public-ip-space').

Returns

str The prefix string (e.g. '64.191.201.0/24'), or an empty string if none found.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
def netbox_get_ipv4_public_prefix(token, site):
    """Return the IPv4 public prefix role entry for a given site.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    site : str
        Site identifier (used to construct the role filter: '<site>-ipv4-public-ip-space').

    Returns
    -------
    str
        The prefix string (e.g. '64.191.201.0/24'), or an empty string if none found.
    """
    myheaders = {'Authorization' : 'Token '+ token}
    parameters = {'q' : '', 'role': site+'-ipv4-public-ip-space'}
    data = requests.get('http://netbox.solutionvalidation.center/api/ipam/prefixes/', headers=myheaders, params=parameters)
    data = data.json()
    results = ''
    for i in range(len(data['results'])):
        results = data['results'][i]['prefix']
    return results

netbox_get_ipv4_public_routes(token, site)

Return IPv4 public addresses (children of the site's public prefix) from NetBox.

Parameters

token : str NetBox API token for authentication. site : str Site identifier to locate the parent public prefix.

Returns

dict[str, dict] Mapping of address (CIDR string) -> dict with keys 'id' and 'description'.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def netbox_get_ipv4_public_routes(token, site):
    """Return IPv4 public addresses (children of the site's public prefix) from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    site : str
        Site identifier to locate the parent public prefix.

    Returns
    -------
    dict[str, dict]
        Mapping of address (CIDR string) -> dict with keys 'id' and 'description'.
    """
    myheaders = {'Authorization' : 'Token '+ token}
    parent_prefix = netbox_get_ipv4_public_prefix(token, site)
    if parent_prefix == '':
        parent_prefix = '1.1.1.0/30'
    parameters = {'q' : '', 'parent': parent_prefix, 'limit' : 100000}
    data = requests.get('http://netbox.solutionvalidation.center/api/ipam/ip-addresses/', headers=myheaders, params=parameters)
    data = data.json()
    results={}
    for i in range(len(data['results'])):
        results.update({data['results'][i]['address']:{'id':data['results'][i]['id'], 'description': data['results'][i]['description']}})
    return results

netbox_get_platforms(token)

Return a list of platform names (software versions) from NetBox.

Parameters

token : str NetBox API token for authentication.

Returns

list[str] List of platform names as strings.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
def netbox_get_platforms(token):
    """Return a list of platform names (software versions) from NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.

    Returns
    -------
    list[str]
        List of platform names as strings.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.get('http://netbox.solutionvalidation.center/api/dcim/platforms/', headers=myheaders)
    data = data.json()
    results = []
    for i in range(len(data['results'])):
        results.append(data['results'][i]['name'])
    return results

netbox_get_sites()

Return the list of supported SVC site identifiers.

Returns

list[str] A list of site codes (e.g. 'ld5', 'da6', 'ny5', ...).

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def netbox_get_sites():
    """Return the list of supported SVC site identifiers.

    Returns
    -------
    list[str]
        A list of site codes (e.g. 'ld5', 'da6', 'ny5', ...).
    """
    svc_locations = ['ld5', 'dx1', 'da6', 'dc6', 'la3', 'mi1', 'ny5', 'se3', 'sv5', 'am3', 'ch3', 'fr4', 'at1', 'hk2',
                     'os1', 'sg2', 'sy4', 'ty4', 'tr2']
    return svc_locations

netbox_get_vlan_dictionary(token, site, device)

Return a mapping of VLAN tag to NetBox VLAN ID for a site and device filter.

Parameters

token : str NetBox API token for authentication. site : str Site identifier to filter VLANs by. device : str Search/filter term for VLANs (passed as 'q' to the API).

Returns

dict[int, int] or dict Mapping of VLAN VID (int) -> NetBox VLAN object id (int). If the request fails or no data is present, returns {'none': 'none'}.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def netbox_get_vlan_dictionary(token, site, device):
    """Return a mapping of VLAN tag to NetBox VLAN ID for a site and device filter.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    site : str
        Site identifier to filter VLANs by.
    device : str
        Search/filter term for VLANs (passed as 'q' to the API).

    Returns
    -------
    dict[int, int] or dict
        Mapping of VLAN VID (int) -> NetBox VLAN object id (int). If the request fails or no data is present,
        returns {'none': 'none'}.
    """
    myheaders = {'Authorization' : 'Token '+ token}
    parameters = {'q' : device, 'site': site, 'limit' : 100000}
    data = requests.get('http://netbox.solutionvalidation.center/api/ipam/vlans/', headers=myheaders, params=parameters)
    data = data.json()
    results = {}
    try:
        for i in range(len(data['results'])):
            results.update({data['results'][i]['vid'] : data['results'][i]['id']})
    except:
        results = {'none': 'none'}
    return results

netbox_get_vrfs(token, site)

Return VRFs for a given site from NetBox with selected metadata.

Parameters

token : str NetBox API token for authentication. site : str Site identifier to filter VRFs by (custom field 'Site').

Returns

dict[str, dict] Mapping of VRF name -> dict with keys: - 'id' : NetBox VRF id - 'instance_type' : custom field 'type' - 'route_distinguisher' : rd (string) - 'instance_interface' : tags list - 'site' : custom field 'Site'

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
def netbox_get_vrfs(token, site):
    """Return VRFs for a given site from NetBox with selected metadata.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    site : str
        Site identifier to filter VRFs by (custom field 'Site').

    Returns
    -------
    dict[str, dict]
        Mapping of VRF name -> dict with keys:
        - 'id' : NetBox VRF id
        - 'instance_type' : custom field 'type'
        - 'route_distinguisher' : rd (string)
        - 'instance_interface' : tags list
        - 'site' : custom field 'Site'
    """
    myheaders = {'Authorization' : 'Token '+ token, 'Content-Type': 'application/json'}
    parameters = {'q':'', 'cf_Site':site, 'limit' : 100000}
    data = requests.get('http://netbox.solutionvalidation.center/api/ipam/vrfs/',headers=myheaders, params=parameters)
    data = data.json()
    results={}
    for i in range(len(data['results'])):
        results.update({data['results'][i]['name']:{'id':data['results'][i]['id'],'instance_type':data['results'][i]['custom_fields']['type'],
                                                    'route_distinguisher':data['results'][i]['rd'],'instance_interface':data['results'][i]['tags'],
                                                    'site':data['results'][i]['custom_fields']['Site']}})
    return results

netbox_patch_device_platform(token, device_id, payload)

Patch/update the platform (software version) of a device in NetBox.

Parameters

token : str NetBox API token for authentication. device_id : int NetBox device id. payload : dict JSON payload with platform update fields.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
def netbox_patch_device_platform(token, device_id, payload):
    """Patch/update the platform (software version) of a device in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    device_id : int
        NetBox device id.
    payload : dict
        JSON payload with platform update fields.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.patch('http://netbox.solutionvalidation.center/api/dcim/devices/'+ str(device_id)+'/', headers=myheaders, json=payload)
    return data.status_code

netbox_patch_interface(token, interface_id, payload)

Patch/update an interface object in NetBox.

Parameters

token : str NetBox API token for authentication. interface_id : int NetBox interface id to update. payload : dict JSON payload with fields to update.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def netbox_patch_interface(token, interface_id, payload):
    """Patch/update an interface object in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    interface_id : int
        NetBox interface id to update.
    payload : dict
        JSON payload with fields to update.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.patch('http://netbox.solutionvalidation.center/api/dcim/interfaces/'+ str(interface_id)+'/', headers=myheaders, json=payload)
    return data.status_code

netbox_patch_ip_address(token, ip_id, payload)

Patch/update an IP address object in NetBox.

Parameters

token : str NetBox API token for authentication. ip_id : int NetBox IP address object id to update. payload : dict JSON payload with fields to update (e.g. {'description': '...'}).

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
def netbox_patch_ip_address(token, ip_id, payload):
    """Patch/update an IP address object in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    ip_id : int
        NetBox IP address object id to update.
    payload : dict
        JSON payload with fields to update (e.g. {'description': '...'}).

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.patch('http://netbox.solutionvalidation.center/api/ipam/ip-addresses/'+ str(ip_id)+'/', headers=myheaders, json=payload)
    return data.status_code

netbox_patch_vrf(token, vrf_id, payload)

Patch/update a VRF object in NetBox.

Parameters

token : str NetBox API token for authentication. vrf_id : int NetBox VRF object id to update. payload : dict JSON payload with fields to update.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
def netbox_patch_vrf(token, vrf_id, payload):
    """Patch/update a VRF object in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    vrf_id : int
        NetBox VRF object id to update.
    payload : dict
        JSON payload with fields to update.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.patch('http://netbox.solutionvalidation.center/api/ipam/vrfs/'+ str(vrf_id)+'/', headers=myheaders, json=payload)
    return data.status_code

netbox_post_interface(token, payload)

Create one or more interfaces in NetBox.

Parameters

token : str NetBox API token for authentication. payload : dict JSON payload for interface creation per NetBox API.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def netbox_post_interface(token, payload):
    """Create one or more interfaces in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    payload : dict
        JSON payload for interface creation per NetBox API.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.post('http://netbox.solutionvalidation.center/api/dcim/interfaces/', headers=myheaders, json=payload)
    return data.status_code

netbox_post_ip_address(token, payload)

Create a new IP address in NetBox.

Parameters

token : str NetBox API token for authentication. payload : dict JSON payload for IP creation (e.g. {'address': 'x.x.x.x/yy', 'description': '...', 'vrf': {...}}).

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def netbox_post_ip_address(token, payload):
    """Create a new IP address in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    payload : dict
        JSON payload for IP creation (e.g. {'address': 'x.x.x.x/yy', 'description': '...', 'vrf': {...}}).

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.post('http://netbox.solutionvalidation.center/api/ipam/ip-addresses/', headers=myheaders, json=payload)
    return data.status_code

netbox_post_platform(token, payload)

Create a new platform (software version) in NetBox.

Parameters

token : str NetBox API token for authentication. payload : dict JSON payload for platform creation (e.g. {'name': ..., 'slug': ...}).

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
def netbox_post_platform(token, payload):
    """Create a new platform (software version) in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    payload : dict
        JSON payload for platform creation (e.g. {'name': ..., 'slug': ...}).

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.post('http://netbox.solutionvalidation.center/api/dcim/platforms/', headers=myheaders, json=payload)
    return data.status_code

netbox_post_vlan(token, payload)

Create a VLAN in NetBox.

Parameters

token : str NetBox API token for authentication. payload : dict JSON payload for VLAN creation following NetBox API schema.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def netbox_post_vlan(token, payload):
    """Create a VLAN in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    payload : dict
        JSON payload for VLAN creation following NetBox API schema.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization' : 'Token '+ token, 'Content-Type': 'application/json'}
    data = requests.post('http://netbox.solutionvalidation.center/api/ipam/vlans/', headers=myheaders, json=payload)
    return data.status_code

netbox_post_vrf(token, payload)

Create a new VRF in NetBox.

Parameters

token : str NetBox API token for authentication. payload : dict JSON payload for VRF creation per NetBox API.

Returns

int HTTP status code returned by the NetBox API.

Source code in packages/svc_netbox_lib/src/svc_netbox_lib/netbox.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
def netbox_post_vrf(token, payload):
    """Create a new VRF in NetBox.

    Parameters
    ----------
    token : str
        NetBox API token for authentication.
    payload : dict
        JSON payload for VRF creation per NetBox API.

    Returns
    -------
    int
        HTTP status code returned by the NetBox API.
    """
    myheaders = {'Authorization': 'Token ' + token, 'Content-Type': 'application/json'}
    data = requests.post('http://netbox.solutionvalidation.center/api/ipam/vrfs/', headers=myheaders, json=payload)
    return data.status_code