]>
git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/reboot_cloud_instance.py
1 # -*- encoding: utf-8 -*-
6 # In case it's installed globally
10 # Credentials are stored in ~/.ovh.conf
14 projects_list
= client
.get('/cloud/project/')
15 if len(projects_list
) > 1:
16 print("More than one project is not supported, taking the first one")
17 project
= projects_list
[0]
18 instances_list
= client
.get('/cloud/project/{}/instance'.format(project
))
19 instances
= dict(map(lambda x
: (x
["id"], x
), instances_list
))
20 if sys
.argv
[-1] in instances
:
21 instance
= instances
[sys
.argv
[-1]]
23 print("Instance not in list:")
24 for instance
in instances_list
:
25 print("{}: {}".format(instance
["name"], instance
["id"]))
28 if "--rescue" in sys
.argv
:
30 elif "--local" in sys
.argv
:
35 if netboot_mode
is not None:
36 result
= client
.post("/cloud/project/{}/instance/{}/rescueMode".format(project
,
37 instance
["id"]), imageId
=instance
["imageId"], rescue
=(netboot_mode
== "rescue"))