def cli(env, limit, closed=False, get_all=False): """List invoices""" manager = AccountManager(env.client) invoices = manager.get_invoices(limit, closed, get_all) table = formatting.Table([ "Id", "Created", "Type", "Status", "Starting Balance", "Ending Balance", "Invoice Amount", "Items" ]) table.align['Starting Balance'] = 'l' table.align['Ending Balance'] = 'l' table.align['Invoice Amount'] = 'l' table.align['Items'] = 'l' if isinstance(invoices, dict): invoices = [invoices] for invoice in invoices: table.add_row([ invoice.get('id'), utils.clean_time(invoice.get('createDate'), out_format="%Y-%m-%d"), invoice.get('typeCode'), invoice.get('statusCode'), invoice.get('startingBalance'), invoice.get('endingBalance'), invoice.get('invoiceTotalAmount'), invoice.get('itemCount') ]) env.fout(table)
def cli(env): """Displays bandwidth pool information Similiar to https://cloud.ibm.com/classic/network/bandwidth/vdr """ manager = AccountManager(env.client) items = manager.get_bandwidth_pools() table = formatting.Table([ "Id", "Pool Name", "Region", "Servers", "Allocation", "Current Usage", "Projected Usage" ], title="Bandwidth Pools") table.align = 'l' for item in items: id_bandwidth = item.get('id') name = item.get('name') region = utils.lookup(item, 'locationGroup', 'name') servers = manager.get_bandwidth_pool_counts(identifier=item.get('id')) allocation = "{} GB".format(item.get('totalBandwidthAllocated', 0)) current = "{} GB".format( utils.lookup(item, 'billingCyclePublicBandwidthUsage', 'amountOut')) projected = "{} GB".format(item.get('projectedPublicBandwidthUsage', 0)) table.add_row([ id_bandwidth, name, region, servers, allocation, current, projected ]) env.fout(table)
def cli(env): """Lists Email Delivery Service """ manager = AccountManager(env.client) email_manager = EmailManager(env.client) result = manager.get_network_message_delivery_accounts() table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table_information = formatting.KeyValueTable( ['id', 'username', 'hostname', 'description', 'vendor']) table_information.align['id'] = 'r' table_information.align['username'] = '******' for email in result: table_information.add_row([ email.get('id'), email.get('username'), email.get('emailAddress'), utils.lookup(email, 'type', 'description'), utils.lookup(email, 'vendor', 'keyName') ]) overview_table = _build_overview_table( email_manager.get_account_overview(email.get('id'))) statistics = email_manager.get_statistics(email.get('id')) table.add_row(['email_information', table_information]) table.add_row(['email_overview', overview_table]) for statistic in statistics: table.add_row(['statistics', build_statistics_table(statistic)]) env.fout(table)
def cli(env, ack_all, planned, unplanned, announcement): """Summary and acknowledgement of upcoming and ongoing maintenance events""" manager = AccountManager(env.client) planned_events = manager.get_upcoming_events("PLANNED") unplanned_events = manager.get_upcoming_events("UNPLANNED_INCIDENT") announcement_events = manager.get_upcoming_events("ANNOUNCEMENT") add_ack_flag(planned_events, manager, ack_all) add_ack_flag(unplanned_events, manager, ack_all) add_ack_flag(announcement_events, manager, ack_all) if planned: env.fout(planned_event_table(planned_events)) if unplanned: env.fout(unplanned_event_table(unplanned_events)) if announcement: env.fout(announcement_event_table(announcement_events)) if not planned and not unplanned and not announcement: env.fout(planned_event_table(planned_events)) env.fout(unplanned_event_table(unplanned_events)) env.fout(announcement_event_table(announcement_events))
def cli(env, identifier, details): """Invoice details""" manager = AccountManager(env.client) top_items = manager.get_billing_items(identifier) table = get_invoice_table(identifier, top_items, details) env.fout(table)
def cli(env, identifier): """Cancels a billing item.""" manager = AccountManager(env.client) item = manager.cancel_item(identifier) env.fout(item)
def cli(env, identifier): """Cancels a billing item.""" manager = AccountManager(env.client) item = manager.cancel_item(identifier) if item: env.fout("Item: {} was cancelled.".format(identifier))
def cli(env, ack_all): """Summary and acknowledgement of upcoming and ongoing maintenance events""" manager = AccountManager(env.client) events = manager.get_upcoming_events() if ack_all: for event in events: result = manager.ack_event(event['id']) event['acknowledgedFlag'] = result env.fout(event_table(events))
def cli(env): """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) env.fout(table)
def cli(env, identifier, ack): """Details of a specific event, and ability to acknowledge event.""" # Print a list of all on going maintenance manager = AccountManager(env.client) event = manager.get_event(identifier) if ack: manager.ack_event(identifier) env.fout(basic_event_table(event)) env.fout(impacted_table(event)) env.fout(update_table(event))
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, identifier, details): """Invoices and all that mess""" manager = AccountManager(env.client) top_items = manager.get_billing_items(identifier) title = "Invoice %s" % identifier table = formatting.Table([ "Item Id", "Category", "Description", "Single", "Monthly", "Create Date", "Location" ], title=title) table.align['category'] = 'l' table.align['description'] = 'l' for item in top_items: fqdn = "%s.%s" % (item.get('hostName', ''), item.get('domainName', '')) # category id=2046, ram_usage doesn't have a name... category = utils.lookup(item, 'category', 'name') or item.get('categoryCode') description = nice_string(item.get('description')) if fqdn != '.': description = "%s (%s)" % (item.get('description'), fqdn) table.add_row([ item.get('id'), category, nice_string(description), "$%.2f" % float(item.get('oneTimeAfterTaxAmount')), "$%.2f" % float(item.get('recurringAfterTaxAmount')), utils.clean_time(item.get('createDate'), out_format="%Y-%m-%d"), utils.lookup(item, 'location', 'name') ]) if details: for child in item.get('children', []): table.add_row([ '>>>', utils.lookup(child, 'category', 'name'), nice_string(child.get('description')), "$%.2f" % float(child.get('oneTimeAfterTaxAmount')), "$%.2f" % float(child.get('recurringAfterTaxAmount')), '---', '---' ]) env.fout(table)
def set_up(self): self.manager = AccountManager(self.client) self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
def cli(env, identifier): """Gets detailed information about a billing item.""" manager = AccountManager(env.client) item = manager.get_item_detail(identifier) env.fout(item_table(item))
def cli(env): """Prints some various bits of information about an account""" manager = AccountManager(env.client) summary = manager.get_summary() env.fout(get_snapshot_table(summary))