]>
Commit | Line | Data |
---|---|---|
1 | # -*- encoding: utf-8 -*- | |
2 | import json | |
3 | try: | |
4 | from ovh import ovh | |
5 | except ImportError: | |
6 | # In case it's installed globally | |
7 | import ovh | |
8 | import sys | |
9 | ||
10 | infos = {} | |
11 | ||
12 | # Credentials are stored in ~/.ovh.conf | |
13 | # See ovh/README.rst | |
14 | client = ovh.Client() | |
15 | ||
16 | vps_list = client.get('/vps/') | |
17 | if sys.argv[-1] in vps_list: | |
18 | vps = sys.argv[-1] | |
19 | else: | |
20 | print("VPS not in list:") | |
21 | for vps in vps_list: | |
22 | print(vps) | |
23 | sys.exit(1) | |
24 | ||
25 | ips = client.get('/vps/{}/ips'.format(vps)) | |
26 | ||
27 | infos["ips"] = {} | |
28 | for ip in ips: | |
29 | ip_infos = client.get('/vps/{}/ips/{}'.format(vps, ip)) | |
30 | ||
31 | if ip_infos["version"] == "v4": | |
32 | infos["ips"]["v4"] = ip_infos | |
33 | else: | |
34 | infos["ips"]["v6"] = ip_infos | |
35 | infos["ips"]["v6"]["mask"] = 128 | |
36 | ||
37 | print(json.dumps(infos)) |