Skip to content

Add pricing date to slcli order preset-list #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions SoftLayer/CLI/order/preset_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
@click.argument('package_keyname')
@click.option('--keyword',
help="A word (or string) used to filter preset names.")
@click.option('--prices', '-p', is_flag=True, help='Use --prices to list the server item prices, e.g. --prices')
@environment.pass_env
def cli(env, package_keyname, keyword):
def cli(env, package_keyname, keyword, prices):
"""List package presets.

.. Note::
Expand All @@ -33,6 +34,8 @@ def cli(env, package_keyname, keyword):
slcli order preset-list BARE_METAL_SERVER --keyword gpu

"""

tables = []
table = formatting.Table(COLUMNS)
manager = ordering.OrderingManager(env.client)

Expand All @@ -41,10 +44,36 @@ def cli(env, package_keyname, keyword):
_filter = {'activePresets': {'name': {'operation': '*= %s' % keyword}}}
presets = manager.list_presets(package_keyname, filter=_filter)

for preset in presets:
table.add_row([
str(preset['name']).strip(),
str(preset['keyName']).strip(),
str(preset['description']).strip()
])
env.fout(table)
if prices:
table_prices = formatting.Table(['keyName', 'priceId', 'Hourly', 'Monthly', 'Restriction', 'Location'])
for price in presets:
locations = []
if price['locations'] != []:
for location in price['locations']:
locations.append(location['name'])
cr_max = get_item_price_data(price['prices'][0], 'capacityRestrictionMaximum')
cr_min = get_item_price_data(price['prices'][0], 'capacityRestrictionMinimum')
cr_type = get_item_price_data(price['prices'][0], 'capacityRestrictionType')
table_prices.add_row([price['keyName'], price['id'],
get_item_price_data(price['prices'][0], 'hourlyRecurringFee'),
get_item_price_data(price['prices'][0], 'recurringFee'),
"%s - %s %s" % (cr_min, cr_max, cr_type), str(locations)])
tables.append(table_prices)

else:
for preset in presets:
table.add_row([
str(preset['name']).strip(),
str(preset['keyName']).strip(),
str(preset['description']).strip()
])
tables.append(table)
env.fout(tables)


def get_item_price_data(price, item_attribute):
"""Given an SoftLayer_Product_Item_Price, returns its default price data"""
result = '-'
if item_attribute in price:
result = price[item_attribute]
return result
33 changes: 30 additions & 3 deletions SoftLayer/fixtures/SoftLayer_Product_Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,23 +1847,50 @@
"isActive": "1",
"keyName": "M1_64X512X25",
"name": "M1.64x512x25",
"packageId": 835
"packageId": 835,
"locations": [],
"prices": [
{
"hourlyRecurringFee": "0",
"id": 258963,
"itemId": 8195,
"recurringFee": "0",
"setupFee": "0"
}]
},
{
"description": "M1.56x448x100",
"id": 797,
"isActive": "1",
"keyName": "M1_56X448X100",
"name": "M1.56x448x100",
"packageId": 835
"packageId": 835,
"locations": [],
"prices": [
{
"hourlyRecurringFee": "0",
"id": 698563,
"itemId": 8195,
"recurringFee": "0",
"setupFee": "0"
}]
},
{
"description": "M1.64x512x100",
"id": 801,
"isActive": "1",
"keyName": "M1_64X512X100",
"name": "M1.64x512x100",
"packageId": 835
"packageId": 835,
"locations": [],
"prices": [
{
"hourlyRecurringFee": "0",
"id": 963258,
"itemId": 8195,
"recurringFee": "0",
"setupFee": "0"
}]
}
]

Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/managers/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

PACKAGE_MASK = '''id, name, keyName, isActive, type'''

PRESET_MASK = '''id, name, keyName, description'''
PRESET_MASK = '''id, name, keyName, description, categories, prices, locations'''


class OrderingManager(object):
Expand Down
5 changes: 5 additions & 0 deletions tests/CLI/modules/order_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ def test_preset_list_keywork(self):
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Product_Package', 'getActivePresets', filter=_filter)

def test_preset_list_prices(self):
result = self.run_command(['order', 'preset-list', 'package', '--prices'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Product_Package', 'getActivePresets')

def test_location_list(self):
result = self.run_command(['order', 'package-locations', 'package'])
self.assert_no_fail(result)
Expand Down