Skip to content

Commit 7a3c644

Browse files
finishing up quote ordering stuff
1 parent 8ffe12f commit 7a3c644

File tree

11 files changed

+289
-68
lines changed

11 files changed

+289
-68
lines changed

SoftLayer/CLI/order/place.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
default='hourly',
3333
show_default=True,
3434
help="Billing rate")
35-
@click.option('--complex-type',
35+
@click.option('--complex-type',
3636
help=("The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'."))
3737
@click.option('--extras',
3838
help="JSON string denoting extra data that needs to be sent with the order")
@@ -57,7 +57,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
5757
5858
5959
Example::
60-
60+
6161
# Order an hourly VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk,
6262
# Ubuntu 16.04, and 1 Gbps public & private uplink in dal13
6363
slcli order place --billing hourly CLOUD_SERVER DALLAS13 \\

SoftLayer/CLI/order/place_quote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@click.option('--send-email',
2222
is_flag=True,
2323
help="The quote will be sent to the email address associated with your user.")
24-
@click.option('--complex-type',
24+
@click.option('--complex-type',
2525
help="The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'.")
2626
@click.option('--extras',
2727
help="JSON string denoting extra data that needs to be sent with the order")

SoftLayer/CLI/order/preset_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def cli(env, package_keyname, keyword):
2121
"""List package presets.
2222
23-
.. Note::
23+
.. Note::
2424
Presets are set CPU / RAM / Disk allotments. You still need to specify required items.
2525
Some packages do not have presets.
2626

SoftLayer/CLI/order/quote.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
"""View and Order a quote"""
22
# :license: MIT, see LICENSE for more details.
33
import click
4-
import json
54

65
from SoftLayer.CLI import environment
7-
from SoftLayer.CLI import exceptions
86
from SoftLayer.CLI import formatting
97
from SoftLayer.CLI import helpers
8+
from SoftLayer.managers import ImageManager as ImageManager
109
from SoftLayer.managers import ordering
11-
from SoftLayer.utils import lookup, clean_time
12-
13-
14-
15-
from pprint import pprint as pp
10+
from SoftLayer.managers import SshKeyManager as SshKeyManager
1611

1712

1813
def _parse_create_args(client, args):
@@ -38,27 +33,30 @@ def _parse_create_args(client, args):
3833

3934
if args.get('image'):
4035
if args.get('image').isdigit():
41-
image_mgr = SoftLayer.ImageManager(client)
36+
image_mgr = ImageManager(client)
4237
image_details = image_mgr.get_image(args.get('image'), mask="id,globalIdentifier")
43-
data['image_id'] = image_details['globalIdentifier']
38+
data['imageTemplateGlobalIdentifier'] = image_details['globalIdentifier']
4439
else:
45-
data['image_id'] = args['image']
40+
data['imageTemplateGlobalIdentifier'] = args['image']
4641

42+
userdata = None
4743
if args.get('userdata'):
48-
data['userdata'] = args['userdata']
44+
userdata = args['userdata']
4945
elif args.get('userfile'):
5046
with open(args['userfile'], 'r') as userfile:
51-
data['userdata'] = userfile.read()
47+
userdata = userfile.read()
48+
if userdata:
49+
for hardware in data['hardware']:
50+
hardware['userData'] = [{'value': userdata}]
5251

5352
# Get the SSH keys
5453
if args.get('key'):
5554
keys = []
5655
for key in args.get('key'):
57-
resolver = SoftLayer.SshKeyManager(client).resolve_ids
56+
resolver = SshKeyManager(client).resolve_ids
5857
key_id = helpers.resolve_id(resolver, key, 'SshKey')
5958
keys.append(key_id)
60-
data['ssh_keys'] = keys
61-
59+
data['sshKeys'] = keys
6260

6361
return data
6462

@@ -113,8 +111,5 @@ def cli(env, quote, **args):
113111
table.align['value'] = 'l'
114112
table.add_row(['id', result['orderId']])
115113
table.add_row(['created', result['orderDate']])
116-
table.add_row(['status', result ['placedOrder']['status']])
114+
table.add_row(['status', result['placedOrder']['status']])
117115
env.fout(table)
118-
119-
120-

SoftLayer/CLI/order/quote_detail.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import formatting
77
from SoftLayer.managers import ordering
8-
from SoftLayer.utils import lookup, clean_time
8+
from SoftLayer.utils import lookup
99

1010

1111
@click.command()
@@ -36,5 +36,3 @@ def cli(env, quote):
3636
])
3737

3838
env.fout(table)
39-
40-

SoftLayer/CLI/order/quote_list.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""List Quotes on an account."""
1+
"""List active quotes on an account."""
22
# :license: MIT, see LICENSE for more details.
33
import click
44

@@ -7,15 +7,11 @@
77
from SoftLayer.managers import ordering
88
from SoftLayer.utils import clean_time
99

10-
from pprint import pprint as pp
1110

1211
@click.command()
13-
# @click.argument('package_keyname')
14-
@click.option('--all', is_flag=True, default=False,
15-
help="Show ALL quotes, by default only saved and pending quotes are shown")
1612
@environment.pass_env
17-
def cli(env, all):
18-
"""List all quotes on an account"""
13+
def cli(env):
14+
"""List all active quotes on an account"""
1915
table = formatting.Table([
2016
'Id', 'Name', 'Created', 'Expiration', 'Status', 'Package Name', 'Package Id'
2117
])
@@ -26,7 +22,6 @@ def cli(env, all):
2622
manager = ordering.OrderingManager(env.client)
2723
items = manager.get_quotes()
2824

29-
3025
for item in items:
3126
package = item['order']['items'][0]['package']
3227
table.add_row([
@@ -39,5 +34,3 @@ def cli(env, all):
3934
package.get('id')
4035
])
4136
env.fout(table)
42-
43-

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,38 @@
489489
}]
490490

491491
getActiveQuotes = [{
492+
'accountId': 1234,
492493
'id': 1234,
493494
'name': 'TestQuote1234',
494495
'quoteKey': '1234test4321',
496+
'createDate': '2019-04-10T14:26:03-06:00',
497+
'modifyDate': '2019-04-10T14:26:03-06:00',
498+
'order': {
499+
'id': 37623333,
500+
'items': [
501+
{
502+
'categoryCode': 'guest_core',
503+
'description': '4 x 2.0 GHz or higher Cores',
504+
'id': 468394713,
505+
'itemId': 859,
506+
'itemPriceId': '1642',
507+
'oneTimeAfterTaxAmount': '0',
508+
'oneTimeFee': '0',
509+
'oneTimeFeeTaxRate': '0',
510+
'oneTimeTaxAmount': '0',
511+
'quantity': 1,
512+
'recurringAfterTaxAmount': '0',
513+
'recurringFee': '0',
514+
'recurringTaxAmount': '0',
515+
'setupAfterTaxAmount': '0',
516+
'setupFee': '0',
517+
'setupFeeDeferralMonths': None,
518+
'setupFeeTaxRate': '0',
519+
'setupTaxAmount': '0',
520+
'package': {'id': 46, 'keyName': 'CLOUD_SERVER'}
521+
},
522+
]
523+
}
495524
}]
496525

497526
getOrders = [{

SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,101 @@
33
'id': 1234,
44
'name': 'TestQuote1234',
55
'quoteKey': '1234test4321',
6+
'order': {
7+
'id': 37623333,
8+
'items': [
9+
{
10+
'categoryCode': 'guest_core',
11+
'description': '4 x 2.0 GHz or higher Cores',
12+
'id': 468394713,
13+
'itemId': 859,
14+
'itemPriceId': '1642',
15+
'oneTimeAfterTaxAmount': '0',
16+
'oneTimeFee': '0',
17+
'oneTimeFeeTaxRate': '0',
18+
'oneTimeTaxAmount': '0',
19+
'quantity': 1,
20+
'recurringAfterTaxAmount': '0',
21+
'recurringFee': '0',
22+
'recurringTaxAmount': '0',
23+
'setupAfterTaxAmount': '0',
24+
'setupFee': '0',
25+
'setupFeeDeferralMonths': None,
26+
'setupFeeTaxRate': '0',
27+
'setupTaxAmount': '0',
28+
'package': {'id': 46, 'keyName': 'CLOUD_SERVER'}
29+
},
30+
]
31+
}
632
}
733

834
getRecalculatedOrderContainer = {
9-
'orderContainers': [{
10-
'presetId': '',
35+
'presetId': '',
36+
'prices': [{
37+
'id': 1921
38+
}],
39+
'quantity': 1,
40+
'packageId': 50,
41+
'useHourlyPricing': '',
42+
43+
}
44+
45+
verifyOrder = {
46+
'orderId': 1234,
47+
'orderDate': '2013-08-01 15:23:45',
48+
'useHourlyPricing': False,
49+
'prices': [{
50+
'id': 1,
51+
'laborFee': '2',
52+
'oneTimeFee': '2',
53+
'oneTimeFeeTax': '.1',
54+
'quantity': 1,
55+
'recurringFee': '2',
56+
'recurringFeeTax': '.1',
57+
'hourlyRecurringFee': '2',
58+
'setupFee': '1',
59+
'item': {'id': 1, 'description': 'this is a thing', 'keyName': 'TheThing'},
60+
}]}
61+
62+
placeOrder = {
63+
'orderId': 1234,
64+
'orderDate': '2013-08-01 15:23:45',
65+
'orderDetails': {
1166
'prices': [{
12-
'id': 1921
67+
'id': 1,
68+
'laborFee': '2',
69+
'oneTimeFee': '2',
70+
'oneTimeFeeTax': '.1',
71+
'quantity': 1,
72+
'recurringFee': '2',
73+
'recurringFeeTax': '.1',
74+
'hourlyRecurringFee': '2',
75+
'setupFee': '1',
76+
'item': {'id': 1, 'description': 'this is a thing'},
1377
}],
14-
'quantity': 1,
15-
'packageId': 50,
16-
'useHourlyPricing': '',
17-
}],
78+
'virtualGuests': [{
79+
'id': 1234567,
80+
'globalIdentifier': '1a2b3c-1701',
81+
'fullyQualifiedDomainName': 'test.guest.com'
82+
}],
83+
},
84+
'placedOrder': {
85+
'id': 37985543,
86+
'orderQuoteId': 2639077,
87+
'orderTypeId': 4,
88+
'status': 'PENDING_AUTO_APPROVAL',
89+
'items': [
90+
{
91+
'categoryCode': 'guest_core',
92+
'description': '4 x 2.0 GHz or higher Cores',
93+
'id': 472527133,
94+
'itemId': 859,
95+
'itemPriceId': '1642',
96+
'laborFee': '0',
97+
'oneTimeFee': '0',
98+
'recurringFee': '0',
99+
'setupFee': '0',
100+
}
101+
]
102+
}
18103
}

SoftLayer/managers/ordering.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,20 @@ def get_order_container(self, quote_id):
161161
container = quote.getRecalculatedOrderContainer(id=quote_id)
162162
return container
163163

164-
def generate_order_template(self, quote_id, extra):
164+
def generate_order_template(self, quote_id, extra, quantity=1):
165165
"""Generate a complete order template.
166166
167167
:param int quote_id: ID of target quote
168168
:param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order
169+
:param int quantity: Number of items to order.
169170
"""
170171

172+
if not isinstance(extra, dict):
173+
raise ValueError("extra is not formatted properly")
174+
171175
container = self.get_order_container(quote_id)
172176

177+
container['quantity'] = quantity
173178
for key in extra.keys():
174179
container[key] = extra[key]
175180

@@ -214,7 +219,7 @@ def order_quote(self, quote_id, extra):
214219
"""
215220

216221
container = self.generate_order_template(quote_id, extra)
217-
return self.client.call('SoftLayer_Billing_Order_Quote','placeOrder', container, id=quote_id)
222+
return self.client.call('SoftLayer_Billing_Order_Quote', 'placeOrder', container, id=quote_id)
218223

219224
def get_package_by_key(self, package_keyname, mask=None):
220225
"""Get a single package with a given key.

0 commit comments

Comments
 (0)