-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_bulk.py
72 lines (45 loc) · 1.57 KB
/
delete_bulk.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
71
72
import requests
import json
from base64 import b64encode
def basic_auth(username, password):
token = b64encode(f"{username}:{password}".encode('utf-8')).decode("ascii")
return f'Basic {token}'
def getting_hosts(url="https://44.203.184.194/api/controller/v2/inventories/3/hosts/"):
username = "admin"
password = "Admin!Password!Gw"
print(basic_auth(username, password))
headers = {
"Content-Type": "application/json",
"Authorization": basic_auth(username, password)
}
response = requests.request("GET",
url=url, headers=headers, verify=False
)
return response.json()
def fetching_only_hosts(full_response, number_hosts):
first_number = full_response['results'][0]['id']
list_number = list()
for n in range(first_number, first_number + number_hosts):
list_number.append(n)
return list_number
def deleting_hosts(list_ids, url="https://44.203.184.194/api/controller/v2/bulk/host_delete/"):
username = "admin"
password = "Admin!Password!Gw"
print(basic_auth(username, password))
headers = {
"Content-Type": "application/json",
"Authorization": basic_auth(username, password)
}
payload = json.dumps(
{
"hosts": list_ids
}
)
response = requests.request("POST",
url=url, headers=headers, data=payload, verify=False
)
print(response.text)
return response
f_resp = getting_hosts()
id_hosts = fetching_only_hosts(f_resp, 3000)
deleting_hosts(id_hosts)