]>
git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/reinstall_ovh_cloud_instance.py
1 # -*- encoding: utf-8 -*-
6 # In case it's installed globally
9 from ovh_helper
import find_cloud_instance
11 # Credentials are stored in ~/.ovh.conf
15 project
, instance
= find_cloud_instance(client
, sys
.argv
[-1])
17 current_image
= instance
["imageId"]
18 available_images
= client
.get('/cloud/project/{}/image'.format(project
),
20 region
=instance
["region"])
21 available_images_ids
= list(map(lambda x
: x
["id"], available_images
))
23 def print_images(available_images
):
24 for image
in available_images
:
25 print("{}: {}".format(image
["name"], image
["id"]))
27 def reinstall(image_id
):
28 return client
.post('/cloud/project/{}/instance/{}/reinstall'.format(project
, instance
["id"]),
31 if "--get-state" in sys
.argv
:
32 print(instance
["status"])
33 elif "--use-current" in sys
.argv
:
34 if current_image
in available_images_ids
:
35 print("Current image still available, using it")
36 print(reinstall(current_image
))
38 print("Current image no more available. Chose among:")
39 print_images(available_images
)
40 elif sys
.argv
[-1] in available_templates
:
41 print("Chosen image available, using it")
42 print(reinstall(current_image
))
44 print("Chosen image not available. Chose among:")
45 print_images(available_images
)