diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-16 19:14:29 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-16 20:13:46 +0100 |
commit | 69da835d04e741f4e85da3c473ba86c8801931fd (patch) | |
tree | 0cfb28cfd468a5b681f2b5af2b935c81d2221950 /python/get_initial_configuration_ovh_vps_ssd.py | |
parent | c15f2234474ff8a8266e26856702b3c561050667 (diff) | |
download | Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.gz Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.zst Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.zip |
Merge install scripts
Diffstat (limited to 'python/get_initial_configuration_ovh_vps_ssd.py')
-rw-r--r-- | python/get_initial_configuration_ovh_vps_ssd.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/python/get_initial_configuration_ovh_vps_ssd.py b/python/get_initial_configuration_ovh_vps_ssd.py new file mode 100644 index 0000000..0c6f698 --- /dev/null +++ b/python/get_initial_configuration_ovh_vps_ssd.py | |||
@@ -0,0 +1,37 @@ | |||
1 | # -*- encoding: utf-8 -*- | ||
2 | import json | ||
3 | try: | ||
4 | from ovh import ovh | ||
5 | except ImportError: | ||
6 | # In case it's installed globally | ||
7 | import ovh | ||
8 | import sys | ||
9 | |||
10 | infos = {} | ||
11 | |||
12 | # Credentials are stored in ~/.ovh.conf | ||
13 | # See ovh/README.rst | ||
14 | client = ovh.Client() | ||
15 | |||
16 | vps_list = client.get('/vps/') | ||
17 | if sys.argv[-1] in vps_list: | ||
18 | vps = sys.argv[-1] | ||
19 | else: | ||
20 | print("VPS not in list:") | ||
21 | for vps in vps_list: | ||
22 | print(vps) | ||
23 | sys.exit(1) | ||
24 | |||
25 | ips = client.get('/vps/{}/ips'.format(vps)) | ||
26 | |||
27 | infos["ips"] = {} | ||
28 | for ip in ips: | ||
29 | ip_infos = client.get('/vps/{}/ips/{}'.format(vps, ip)) | ||
30 | |||
31 | if ip_infos["version"] == "v4": | ||
32 | infos["ips"]["v4"] = ip_infos | ||
33 | else: | ||
34 | infos["ips"]["v6"] = ip_infos | ||
35 | infos["ips"]["v6"]["mask"] = 128 | ||
36 | |||
37 | print(json.dumps(infos)) | ||