1+ """Save an order as quote"""
2+ # :license: MIT, see LICENSE for more details.
3+
4+ import json
5+
6+ import click
7+
8+ from SoftLayer .CLI import environment
9+ from SoftLayer .CLI import exceptions
10+ from SoftLayer .CLI import formatting
11+ from SoftLayer .managers import ordering
12+
13+ COLUMNS = ['keyName' ,
14+ 'description' ,
15+ 'cost' , ]
16+
17+ @click .command ()
18+ @click .argument ('package_keyname' )
19+ @click .argument ('location' )
20+ @click .option ('--preset' ,
21+ help = "The order preset (if required by the package)" )
22+ @click .option ('--name' ,
23+ help = "Quote name (optional)" )
24+ @click .option ('--send-email' ,
25+ is_flag = True ,
26+ help = "Quote will be sent to the email address" )
27+ @click .option ('--complex-type' , help = ("The complex type of the order. This typically begins"
28+ " with 'SoftLayer_Container_Product_Order_'." ))
29+ @click .option ('--extras' ,
30+ help = "JSON string denoting extra data that needs to be sent with the order" )
31+ @click .argument ('order_items' , nargs = - 1 )
32+ @environment .pass_env
33+ def cli (env , package_keyname , location , preset , name , email , complex_type ,
34+ extras , order_items ):
35+ """Save an order as quote.
36+
37+ This CLI command is used for saving an order in quote of the specified package in
38+ the given location (denoted by a datacenter's long name). Orders made via the CLI
39+ can then be converted to be made programmatically by calling
40+ SoftLayer.OrderingManager.place_order() with the same keynames.
41+
42+ Packages for ordering can be retrieved from `slcli order package-list`
43+ Presets for ordering can be retrieved from `slcli order preset-list` (not all packages
44+ have presets)
45+
46+ Items can be retrieved from `slcli order item-list`. In order to find required
47+ items for the order, use `slcli order category-list`, and then provide the
48+ --category option for each category code in `slcli order item-list`.
49+
50+ \b
51+ Example:
52+ # Order an hourly VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk,
53+ # Ubuntu 16.04, and 1 Gbps public & private uplink in dal13
54+ slcli order quote --name " My quote name" --email CLOUD_SERVER DALLAS13 \\
55+ GUEST_CORES_4 \\
56+ RAM_16_GB \\
57+ REBOOT_REMOTE_CONSOLE \\
58+ 1_GBPS_PUBLIC_PRIVATE_NETWORK_UPLINKS \\
59+ BANDWIDTH_0_GB_2 \\
60+ 1_IP_ADDRESS \\
61+ GUEST_DISK_100_GB_SAN \\
62+ OS_UBUNTU_16_04_LTS_XENIAL_XERUS_MINIMAL_64_BIT_FOR_VSI \\
63+ MONITORING_HOST_PING \\
64+ NOTIFICATION_EMAIL_AND_TICKET \\
65+ AUTOMATED_NOTIFICATION \\
66+ UNLIMITED_SSL_VPN_USERS_1_PPTP_VPN_USER_PER_ACCOUNT \\
67+ NESSUS_VULNERABILITY_ASSESSMENT_REPORTING \\
68+ --extras '{"virtualGuests": [{"hostname": "test", "domain": "softlayer.com"}]}' \\
69+ --complex-type SoftLayer_Container_Product_Order_Virtual_Guest
70+
71+ """
72+ manager = ordering .OrderingManager (env .client )
73+
74+ if extras :
75+ extras = json .loads (extras )
76+
77+ args = (package_keyname , location , order_items )
78+ kwargs = {'preset_keyname' : preset ,
79+ 'extras' : extras ,
80+ 'quantity' : 1 ,
81+ 'quoteName' : name ,
82+ 'sendQuoteEmailFlag' : email ,
83+ 'complex_type' : complex_type }
84+
85+ order = manager .save_quote (* args , ** kwargs )
86+
87+ table = formatting .KeyValueTable (['name' , 'value' ])
88+ table .align ['name' ] = 'r'
89+ table .align ['value' ] = 'l'
90+ table .add_row (['id' , order ['orderId' ]])
91+ table .add_row (['created' , order ['orderDate' ]])
92+ table .add_row (['status' , order ['placedOrder' ]['status' ]])
93+ env .fout (table )
0 commit comments