]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/get_initial_configuration_ovh_cloud_instance.py
Merge branch 'dev'
[perso/Immae/Projets/Puppet.git] / python / get_initial_configuration_ovh_cloud_instance.py
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 from ovh_helper import find_cloud_instance
10
11 infos = {}
12
13 # Credentials are stored in ~/.ovh.conf
14 # See ovh/README.rst
15 client = ovh.Client()
16
17 _, instance = find_cloud_instance(client, sys.argv[-1])
18
19 infos["ips"] = {}
20 for ip_infos in instance["ipAddresses"]:
21 ip_infos["ipAddress"] = ip_infos.pop("ip")
22 ip_infos["gateway"] = ip_infos.pop("gatewayIp")
23
24 if ip_infos["version"] == 4:
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))