]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame_incremental - python/get_initial_configuration_ovh_cloud_instance.py
Add wrapper to caldance app
[perso/Immae/Projets/Puppet.git] / python / get_initial_configuration_ovh_cloud_instance.py
... / ...
CommitLineData
1# -*- encoding: utf-8 -*-
2import json
3try:
4 from ovh import ovh
5except ImportError:
6 # In case it's installed globally
7 import ovh
8import sys
9from ovh_helper import find_cloud_instance
10
11infos = {}
12
13# Credentials are stored in ~/.ovh.conf
14# See ovh/README.rst
15client = ovh.Client()
16
17_, instance = find_cloud_instance(client, sys.argv[-1])
18
19infos["ips"] = {}
20for 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
30print(json.dumps(infos))