]>
Commit | Line | Data |
---|---|---|
248bd83e IB |
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 | |
69da835d | 9 | from ovh_helper import find_cloud_instance |
248bd83e IB |
10 | |
11 | infos = {} | |
12 | ||
13 | # Credentials are stored in ~/.ovh.conf | |
14 | # See ovh/README.rst | |
15 | client = ovh.Client() | |
16 | ||
69da835d | 17 | _, instance = find_cloud_instance(client, sys.argv[-1]) |
248bd83e IB |
18 | |
19 | infos["ips"] = {} | |
69da835d IB |
20 | for ip_infos in instance["ipAddresses"]: |
21 | ip_infos["ipAddress"] = ip_infos.pop("ip") | |
22 | ip_infos["gateway"] = ip_infos.pop("gatewayIp") | |
248bd83e | 23 | |
69da835d | 24 | if ip_infos["version"] == 4: |
248bd83e IB |
25 | infos["ips"]["v4"] = ip_infos |
26 | else: | |
27 | infos["ips"]["v6"] = ip_infos | |
28 | infos["ips"]["v6"]["mask"] = 128 | |
29 | ||
30 | print(json.dumps(infos)) |