]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - python/get_initial_configuration_ovh_cloud_instance.py
Merge install scripts
[perso/Immae/Projets/Puppet.git] / python / get_initial_configuration_ovh_cloud_instance.py
diff --git a/python/get_initial_configuration_ovh_cloud_instance.py b/python/get_initial_configuration_ovh_cloud_instance.py
new file mode 100644 (file)
index 0000000..844373c
--- /dev/null
@@ -0,0 +1,30 @@
+# -*- 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))