Skip to content

Commit dbb70b7

Browse files
author
Nathan Beittenmiller
committed
Changed per peer review notes and future API plans. Cutting down the number of options available when ordering any kind of server.
1 parent 94d9784 commit dbb70b7

3 files changed

Lines changed: 55 additions & 231 deletions

File tree

SoftLayer/CLI/modules/bmetal.py

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -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):
@@ -107,13 +106,6 @@ def execute(cls, client, args):
107106
item[0] for item in sorted(result[1],
108107
key=lambda x: x[0]))])
109108

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]))])
116-
117109
return t
118110

119111
@classmethod
@@ -256,9 +248,9 @@ def _generate_windows_code(description):
256248
elif 'disk' == section:
257249
disks = []
258250
for disk in bmi_options['categories']['disk0']['items']:
259-
disks.append((disk['capacity'], disk['price_id']))
251+
disks.append((int(disk['capacity']), disk['price_id']))
260252

261-
return [('disk(0)', disks)]
253+
return [('disks', disks)]
262254
elif 'nic' == section:
263255
single = []
264256
dual = []
@@ -271,20 +263,13 @@ def _generate_windows_code(description):
271263
single.append((item['capacity'], item['price_id']))
272264

273265
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)]
281266

282267
return []
283268

284269

285270
class CreateBMetalInstance(CLIRunnable):
286271
"""
287-
usage: sl bmetal create --hostname=HOST --domain=DOMAIN --cpu=CPU
272+
usage: sl bmetal create --hostname=HOST --domain=DOMAIN --cpu=CPU --disk=DISK...
288273
--memory=MEMORY --os=OS (--hourly | --monthly) [options]
289274
290275
Order/create a bare metal instance. See 'sl bmetal create-options' for valid
@@ -311,7 +296,6 @@ class CreateBMetalInstance(CLIRunnable):
311296
Note: Omitting this value defaults to the first
312297
available datacenter
313298
-n MBPS, --network=MBPS Network port speed in Mbps
314-
-b MBPS, --bandwith=MBPS Outbound bandwidth in Mbps
315299
--dry-run, --test Do not create the instance, just get a quote
316300
"""
317301
action = 'create'
@@ -335,7 +319,7 @@ def execute(cls, client, args):
335319
args['--memory'])
336320

337321
if server_core:
338-
order['server_core'] = server_core
322+
order['server'] = server_core
339323
else:
340324
raise CLIAbort('Invalid CPU/memory combination specified.')
341325

@@ -353,16 +337,16 @@ def execute(cls, client, args):
353337
order['location'] = args['--datacenter'] or 'FIRST_AVAILABLE'
354338

355339
# Set the disk size
356-
if args.get('--disk'):
340+
disk_prices = []
341+
for disk in args.get('--disk'):
357342
disk_price = cls._get_price_id_from_options(bmi_options, 'disk',
358-
args.get('--disk'))
359-
else:
360-
disk_price = cls._get_default_value(bmi_options, 'disk0')
343+
disk)
361344

362-
if disk_price:
363-
order['disk0'] = disk_price
364-
else:
365-
raise CLIAbort('Invalid disk size specified.')
345+
if disk_price:
346+
disk_prices.append(disk_price)
347+
348+
if not disk_prices:
349+
disk_price = cls._get_default_value(bmi_options, 'disk0')
366350

367351
# Set the port speed
368352
port_speed = args.get('--network') or 10
@@ -375,45 +359,6 @@ def execute(cls, client, args):
375359
else:
376360
raise CLIAbort('Invalid NIC speed specified.')
377361

378-
# Get the bandwidth limit and convert it to a price ID.
379-
# Yes, these should be multiplied by 1000, not 1024.
380-
if not args.get('--bandwidth'):
381-
bw_price = cls._get_default_value(bmi_options, 'bandwidth')
382-
else:
383-
try:
384-
bandwidth = int(args.get('--bandwidth', 0))
385-
if bandwidth < 1000:
386-
bandwidth = bandwidth * 1000
387-
except ValueError:
388-
unit = args['--bandwidth'][-1]
389-
bandwidth = int(args['--bandwidth'][0:-1])
390-
if unit in ['G', 'g']:
391-
bandwidth = bandwidth * 1000
392-
393-
bw_price = cls._get_price_id_from_options(bmi_options, 'bandwidth',
394-
bandwidth)
395-
396-
if bw_price:
397-
order['bandwidth'] = bw_price
398-
else:
399-
raise CLIAbort('Invalid bandwidth cap specified.')
400-
401-
# Now add in the other required values that the user did not specify.
402-
order['pri_ip_addresses'] = cls._get_default_value(bmi_options,
403-
'pri_ip_addresses')
404-
405-
order['monitoring'] = cls._get_default_value(bmi_options, 'monitoring')
406-
vuln_scanner = cls._get_default_value(bmi_options,
407-
'vulnerability_scanner')
408-
order['vulnerability_scanner'] = vuln_scanner
409-
order['response'] = cls._get_default_value(bmi_options, 'response')
410-
order['vpn_management'] = cls._get_default_value(bmi_options,
411-
'vpn_management')
412-
remote_mgmt = cls._get_default_value(bmi_options, 'remote_management')
413-
order['remote_management'] = remote_mgmt
414-
order['notification'] = cls._get_default_value(bmi_options,
415-
'notification')
416-
417362
# Begin output
418363
t = Table(['Item', 'cost'])
419364
t.align['Item'] = 'r'

SoftLayer/CLI/modules/hardware.py

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,11 @@ class HardwareCreateOptions(CLIRunnable):
329329
--disk Show disk options
330330
--os Show operating system options
331331
--memory Show memory size options
332-
--gpus Show GPU options (if any)
333-
--bandwidth Show bandwidth options
334332
--controller Show disk controller options
335333
"""
336334

337335
action = 'create-options'
338-
options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic', 'bandwidth',
339-
'gpus', 'ps', 'controller']
336+
options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic', 'controller']
340337

341338
@classmethod
342339
def execute(cls, client, args):
@@ -401,20 +398,6 @@ def execute(cls, client, args):
401398
item[0] for item in sorted(result[1],
402399
key=lambda x: x[0]))])
403400

404-
gpu_categories = ds_options['categories'].get('gpu0')
405-
if (args['--gpus'] or show_all) and gpu_categories:
406-
results = cls.get_create_options(ds_options, 'gpus')
407-
408-
for result in results:
409-
t.add_row([result[0], listing(item[0] for item in result[1])])
410-
411-
if args['--bandwidth'] or show_all:
412-
results = cls.get_create_options(ds_options, 'bandwidth')[0]
413-
414-
t.add_row([results[0], listing(
415-
item[0] for item in sorted(results[1],
416-
key=lambda x: x[0]))])
417-
418401
if args['--controller'] or show_all:
419402
results = cls.get_create_options(ds_options, 'disk_controller')[0]
420403

@@ -586,21 +569,6 @@ def _generate_windows_code(description):
586569
single.append((int(item['capacity']), item['price_id']))
587570

588571
return [('single nic', single), ('dual nic', dual)]
589-
elif 'gpus' == section:
590-
results = []
591-
592-
for item in ds_options['categories']['gpu0']['items']:
593-
text = 'gpu: ' + item['description']
594-
results.append((text, [(str(item['id']), item['price_id'])]))
595-
596-
return results
597-
elif 'bandwidth' == section:
598-
options = []
599-
for item in ds_options['categories']['bandwidth']['items']:
600-
if item['capacity']:
601-
options.append((int(item['capacity']), item['price_id']))
602-
603-
return [('bandwidth', options)]
604572
elif 'disk_controller' == section:
605573
options = []
606574
for item in ds_options['categories']['disk_controller']['items']:
@@ -638,9 +606,6 @@ class CreateHardware(CLIRunnable):
638606
Note: Omitting this value defaults to the first
639607
available datacenter
640608
-n MBPS, --network=MBPS Network port speed in Mbps
641-
-b MBPS, --bandwidth=MBPS Outbound bandwidth in Mbps
642-
--gpu0=GPU First GPU option for chassis that support them.
643-
--gpu1=GPU Second GPU option for chassis that support them.
644609
--controller=RAID The RAID configuration for the server.
645610
Defaults to None.
646611
--dry-run, --test Do not create the server, just get a quote
@@ -675,18 +640,15 @@ def execute(cls, client, args):
675640
order['ram'] = cls._get_price_id_from_options(ds_options, 'memory',
676641
int(args['--memory']))
677642
# Set the disk sizes
678-
has_disks = False
679-
disk_count = 0
643+
disk_prices = []
680644
for disk in args.get('--disk'):
681645
disk_price = cls._get_price_id_from_options(ds_options, 'disk',
682646
disk)
683647

684648
if disk_price:
685-
order['disk' + str(disk_count)] = disk_price
686-
disk_count += 1
687-
has_disks = True
649+
disk_prices.append(disk_price)
688650

689-
if not has_disks:
651+
if not disk_prices:
690652
disk_price = cls._get_default_value(ds_options, 'disk0')
691653

692654
# Set the disk controller price
@@ -701,16 +663,6 @@ def execute(cls, client, args):
701663

702664
order['disk_controller'] = dc_price
703665

704-
if args.get('--gpu0'):
705-
gpu0_price = cls._get_price_id_from_options(ds_options, 'gpus',
706-
args.get('--gpu0'))
707-
order['gpu0'] = gpu0_price
708-
709-
if args.get('--gpu1'):
710-
gpu1_price = cls._get_price_id_from_options(ds_options, 'gpus',
711-
args.get('--gpu1'))
712-
order['gpu1'] = gpu1_price
713-
714666
# Set the port speed
715667
port_speed = args.get('--network') or 10
716668

@@ -722,54 +674,6 @@ def execute(cls, client, args):
722674
else:
723675
raise CLIAbort('Invalid NIC speed specified.')
724676

725-
# Get the bandwidth limit and convert it to a price ID.
726-
# Yes, these should be multiplied by 1000, not 1024.
727-
if not args.get('--bandwidth'):
728-
bw_price = cls._get_default_value(ds_options, 'bandwidth')
729-
else:
730-
try:
731-
bandwidth = int(args.get('--bandwidth', 0))
732-
if bandwidth < 1000:
733-
bandwidth = bandwidth * 1000
734-
except ValueError:
735-
unit = args['--bandwidth'][-1]
736-
bandwidth = int(args['--bandwidth'][0:-1])
737-
if unit in ['G', 'g']:
738-
bandwidth = bandwidth * 1000
739-
740-
bw_price = cls._get_price_id_from_options(ds_options, 'bandwidth',
741-
bandwidth)
742-
743-
if bw_price:
744-
order['bandwidth'] = bw_price
745-
else:
746-
raise CLIAbort('Invalid bandwidth cap specified.')
747-
748-
# Now add in the other required values that the user did not specify.
749-
# TODO - Does this need to be generic? What if stuff costs money?
750-
order['pri_ip_addresses'] = cls._get_default_value(ds_options,
751-
'pri_ip_addresses')
752-
753-
order['monitoring'] = cls._get_default_value(ds_options, 'monitoring')
754-
vuln_scanner = cls._get_default_value(ds_options,
755-
'vulnerability_scanner')
756-
order['vulnerability_scanner'] = vuln_scanner
757-
order['response'] = cls._get_default_value(ds_options, 'response')
758-
order['vpn_management'] = cls._get_default_value(ds_options,
759-
'vpn_management')
760-
remote_mgmt = cls._get_default_value(ds_options, 'remote_management')
761-
order['remote_management'] = remote_mgmt
762-
order['notification'] = cls._get_default_value(ds_options,
763-
'notification')
764-
order['lockbox'] = cls._get_default_value(ds_options, 'lockbox')
765-
766-
# Add in additional required values for this chassis.
767-
ps = ds_options['categories'].get('power_supply')
768-
769-
if ps and ps['is_required']:
770-
order['power_supply'] = cls._get_default_value(ds_options,
771-
'power_supply')
772-
773677
# Begin output
774678
t = Table(['Item', 'cost'])
775679
t.align['Item'] = 'r'

0 commit comments

Comments
 (0)