aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-01 00:22:47 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-01 00:42:25 +0200
commitec1096d8c0d897ebd1ea445d9c5404a13c33ce2e (patch)
tree2f81f476207059287c991e19d390f89e4bb5c5ab /python
parent548061112d2e2627317f9379d2f501fcf3f6ea54 (diff)
downloadPuppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.tar.gz
Puppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.tar.zst
Puppet-ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e.zip
Add install scripts
Diffstat (limited to 'python')
m---------python/ovh0
-rw-r--r--python/ovh_helper.py19
-rw-r--r--python/reboot_vps_server.py36
-rw-r--r--python/reinstall_vps_server.py82
4 files changed, 137 insertions, 0 deletions
diff --git a/python/ovh b/python/ovh
new file mode 160000
Subproject 2a0cc19a96d8efc38ca8e1897c8fa38e459beb8
diff --git a/python/ovh_helper.py b/python/ovh_helper.py
new file mode 100644
index 0000000..a49a245
--- /dev/null
+++ b/python/ovh_helper.py
@@ -0,0 +1,19 @@
1import time
2
3def show_progress(client, vps, task_type):
4 running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0]
5
6 progress = 0
7 state = "todo"
8 print(" 0 %", end='')
9 while state != "done":
10 old_progress = progress
11 task = client.get("/vps/{}/tasks/{}".format(vps, running_task_id))
12 progress = task["progress"]
13 state = task["state"]
14
15 if progress != old_progress:
16 print("\r{:>3} %".format(progress), end="")
17 time.sleep(3)
18
19 print("\rFinished")
diff --git a/python/reboot_vps_server.py b/python/reboot_vps_server.py
new file mode 100644
index 0000000..7ea301a
--- /dev/null
+++ b/python/reboot_vps_server.py
@@ -0,0 +1,36 @@
1# -*- encoding: utf-8 -*-
2import json
3from ovh import ovh
4import sys
5import ovh_helper
6
7# Credentials are stored in ~/.ovh.conf
8# See ovh/README.rst
9client = ovh.Client()
10
11vps_list = client.get('/vps/')
12if sys.argv[-1] in vps_list:
13 vps = sys.argv[-1]
14else:
15 print("VPS not in list:")
16 for vps in vps_list:
17 print(vps)
18 sys.exit(1)
19
20if "--rescue" in sys.argv:
21 netboot_mode="rescue"
22elif "--local" in sys.argv:
23 netboot_mode="local"
24else:
25 netboot_mode=None
26
27current_state=client.get("/vps/{}".format(vps))["netbootMode"]
28
29if netboot_mode is None or current_state == netboot_mode:
30 client.post("/vps/{}/reboot".format(vps))
31 task_type="rebootVm"
32else:
33 client.put("/vps/{}".format(vps), netbootMode=netboot_mode)
34 task_type="setNetboot"
35
36ovh_helper.show_progress(client, vps, task_type)
diff --git a/python/reinstall_vps_server.py b/python/reinstall_vps_server.py
new file mode 100644
index 0000000..2eea203
--- /dev/null
+++ b/python/reinstall_vps_server.py
@@ -0,0 +1,82 @@
1# -*- encoding: utf-8 -*-
2import json
3from ovh import ovh
4import sys
5import ovh_helper
6
7# Credentials are stored in ~/.ovh.conf
8# See ovh/README.rst
9client = ovh.Client()
10
11vps_list = client.get('/vps/')
12if sys.argv[-1] in vps_list:
13 vps = sys.argv[-1]
14else:
15 print("VPS not in list:")
16 for vps in vps_list:
17 print(vps)
18 sys.exit(1)
19
20current_distribution = client.get('/vps/{}/distribution'.format(vps))
21
22available_templates = client.get('/vps/{}/templates'.format(vps))
23
24def print_templates(client, vps, available_templates):
25 for tid in available_templates:
26 template = client.get('/vps/{}/templates/{}'.format(vps, tid))
27 print("{}: {}".format(template["id"], template["distribution"]))
28
29
30if "--get-state" in sys.argv:
31 print(client.get('/vps/{}'.format(vps))["state"])
32elif "--use-current" in sys.argv:
33 if current_distribution['id'] in available_templates:
34 print("Current template still available, using it")
35 result = client.post('/vps/{}/reinstall'.format(vps), templateId=current_distribution['id'])
36 print(result)
37 ovh_helper.show_progress(client, vps, "reinstallVm")
38 else:
39 print("Current template no more available. Chose among:")
40 print_templates(client, vps, available_templates)
41elif sys.argv[-1] in available_templates:
42 print("Chosen template available, using it")
43 result = client.post('/vps/{}/reinstall'.format(vps), templateId=int(sys.argv[-1]))
44 print(result)
45 ovh_helper.show_progress(client, vps, "reinstallVm")
46else:
47 print("Chosen template not available. Chose among:")
48 print_templates(client, vps, available_templates)
49
50# Buy new:
51# POST /order/cart
52# ovhSubsidiary FR
53# POST /order/cart/{cartId}/assign
54# GET /vps/datacenter?country=FR
55# Get list of vps:
56# GET /order/cart/{cartId}/vps
57# POST /order/cart/{cartId}/vps
58# duration "P1M"
59# planCode "vps_ssd_model1"
60# pricingMode "default"
61# quantity 1
62# POST /order/cart/{cartId}/item/{item}/configuration
63# label: "vps_ssd_datacenter"
64# value: "gra"
65# POST /order/cart/{cartId}/item/{item}/configuration
66# label: "vps_ssd_os"
67# value: "linux--archlinux--64--en"
68# POST /order/cart/{cartId}/item/{item}/configuration
69# label: "AUTO_RENEW_VPS"
70# value: false
71# GET /order/cart/{carId}/summary
72# GET /order/cart/{cartId}/checkout
73# POST /order/cart/{cartId}/checkout
74# waiveRetractationPeriod
75
76# /me/paymentMean ? /me/order/{orderId}/debt/pay ?
77
78# Reboot in rescue:
79# PUT /vps/{serviceName}
80# netbootMode "rescue" / "local"
81# changer son nom:
82# displayName: "..."