-
Notifications
You must be signed in to change notification settings - Fork 2
/
gns3_show_appliances_v1_1.py
44 lines (38 loc) · 1.57 KB
/
gns3_show_appliances_v1_1.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
#!/usr/bin/env python
import requests
from prettytable import PrettyTable
import argparse
def gns3_get_appliances_names_and_id(gns3_server):
gns3_appliances_dict = {}
show_appliances = requests.get(gns3_server + '/v2/templates')
if show_appliances:
show_appliances_dict = show_appliances.json()
for appliance in show_appliances_dict:
gns3_get_appliance_name = appliance['name']
gns3_get_appliance_id = appliance['template_id']
gns3_show_appliances = gns3_get_appliance_name, gns3_get_appliance_id
gns3_appliance_name = gns3_show_appliances[0]
gns3_appliance_id = gns3_show_appliances[1]
gns3_appliances_dict.update({gns3_appliance_name: gns3_appliance_id})
else:
print(show_appliances)
print('that is not working.')
exit()
return gns3_appliances_dict
def main():
gns3_appliances = gns3_get_appliances_names_and_id(gns3_server)
t_available_appliances = PrettyTable(['Appliance Name', 'ID'])
for key, value in gns3_appliances.items():
t_available_appliances.add_row([key, value])
print('#' * 100)
print('Current GNS3 server is', gns3_server)
print('Available appliances are:')
print('#' * 100)
print(t_available_appliances)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-s', action='store', dest='gns3_server', required=True,
help='GNS3 server, for example: http://172.16.1.1:3080')
args = parser.parse_args()
gns3_server = args.gns3_server
main()