Skip to content
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
15 changes: 10 additions & 5 deletions SoftLayer/CLI/account/billing_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@


@click.command(cls=SLCommand)
@click.option('--create', '-c', help='The date the billing item was created.')
@click.option('--ordered', '-o', help='Name that ordered the item')
@click.option('--category', '-C', help='Category name')
@environment.pass_env
def cli(env):
def cli(env, create, category, ordered):
"""Lists billing items with some other useful information.

Similiar to https://cloud.ibm.com/billing/billing-items
"""

manager = AccountManager(env.client)
items = manager.get_account_billing_items()
table = item_table(items)
items = manager.get_account_billing_items(create, category)
table = item_table(items, ordered)

env.fout(table)


def item_table(items):
def item_table(items, ordered=None):
"""Formats a table for billing items"""
table = formatting.Table([
"Id",
Expand All @@ -48,7 +51,9 @@ def item_table(items):
if user:
# ordered_by = "{} ({})".format(user.get('displayName'), utils.lookup(user, 'userStatus', 'name'))
ordered_by = user.get('displayName')

if ordered:
if ordered != ordered_by:
continue
table.add_row([
item.get('id'),
create_date,
Expand Down
9 changes: 8 additions & 1 deletion SoftLayer/managers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_billing_items(self, identifier):
limit=100
)

def get_account_billing_items(self, mask=None):
def get_account_billing_items(self, create=None, category=None, mask=None):
"""Gets all the topLevelBillingItems currently active on the account

:param string mask: Object Mask
Expand All @@ -226,6 +226,13 @@ def get_account_billing_items(self, mask=None):
}
}

if category:
object_filter = utils.dict_merge(object_filter,
{"allTopLevelBillingItems": {"categoryCode": {"operation": category}}})
if create:
object_filter = utils.dict_merge(object_filter,
{"allTopLevelBillingItems": {"createDate": {"operation": create}}})

return self.client.call('Account', 'getAllTopLevelBillingItems',
mask=mask, filter=object_filter, iter=True, limit=100)

Expand Down
15 changes: 15 additions & 0 deletions tests/CLI/modules/account_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ def test_account_billing_items(self):
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

def test_account_billing_items_by_category(self):
result = self.run_command(['account', 'billing-items', '--category', 'server'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

def test_account_billing_items_by_ordered(self):
result = self.run_command(['account', 'billing-items', '--ordered', 'Test'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

def test_account_billing_items_create(self):
result = self.run_command(['account', 'billing-items', '--create', '04-21-2023'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

# slcli account item-detail
def test_account_get_billing_item_detail(self):
result = self.run_command(['account', 'item-detail', '12345'])
Expand Down