]>
git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/get_initial_configuration_cloud_instance.py
1 # -*- encoding: utf-8 -*-
6 # In case it's installed globally
12 # Credentials are stored in ~/.ovh.conf
16 projects_list
= client
.get('/cloud/project/')
17 if len(projects_list
) > 1:
18 print("More than one project is not supported, taking the first one")
19 project
= projects_list
[0]
20 instances_list
= client
.get('/cloud/project/{}/instance'.format(project
))
21 instances
= dict(map(lambda x
: (x
["id"], x
), instances_list
))
22 if sys
.argv
[-1] in instances
:
23 instance
= instances
[sys
.argv
[-1]]
25 print("Instance not in list:")
26 for instance
in instances_list
:
27 print("{}: {}".format(instance
["name"], instance
["id"]))
31 for ip_infos
in instance
["ipAddresses"]:
32 ip_infos
["ipAddress"] = ip_infos
.pop("ip")
33 ip_infos
["gateway"] = ip_infos
.pop("gatewayIp")
35 if ip_infos
["version"] == 4:
36 infos
["ips"]["v4"] = ip_infos
38 infos
["ips"]["v6"] = ip_infos
39 infos
["ips"]["v6"]["mask"] = 128
41 print(json
.dumps(infos
))