]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - python/reboot_ovh_cloud_instance.py
Merge install scripts
[perso/Immae/Projets/Puppet.git] / python / reboot_ovh_cloud_instance.py
similarity index 52%
rename from python/reboot_cloud_instance.py
rename to python/reboot_ovh_cloud_instance.py
index b90f488826c0243f9c233a2cf469dc822d069c1f..de20c07c1a905789f5c129ec797c0626de664efd 100644 (file)
@@ -6,24 +6,13 @@ except ImportError:
     # In case it's installed globally
     import ovh
 import sys
+from ovh_helper import find_cloud_instance
 
 # Credentials are stored in ~/.ovh.conf
 # See ovh/README.rst
 client = ovh.Client()
 
-projects_list = client.get('/cloud/project/')
-if len(projects_list) > 1:
-    print("More than one project is not supported, taking the first one")
-project = projects_list[0]
-instances_list = client.get('/cloud/project/{}/instance'.format(project))
-instances = dict(map(lambda x: (x["id"], x), instances_list))
-if sys.argv[-1] in instances:
-    instance = instances[sys.argv[-1]]
-else:
-    print("Instance not in list:")
-    for instance in instances_list:
-        print("{}: {}".format(instance["name"], instance["id"]))
-    sys.exit(1)
+project, instance = find_cloud_instance(client, sys.argv[-1])
 
 if "--rescue" in sys.argv:
     netboot_mode="rescue"