aboutsummaryrefslogblamecommitdiff
path: root/python/get_initial_configuration_ovh_cloud_instance.py
blob: 844373c3a519ae2ae3f206a1040e92543ea9e854 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                     
                                          






                                       
                                                       

                 


                                                     
 
                                





                                        
# -*- 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))