Skip to content

Commit 193afe2

Browse files
author
Nathan Beittenmiller
committed
Discovered that packages now have a type I can use for filtering out unnecessary packages. Removed hardcoded package IDs.
1 parent 9996990 commit 193afe2

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

SoftLayer/CLI/modules/server.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,11 @@ def execute(self, args):
457457
if args['--cpu'] or show_all:
458458
results = self.get_create_options(ds_options, 'cpu')
459459

460-
cpu_table = Table(['id', 'description'])
461-
for result in sorted(results):
460+
cpu_table = Table(['ID', 'Description'])
461+
cpu_table.align['ID'] = 'r'
462+
cpu_table.align['Description'] = 'l'
463+
464+
for result in sorted(results, key=lambda x: x[1]):
462465
cpu_table.add_row([result[1], result[0]])
463466
table.add_row(['cpu', cpu_table])
464467

@@ -520,7 +523,7 @@ def get_create_options(self, ds_options, section, pretty=True):
520523
datacenters = [loc['keyname']
521524
for loc in ds_options['locations']]
522525
return [('datacenter', datacenters)]
523-
elif 'cpu' == section:
526+
elif 'cpu' == section and 'server' in ds_options['categories']:
524527
results = []
525528

526529
for item in ds_options['categories']['server']['items']:
@@ -530,7 +533,7 @@ def get_create_options(self, ds_options, section, pretty=True):
530533
))
531534

532535
return results
533-
elif 'memory' == section:
536+
elif 'memory' == section and 'ram' in ds_options['categories']:
534537
ram = []
535538
for option in ds_options['categories']['ram']['items']:
536539
ram.append((int(option['capacity']), option['price_id']))

SoftLayer/managers/hardware.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,25 @@ def get_available_dedicated_server_packages(self):
184184
the form (id, name, description)
185185
"""
186186

187-
# Note - This currently returns a hard coded list until the API is
188-
# updated to allow filtering on packages to just those for ordering
189-
# servers.
190-
package_ids = [13, 15, 23, 25, 26, 27, 29, 32, 41, 42, 43, 44, 49, 51,
191-
52, 53, 54, 55, 56, 57, 126, 140, 141, 142, 143, 144,
192-
145, 146, 147, 148, 158]
193-
194187
package_obj = self.client['Product_Package']
195188
packages = []
196189

197-
for package_id in package_ids:
198-
package = package_obj.getObject(id=package_id,
199-
mask='mask[id, name, description]')
190+
# Pull back only server packages
191+
mask = 'id,name,description,type'
192+
_filter = {
193+
'type': {
194+
'keyName': {
195+
'operation': 'in',
196+
'options': [{'name': 'data', 'value': ['BARE_METAL_CPU']}],
197+
},
198+
},
199+
}
200200

201-
if package.get('name'):
201+
for package in package_obj.getAllObjects(mask=mask, filter=_filter):
202+
# Filter out packages without a name or that are designated as
203+
# 'OUTlET.' The outlet packages are missing some necessary data
204+
# and their orders will fail.
205+
if package.get('name') and 'OUTLET' not in package['description']:
202206
packages.append((package['id'], package['name'],
203207
package['description']))
204208

0 commit comments

Comments
 (0)