Skip to content

Commit 218399b

Browse files
Merge pull request softlayer#123 from beittenc/add_dedicated_server_ordering
Add dedicated server ordering
2 parents d57c728 + 54e441d commit 218399b

5 files changed

Lines changed: 771 additions & 197 deletions

File tree

SoftLayer/API.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def authenticate_with_password(self, username, password,
141141
security_question_id,
142142
security_question_answer)
143143
self.auth = TokenAuthentication(res['userId'], res['hash'])
144+
return (res['userId'], res['hash'])
144145

145146
def add_raw_header(self, name, value):
146147
""" Set HTTP headers for API calls.

SoftLayer/CLI/modules/bmetal.py

Lines changed: 33 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BMetalCreateOptions(CLIRunnable):
3838
"""
3939
usage: sl bmetal create-options [options]
4040
41-
Output available available options when creating a server
41+
Output available available options when creating a bare metal instance.
4242
4343
Options:
4444
--all Show all options. default if no other option provided
@@ -48,10 +48,9 @@ class BMetalCreateOptions(CLIRunnable):
4848
--disk Show disk options
4949
--os Show operating system options
5050
--memory Show memory size options
51-
--bandwidth Show bandwidth options
5251
"""
5352
action = 'create-options'
54-
options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic', 'bandwidth']
53+
options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic']
5554

5655
@classmethod
5756
def execute(cls, client, args):
@@ -96,23 +95,14 @@ def execute(cls, client, args):
9695
results = cls.get_create_options(bmi_options, 'disk')[0]
9796

9897
t.add_row([results[0], listing(
99-
item[0] for item in sorted(results[1],
100-
key=lambda x: int(x[0])))])
98+
item[0] for item in sorted(results[1]))])
10199

102100
if args['--nic'] or show_all:
103101
results = cls.get_create_options(bmi_options, 'nic')
104102

105103
for result in results:
106104
t.add_row([result[0], listing(
107-
item[0] for item in sorted(result[1],
108-
key=lambda x: x[0]))])
109-
110-
if args['--bandwidth'] or show_all:
111-
results = cls.get_create_options(bmi_options, 'bandwidth')[0]
112-
113-
t.add_row([results[0], listing(
114-
item[0] for item in sorted(results[1],
115-
key=lambda x: x[0]))])
105+
item[0] for item in sorted(result[1],))])
116106

117107
return t
118108

@@ -256,35 +246,28 @@ def _generate_windows_code(description):
256246
elif 'disk' == section:
257247
disks = []
258248
for disk in bmi_options['categories']['disk0']['items']:
259-
disks.append((disk['capacity'], disk['price_id']))
249+
disks.append((int(disk['capacity']), disk['price_id']))
260250

261-
return [('disk(0)', disks)]
251+
return [('disks', disks)]
262252
elif 'nic' == section:
263253
single = []
264254
dual = []
265255

266256
for item in bmi_options['categories']['port_speed']['items']:
267257
if 'dual' in item['description'].lower():
268-
dual.append((str(item['capacity']) + '_DUAL',
258+
dual.append((str(int(item['capacity'])) + '_DUAL',
269259
item['price_id']))
270260
else:
271-
single.append((item['capacity'], item['price_id']))
261+
single.append((int(item['capacity']), item['price_id']))
272262

273263
return [('single nic', single), ('dual nic', dual)]
274-
elif 'bandwidth' == section:
275-
options = []
276-
for item in bmi_options['categories']['bandwidth']['items']:
277-
if item['capacity']:
278-
options.append((item['capacity'], item['price_id']))
279-
280-
return [('bandwidth', options)]
281264

282265
return []
283266

284267

285268
class CreateBMetalInstance(CLIRunnable):
286269
"""
287-
usage: sl bmetal create --hostname=HOST --domain=DOMAIN --cpu=CPU
270+
usage: sl bmetal create --hostname=HOST --domain=DOMAIN --cpu=CPU --disk=DISK...
288271
--memory=MEMORY --os=OS (--hourly | --monthly) [options]
289272
290273
Order/create a bare metal instance. See 'sl bmetal create-options' for valid
@@ -311,11 +294,7 @@ class CreateBMetalInstance(CLIRunnable):
311294
Note: Omitting this value defaults to the first
312295
available datacenter
313296
-n MBPS, --network=MBPS Network port speed in Mbps
314-
-b MBPS, --bandwith=MBPS Outbound bandwidth in Mbps
315-
--dry-run, --test Do not create CCI, just get a quote
316-
317-
--wait=SECONDS Block until CCI is finished provisioning for up to X
318-
seconds before returning.
297+
--dry-run, --test Do not create the instance, just get a quote
319298
"""
320299
action = 'create'
321300
options = ['confirm']
@@ -338,7 +317,7 @@ def execute(cls, client, args):
338317
args['--memory'])
339318

340319
if server_core:
341-
order['server_core'] = server_core
320+
order['server'] = server_core
342321
else:
343322
raise CLIAbort('Invalid CPU/memory combination specified.')
344323

@@ -356,16 +335,18 @@ def execute(cls, client, args):
356335
order['location'] = args['--datacenter'] or 'FIRST_AVAILABLE'
357336

358337
# Set the disk size
359-
if args.get('--disk'):
338+
disk_prices = []
339+
for disk in args.get('--disk'):
360340
disk_price = cls._get_price_id_from_options(bmi_options, 'disk',
361-
args.get('--disk'))
362-
else:
363-
disk_price = cls._get_default_value(bmi_options, 'disk0')
341+
disk)
364342

365-
if disk_price:
366-
order['disk0'] = disk_price
367-
else:
368-
raise CLIAbort('Invalid disk size specified.')
343+
if disk_price:
344+
disk_prices.append(disk_price)
345+
346+
if not disk_prices:
347+
disk_prices.append(cls._get_default_value(bmi_options, 'disk0'))
348+
349+
order['disks'] = disk_prices
369350

370351
# Set the port speed
371352
port_speed = args.get('--network') or 10
@@ -378,45 +359,6 @@ def execute(cls, client, args):
378359
else:
379360
raise CLIAbort('Invalid NIC speed specified.')
380361

381-
# Get the bandwidth limit and convert it to a price ID.
382-
# Yes, these should be multiplied by 1000, not 1024.
383-
if not args.get('--bandwidth'):
384-
bw_price = cls._get_default_value(bmi_options, 'bandwidth')
385-
else:
386-
try:
387-
bandwidth = int(args.get('--bandwidth', 0))
388-
if bandwidth < 1000:
389-
bandwidth = bandwidth * 1000
390-
except ValueError:
391-
unit = args['--bandwidth'][-1]
392-
bandwidth = int(args['--bandwidth'][0:-1])
393-
if unit in ['G', 'g']:
394-
bandwidth = bandwidth * 1000
395-
396-
bw_price = cls._get_price_id_from_options(bmi_options, 'bandwidth',
397-
bandwidth)
398-
399-
if bw_price:
400-
order['bandwidth'] = bw_price
401-
else:
402-
raise CLIAbort('Invalid bandwidth cap specified.')
403-
404-
# Now add in the other required values that the user did not specify.
405-
order['pri_ip_addresses'] = cls._get_default_value(bmi_options,
406-
'pri_ip_addresses')
407-
408-
order['monitoring'] = cls._get_default_value(bmi_options, 'monitoring')
409-
vuln_scanner = cls._get_default_value(bmi_options,
410-
'vulnerability_scanner')
411-
order['vulnerability_scanner'] = vuln_scanner
412-
order['response'] = cls._get_default_value(bmi_options, 'response')
413-
order['vpn_management'] = cls._get_default_value(bmi_options,
414-
'vpn_management')
415-
remote_mgmt = cls._get_default_value(bmi_options, 'remote_management')
416-
order['remote_management'] = remote_mgmt
417-
order['notification'] = cls._get_default_value(bmi_options,
418-
'notification')
419-
420362
# Begin output
421363
t = Table(['Item', 'cost'])
422364
t.align['Item'] = 'r'
@@ -457,7 +399,6 @@ def execute(cls, client, args):
457399
"This action will incur charges on your account. Continue?"):
458400
result = mgr.place_order(**order)
459401

460-
print result
461402
t = Table(['name', 'value'])
462403
t.align['name'] = 'r'
463404
t.align['value'] = 'l'
@@ -488,18 +429,18 @@ def _get_cpu_and_memory_price_ids(cls, bmi_options, cpu_value,
488429

489430
@classmethod
490431
def _get_default_value(cls, bmi_options, option):
491-
if bmi_options['categories'].get(option):
492-
for item in bmi_options['categories'][option]['items']:
493-
if not any([
494-
float(item['prices'][0].get('setupFee', 0)),
495-
float(item['prices'][0].get('recurringFee', 0)),
496-
float(item['prices'][0].get('hourlyRecurringFee', 0)),
497-
float(item['prices'][0].get('oneTimeFee', 0)),
498-
float(item['prices'][0].get('laborFee', 0)),
499-
]):
500-
return item['price_id']
501-
502-
return None
432+
if option not in bmi_options['categories']:
433+
return
434+
435+
for item in bmi_options['categories'][option]['items']:
436+
if not any([
437+
float(item['prices'][0].get('setupFee', 0)),
438+
float(item['prices'][0].get('recurringFee', 0)),
439+
float(item['prices'][0].get('hourlyRecurringFee', 0)),
440+
float(item['prices'][0].get('oneTimeFee', 0)),
441+
float(item['prices'][0].get('laborFee', 0)),
442+
]):
443+
return item['price_id']
503444

504445
@classmethod
505446
def _get_price_id_from_options(cls, bmi_options, option, value):

0 commit comments

Comments
 (0)