diff options
Diffstat (limited to 'python/buy_ovh_vps_ssd.py')
-rw-r--r-- | python/buy_ovh_vps_ssd.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/python/buy_ovh_vps_ssd.py b/python/buy_ovh_vps_ssd.py new file mode 100644 index 0000000..44ae786 --- /dev/null +++ b/python/buy_ovh_vps_ssd.py | |||
@@ -0,0 +1,63 @@ | |||
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 | # Create a cart | ||
16 | cart = client.post('/order/cart', ovhSubsidiary="FR") | ||
17 | cart_id = cart["cartId"] | ||
18 | |||
19 | # Assign it to my user | ||
20 | client.post('/order/cart/{}/assign'.format(cart_id)) | ||
21 | |||
22 | # list of vps: | ||
23 | # client.get('/order/cart/{}/vps'.format(cart_id)) | ||
24 | item = client.post('/order/cart/{}/vps'.format(cart_id), | ||
25 | duration="P1M", | ||
26 | planCode="vps_ssd_model1", | ||
27 | pricingMode="default", | ||
28 | quantity=1) | ||
29 | item_id = item["itemId"] | ||
30 | |||
31 | # Datacenter, OS, auto-renew | ||
32 | client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), | ||
33 | label="vps_ssd_datacenter", | ||
34 | value="gra") | ||
35 | client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), | ||
36 | label="vps_ssd_os", | ||
37 | value="linux--archlinux--64--en") | ||
38 | client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), | ||
39 | label="AUTO_RENEW_VPS", | ||
40 | value=False) | ||
41 | |||
42 | #summary = client.get('/order/cart/{}/summary'.format(cart_id)) | ||
43 | #checkout = client.get('/order/cart/{}/checkout'.format(cart_id)) | ||
44 | |||
45 | # Checkout | ||
46 | order = client.post('/order/cart/{}/checkout'.format(cart_id), | ||
47 | waiveRetractationPeriod=True) | ||
48 | order_id = order["orderId"] | ||
49 | print(order_id) | ||
50 | |||
51 | payment_mean = client.get('/me/order/{}/availableRegisteredPaymentMean'.format(order_id))[0]['paymentMean'] | ||
52 | payment_mean_id = client.get('/me/paymentMean/{}'.format(payment_mean))[0] | ||
53 | |||
54 | payment_mean_status = client.get('/me/paymentMean/{}/{}'.format(payment_mean, payment_mean_id)) | ||
55 | |||
56 | if payment_mean_status["state"] != "valid": | ||
57 | raise "Bouh" | ||
58 | |||
59 | paid_order = client.post('/me/order/{}/payWithRegisteredPaymentMean'.format(order_id), | ||
60 | paymentMean=payment_mean, paymentMeanId=payment_mean_id) | ||
61 | |||
62 | if 'paymentDate' in paid_order: | ||
63 | print("successful") | ||