def item_table(items): """Formats a table for billing items""" table = formatting.Table([ "Id", "Create Date", "Cost", "Category Code", "Ordered By", "Description", "Notes" ], title="Billing Items") table.align['Description'] = 'l' table.align['Category Code'] = 'l' for item in items: description = item.get('description') fqdn = "{}.{}".format(item.get('hostName', ''), item.get('domainName', '')) if fqdn != ".": description = fqdn user = utils.lookup(item, 'orderItem', 'order', 'userRecord') ordered_by = "IBM" create_date = utils.clean_time(item.get('createDate'), in_format='%Y-%m-%d', out_format='%Y-%m-%d') if user: # ordered_by = "{} ({})".format(user.get('displayName'), utils.lookup(user, 'userStatus', 'name')) ordered_by = user.get('displayName') table.add_row([ item.get('id'), create_date, item.get('nextInvoiceTotalRecurringAmount'), item.get('categoryCode'), ordered_by, utils.trim_to(description, 50), utils.trim_to(item.get('notes', 'None'), 40), ]) return table
def cli(env, limit): """Lists account orders. Use `slcli order lookup <ID>` to find more details about a specific order.""" manager = AccountManager(env.client) orders = manager.get_account_all_billing_orders(limit) order_table = formatting.Table(['Id', 'State', 'User', 'Date', 'Amount', 'Item'], title="orders") order_table.align = 'l' for order in orders: items = [] for item in order['items']: items.append(item['description']) create_date = utils.clean_time(order['createDate'], in_format='%Y-%m-%d', out_format='%Y-%m-%d') order_table.add_row([order['id'], order['status'], order['userRecord']['username'], create_date, order['orderTotalAmount'], utils.trim_to(' '.join(map(str, items)), 50)]) env.fout(order_table)
def cli(env): """Show all licenses.""" manager = account.AccountManager(env.client) control_panel = manager.get_active_virtual_licenses() vmwares = manager.get_active_account_licenses() table_panel = formatting.KeyValueTable([ 'id', 'ip_address', 'manufacturer', 'software', 'key', 'subnet', 'subnet notes' ], title="Control Panel Licenses") table_vmware = formatting.KeyValueTable([ 'name', 'license_key', 'cpus', 'description', 'manufacturer', 'requiredUser' ], title="VMware Licenses") for panel in control_panel: table_panel.add_row([ panel.get('id'), panel.get('ipAddress'), utils.lookup(panel, 'softwareDescription', 'manufacturer'), utils.trim_to( utils.lookup(panel, 'softwareDescription', 'longDescription'), 40), panel.get('key'), utils.lookup(panel, 'subnet', 'broadcastAddress'), utils.lookup(panel, 'subnet', 'note') ]) env.fout(table_panel) for vmware in vmwares: table_vmware.add_row([ utils.lookup(vmware, 'softwareDescription', 'name'), vmware.get('key'), vmware.get('capacity'), utils.lookup(vmware, 'billingItem', 'description'), utils.lookup(vmware, 'softwareDescription', 'manufacturer'), utils.lookup(vmware, 'softwareDescription', 'requiredUser') ]) env.fout(table_vmware)
def cli(env): """Server order options for a given chassis.""" licenses_manager = LicensesManager(env.client) options = licenses_manager.get_create_options() table = formatting.Table( ['Id', 'description', 'keyName', 'capacity', 'recurringFee']) for item in options: fee = 0 if len(item.get('prices', [])) > 0: fee = item.get('prices')[0].get('recurringFee', 0) table.add_row([ item.get('id'), utils.trim_to(item.get('description'), 40), item.get('keyName'), item.get('capacity'), fee ]) env.fout(table)