1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# -*- encoding: utf-8 -*-
import json
from ovh import ovh
import sys
import ovh_helper
# Credentials are stored in ~/.ovh.conf
# See ovh/README.rst
client = ovh.Client()
vps_list = client.get('/vps/')
if sys.argv[-1] in vps_list:
vps = sys.argv[-1]
else:
print("VPS not in list:")
for vps in vps_list:
print(vps)
sys.exit(1)
current_distribution = client.get('/vps/{}/distribution'.format(vps))
available_templates = client.get('/vps/{}/templates'.format(vps))
def print_templates(client, vps, available_templates):
for tid in available_templates:
template = client.get('/vps/{}/templates/{}'.format(vps, tid))
print("{}: {}".format(template["id"], template["distribution"]))
if "--get-state" in sys.argv:
print(client.get('/vps/{}'.format(vps))["state"])
elif "--use-current" in sys.argv:
if current_distribution['id'] in available_templates:
print("Current template still available, using it")
result = client.post('/vps/{}/reinstall'.format(vps), templateId=current_distribution['id'])
print(result)
ovh_helper.show_progress(client, vps, "reinstallVm")
else:
print("Current template no more available. Chose among:")
print_templates(client, vps, available_templates)
elif sys.argv[-1] in available_templates:
print("Chosen template available, using it")
result = client.post('/vps/{}/reinstall'.format(vps), templateId=int(sys.argv[-1]))
print(result)
ovh_helper.show_progress(client, vps, "reinstallVm")
else:
print("Chosen template not available. Chose among:")
print_templates(client, vps, available_templates)
# Buy new:
# POST /order/cart
# ovhSubsidiary FR
# POST /order/cart/{cartId}/assign
# GET /vps/datacenter?country=FR
# Get list of vps:
# GET /order/cart/{cartId}/vps
# POST /order/cart/{cartId}/vps
# duration "P1M"
# planCode "vps_ssd_model1"
# pricingMode "default"
# quantity 1
# POST /order/cart/{cartId}/item/{item}/configuration
# label: "vps_ssd_datacenter"
# value: "gra"
# POST /order/cart/{cartId}/item/{item}/configuration
# label: "vps_ssd_os"
# value: "linux--archlinux--64--en"
# POST /order/cart/{cartId}/item/{item}/configuration
# label: "AUTO_RENEW_VPS"
# value: false
# GET /order/cart/{carId}/summary
# GET /order/cart/{cartId}/checkout
# POST /order/cart/{cartId}/checkout
# waiveRetractationPeriod
# /me/paymentMean ? /me/order/{orderId}/debt/pay ?
# Reboot in rescue:
# PUT /vps/{serviceName}
# netbootMode "rescue" / "local"
# changer son nom:
# displayName: "..."
|