]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add buy server script
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 5 Oct 2017 22:24:55 +0000 (00:24 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 5 Oct 2017 22:24:55 +0000 (00:24 +0200)
python/buy_vps_server.py [new file with mode: 0644]
python/reinstall_vps_server.py

diff --git a/python/buy_vps_server.py b/python/buy_vps_server.py
new file mode 100644 (file)
index 0000000..2803e32
--- /dev/null
@@ -0,0 +1,54 @@
+# -*- encoding: utf-8 -*-
+import json
+try:
+    from ovh import ovh
+except ImportError:
+    # In case it's installed globally
+    import ovh
+import sys
+import ovh_helper
+
+# Credentials are stored in ~/.ovh.conf
+# See ovh/README.rst
+client = ovh.Client()
+
+# Create a cart
+cart = client.post('/order/cart', ovhSubsidiary="FR")
+cart_id = cart["cartId"]
+
+# Assign it to my user
+client.post('/order/cart/{}/assign'.format(cart_id))
+
+# list of vps:
+# client.get('/order/cart/{}/vps'.format(cart_id))
+item = client.post('/order/cart/{}/vps'.format(cart_id),
+        duration="P1M",
+        planCode="vps_ssd_model1",
+        pricingMode="default",
+        quantity=1)
+item_id = item["itemId"]
+
+# Datacenter, OS, auto-renew
+client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id),
+        label="vps_ssd_datacenter",
+        value="gra")
+client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id),
+        label="vps_ssd_os",
+        value="linux--archlinux--64--en")
+client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id),
+        label="AUTO_RENEW_VPS",
+        value=False)
+
+#summary  = client.get('/order/cart/{}/summary'.format(cart_id))
+#checkout = client.get('/order/cart/{}/checkout'.format(cart_id))
+
+# Checkout
+order = client.post('/order/cart/{}/checkout'.format(cart_id),
+        waiveRetractationPeriod=True)
+order_id = order["orderId"]
+print(order_id)
+
+# Suite à tester :
+# /me/order/{orderId}/availableRegisteredPaymentMean
+# /me/paymentMean ? /me/order/{orderId}/debt/pay ?
+
index 158ca232e6577f172270811dd8e39189c8fd8009..9f535cc10634132c68001974a524c5b6e6cc70cc 100644 (file)
@@ -51,35 +51,6 @@ 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
-# Suite à tester :
-# /me/order/{orderId}/availableRegisteredPaymentMean
-# /me/paymentMean ? /me/order/{orderId}/debt/pay ?
-
 # Reboot in rescue:
 # PUT /vps/{serviceName}
 #   netbootMode "rescue" / "local"