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