-
Notifications
You must be signed in to change notification settings - Fork 0
/
wapi-request.py
executable file
·70 lines (53 loc) · 1.58 KB
/
wapi-request.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
#!/usr/bin/env python3
import os
import sys
import json
import urllib3
import logging
import argparse
import requests
import coloredlogs
from netaddr import IPNetwork
from time import perf_counter, sleep
load_dotenv()
__author__ = 'ppiper'
ibx_grid_master = '192.168.40.58'
ibx_username = 'admin'
ibx_password = 'infoblox'
ibx_wapi_version = 'v2.11'
log_level = logging.DEBUG
log_format = '%(asctime)s %(levelname)s %(message)s'
logger = logging.getLogger()
coloredlogs.install(
level=log_level,
logger=logger,
fmt=log_format
)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def get_nets():
base_network = IPNetwork('10.0.0.0/8')
subnets = list(base_network.subnet(24, count=1024))
return subnets
def main():
url = f'https://{ibx_grid_master}/wapi/{ibx_wapi_version}'
with requests.session() as s:
grid = s.get(f'{url}/grid', auth=(ibx_username, ibx_password), verify=False)
logger.info(grid.json())
networks = get_nets()
t1_start = perf_counter()
# add networks using the requests object
network_requests = []
for network in networks:
network_object = dict(
method="POST",
object="network",
data=dict(network=str(network), comment='test-network')
)
network_requests.append(network_object)
s.post(f'{url}/request', data=json.dumps(network_requests), verify=False)
t1_stop = perf_counter()
logger.info('finished!')
logger.info(f'elapsed time for execution {t1_start - t1_stop}')
sys.exit()
if __name__ == '__main__':
main()