1+ """Create a Reserved Capacity instance"""
2+ # :license: MIT, see LICENSE for more details.
3+
4+ import click
5+
6+ import SoftLayer
7+ from SoftLayer .CLI import environment
8+ from SoftLayer .CLI import formatting
9+ from SoftLayer .managers .vs_capacity import CapacityManager as CapacityManager
10+
11+
12+ from pprint import pprint as pp
13+
14+ @click .command (epilog = "See 'slcli vs capacity create-options' for valid options" )
15+ @click .option ('--name' , '-n' , required = True , prompt = True ,
16+ help = "Name for your new reserved capacity" )
17+ @click .option ('--datacenter' , '-d' , required = True , prompt = True ,
18+ help = "Datacenter shortname" )
19+ @click .option ('--backend_router_id' , '-b' , required = True , prompt = True ,
20+ help = "backendRouterId, create-options has a list of valid ids to use." )
21+ @click .option ('--capacity' , '-c' , required = True , prompt = True ,
22+ help = "Capacity keyname (C1_2X2_1_YEAR_TERM for example)." )
23+ @click .option ('--quantity' , '-q' , required = True , prompt = True ,
24+ help = "Number of VSI instances this capacity reservation can support." )
25+ @click .option ('--test' , is_flag = True ,
26+ help = "Do not actually create the virtual server" )
27+ @environment .pass_env
28+ def cli (env , name , datacenter , backend_router_id , capacity , quantity , test = False ):
29+ """Create a Reserved Capacity instance"""
30+ manager = CapacityManager (env .client )
31+ result = manager .create (
32+ name = name ,
33+ datacenter = datacenter ,
34+ backend_router_id = backend_router_id ,
35+ capacity = capacity ,
36+ quantity = quantity ,
37+ test = test )
38+
39+ pp (result )
40+ if test :
41+ table = formating .Table (['Name' , 'Value' ], "Test Order" )
42+ container = result ['orderContainers' ][0 ]
43+ table .add_row (['Name' , container ['name' ]])
44+ table .add_row (['Location' ], container ['locationObject' ]['longName' ])
45+ for price in container ['prices' ]:
46+ table .add_row ([price ['item' ]['keyName' ], price ['item' ]['description' ]])
47+ table .add_row (['Total' , result ['postTaxRecurring' ]])
48+ else :
49+ table = formatting .Table (['Name' , 'Value' ], "Reciept" )
50+ table .add_row (['Order Date' , result ['orderDate' ]])
51+ table .add_row (['Order ID' , result ['orderId' ]])
52+ table .add_row (['status' , result ['placedOrder' ]['status' ]])
53+ for item in result ['placedOrder' ]['items' ]:
54+ table .add_row ([item ['categoryCode' ], item ['description' ]])
55+ table .add_row (['Total' , result ['orderDetails' ]['postTaxRecurring' ]])
56+ env .fout (table )
57+
58+
59+ """
60+ Calling: SoftLayer_Product_Order::placeOrder(
61+ id=None,
62+ mask='',
63+ filter='None',
64+ args=(
65+ {'orderContainers': [
66+ {'backendRouterId': 1079095,
67+ 'name': 'cgallo-test-capacity',
68+ 'quantity': 1,
69+ 'packageId': 1059,
70+ 'location': 1854895,
71+ 'useHourlyPricing': True,
72+ 'complexType': 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity',
73+ 'prices': [{'id': 217633}]}]},), limit=None, offset=None))
74+ Resetting dropped connection: r237377.application.qadal0501.softlayer.local
75+ """
0 commit comments