]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame_incremental - python/get_initial_configuration.py
Add cron for cryptoportfolio bot
[perso/Immae/Projets/Puppet.git] / python / get_initial_configuration.py
... / ...
CommitLineData
1# -*- encoding: utf-8 -*-
2import json
3try:
4 from ovh import ovh
5except ImportError:
6 # In case it's installed globally
7 import ovh
8import sys
9
10infos = {}
11
12# Credentials are stored in ~/.ovh.conf
13# See ovh/README.rst
14client = ovh.Client()
15
16vps_list = client.get('/vps/')
17if sys.argv[-1] in vps_list:
18 vps = sys.argv[-1]
19else:
20 print("VPS not in list:")
21 for vps in vps_list:
22 print(vps)
23 sys.exit(1)
24
25ips = client.get('/vps/{}/ips'.format(vps))
26
27infos["ips"] = {}
28for 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
37print(json.dumps(infos))