blob: 844373c3a519ae2ae3f206a1040e92543ea9e854 (
plain) (
blame)
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
|
# -*- encoding: utf-8 -*-
import json
try:
from ovh import ovh
except ImportError:
# In case it's installed globally
import ovh
import sys
from ovh_helper import find_cloud_instance
infos = {}
# Credentials are stored in ~/.ovh.conf
# See ovh/README.rst
client = ovh.Client()
_, instance = find_cloud_instance(client, sys.argv[-1])
infos["ips"] = {}
for ip_infos in instance["ipAddresses"]:
ip_infos["ipAddress"] = ip_infos.pop("ip")
ip_infos["gateway"] = ip_infos.pop("gatewayIp")
if ip_infos["version"] == 4:
infos["ips"]["v4"] = ip_infos
else:
infos["ips"]["v6"] = ip_infos
infos["ips"]["v6"]["mask"] = 128
print(json.dumps(infos))
|