|
1 | | -"""Gets some details about a specific billing item.""" |
2 | | -# :license: MIT, see LICENSE for more details. |
3 | | -import click |
4 | | - |
5 | | -from SoftLayer.CLI import environment |
6 | | -from SoftLayer.CLI import formatting |
7 | | -from SoftLayer.managers.account import AccountManager as AccountManager |
8 | | -from SoftLayer import utils |
9 | | - |
10 | | - |
11 | | -@click.command() |
12 | | -@click.argument('identifier') |
13 | | -@environment.pass_env |
14 | | -def cli(env, identifier): |
15 | | - """Gets detailed information about a billing item.""" |
16 | | - manager = AccountManager(env.client) |
17 | | - item = manager.get_billing_item(identifier) |
18 | | - env.fout(item_table(item)) |
19 | | - |
20 | | - |
21 | | -def item_table(item): |
22 | | - """Formats a table for billing items""" |
23 | | - |
24 | | - date_format = '%Y-%m-%d' |
25 | | - table = formatting.KeyValueTable(["Key", "Value"], title="{}".format(item.get('description', 'Billing Item'))) |
26 | | - table.add_row(['createDate', utils.clean_time(item.get('createDate'), date_format, date_format)]) |
27 | | - table.add_row(['cycleStartDate', utils.clean_time(item.get('cycleStartDate'), date_format, date_format)]) |
28 | | - table.add_row(['cancellationDate', utils.clean_time(item.get('cancellationDate'), date_format, date_format)]) |
29 | | - table.add_row(['description', item.get('description')]) |
30 | | - fqdn = "{}.{}".format(item.get('hostName'), item.get('domain')) |
31 | | - if fqdn != ".": |
32 | | - table.add_row(['FQDN', fqdn]) |
33 | | - |
34 | | - if item.get('hourlyFlag', False): |
35 | | - table.add_row(['hourlyRecurringFee', item.get('hourlyRecurringFee')]) |
36 | | - table.add_row(['hoursUsed', item.get('hoursUsed')]) |
37 | | - table.add_row(['currentHourlyCharge', item.get('currentHourlyCharge')]) |
38 | | - else: |
39 | | - table.add_row(['recurringFee', item.get('recurringFee')]) |
40 | | - |
41 | | - ordered_by = "IBM" |
42 | | - user = utils.lookup(item, 'orderItem', 'order', 'userRecord') |
43 | | - if user: |
44 | | - ordered_by = "{} ({})".format(user.get('displayName'), utils.lookup(user, 'userStatus', 'name')) |
45 | | - table.add_row(['Ordered By', ordered_by]) |
46 | | - table.add_row(['Notes', item.get('notes')]) |
47 | | - table.add_row(['Location', utils.lookup(item, 'location', 'name')]) |
48 | | - if item.get('children'): |
49 | | - for child in item.get('children'): |
50 | | - table.add_row([child.get('categoryCode'), child.get('description')]) |
51 | | - |
52 | | - return table |
| 1 | +"""Gets some details about a specific billing item.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | +import click |
| 4 | + |
| 5 | +from SoftLayer.CLI import environment |
| 6 | +from SoftLayer.CLI import formatting |
| 7 | +from SoftLayer.managers.account import AccountManager as AccountManager |
| 8 | +from SoftLayer import utils |
| 9 | + |
| 10 | + |
| 11 | +@click.command() |
| 12 | +@click.argument('identifier') |
| 13 | +@environment.pass_env |
| 14 | +def cli(env, identifier): |
| 15 | + """Gets detailed information about a billing item.""" |
| 16 | + manager = AccountManager(env.client) |
| 17 | + item = manager.get_item_detail(identifier) |
| 18 | + env.fout(item_table(item)) |
| 19 | + |
| 20 | + |
| 21 | +def item_table(item): |
| 22 | + """Formats a table for billing items""" |
| 23 | + |
| 24 | + date_format = '%Y-%m-%d' |
| 25 | + table = formatting.Table(["Key", "Value"], title="{}".format(item.get('description', 'Billing Item'))) |
| 26 | + table.add_row(['createDate', utils.clean_time(item.get('createDate'), date_format, date_format)]) |
| 27 | + table.add_row(['cycleStartDate', utils.clean_time(item.get('cycleStartDate'), date_format, date_format)]) |
| 28 | + table.add_row(['cancellationDate', utils.clean_time(item.get('cancellationDate'), date_format, date_format)]) |
| 29 | + table.add_row(['description', item.get('description')]) |
| 30 | + table.align = 'l' |
| 31 | + fqdn = "{}.{}".format(item.get('hostName'), item.get('domain')) |
| 32 | + if fqdn != ".": |
| 33 | + table.add_row(['FQDN', fqdn]) |
| 34 | + |
| 35 | + if item.get('hourlyFlag', False): |
| 36 | + table.add_row(['hourlyRecurringFee', item.get('hourlyRecurringFee')]) |
| 37 | + table.add_row(['hoursUsed', item.get('hoursUsed')]) |
| 38 | + table.add_row(['currentHourlyCharge', item.get('currentHourlyCharge')]) |
| 39 | + else: |
| 40 | + table.add_row(['recurringFee', item.get('recurringFee')]) |
| 41 | + |
| 42 | + ordered_by = "IBM" |
| 43 | + user = utils.lookup(item, 'orderItem', 'order', 'userRecord') |
| 44 | + if user: |
| 45 | + ordered_by = "{} ({})".format(user.get('displayName'), utils.lookup(user, 'userStatus', 'name')) |
| 46 | + table.add_row(['Ordered By', ordered_by]) |
| 47 | + table.add_row(['Notes', item.get('notes')]) |
| 48 | + table.add_row(['Location', utils.lookup(item, 'location', 'name')]) |
| 49 | + if item.get('children'): |
| 50 | + for child in item.get('children'): |
| 51 | + table.add_row([child.get('categoryCode'), child.get('description')]) |
| 52 | + |
| 53 | + return table |
0 commit comments