Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def cli(env, identifier):
    """Cancels a billing item."""

    manager = AccountManager(env.client)
    item = manager.cancel_item(identifier)

    env.fout(item)
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def cli(env, limit, closed=False, get_all=False):
    """Invoices and all that mess"""

    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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
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))
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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))
Ejemplo n.º 12
0
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))
Ejemplo n.º 13
0
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 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)
Ejemplo n.º 16
0
 def set_up(self):
     self.manager = AccountManager(self.client)
     self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
Ejemplo n.º 17
0
class AccountManagerTests(testing.TestCase):
    def set_up(self):
        self.manager = AccountManager(self.client)
        self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'

    def test_get_summary(self):
        self.manager.get_summary()
        self.assert_called_with('SoftLayer_Account', 'getObject')

    def test_get_upcoming_events(self):
        self.manager.get_upcoming_events()
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_ack_event(self):
        self.manager.ack_event(12345)
        self.assert_called_with(self.SLNOE,
                                'acknowledgeNotification',
                                identifier=12345)

    def test_get_event(self):
        self.manager.get_event(12345)
        self.assert_called_with(self.SLNOE, 'getObject', identifier=12345)

    def test_get_invoices(self):
        self.manager.get_invoices()
        self.assert_called_with('SoftLayer_Account', 'getInvoices')

    def test_get_invoices_closed(self):
        self.manager.get_invoices(closed=True)
        _filter = {
            'invoices': {
                'createDate': {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['DESC']
                    }]
                }
            }
        }
        self.assert_called_with('SoftLayer_Account',
                                'getInvoices',
                                filter=_filter)

    def test_get_billing_items(self):
        self.manager.get_billing_items(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice',
                                'getInvoiceTopLevelItems')

    def test_get_account_billing_items(self):
        self.manager.get_account_billing_items()
        object_filter = {
            "allTopLevelBillingItems": {
                "cancellationDate": {
                    "operation": "is null"
                },
                "createDate": {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['ASC']
                    }]
                }
            }
        }

        self.assert_called_with('SoftLayer_Account',
                                'getAllTopLevelBillingItems',
                                offset=0,
                                limit=100,
                                filter=object_filter)
        self.manager.get_account_billing_items(mask="id")
        self.assert_called_with('SoftLayer_Account',
                                'getAllTopLevelBillingItems',
                                mask="mask[id]")

    def test_get_billing_item(self):
        self.manager.get_billing_item(12345)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=12345)
        self.manager.get_billing_item(12345, mask="id")
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=12345,
                                mask="mask[id]")

    def test_cancel_item(self):
        self.manager.cancel_item(12345)
        reason = "No longer needed"
        note = "Cancelled by testAccount with the SLCLI"
        self.assert_called_with('SoftLayer_Billing_Item',
                                'cancelItem',
                                args=(False, True, reason, note),
                                identifier=12345)
        reason = "TEST"
        note = "note test"
        self.manager.cancel_item(12345, reason, note)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'cancelItem',
                                args=(False, True, reason, note),
                                identifier=12345)
Ejemplo n.º 18
0
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))
Ejemplo n.º 19
0
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))
Ejemplo n.º 20
0
class AccountManagerTests(testing.TestCase):
    def set_up(self):
        self.manager = AccountManager(self.client)
        self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'

    def test_get_summary(self):
        self.manager.get_summary()
        self.assert_called_with('SoftLayer_Account', 'getObject')

    def test_get_planned_upcoming_events(self):
        self.manager.get_upcoming_events("PLANNED")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_get_unplanned_upcoming_events(self):
        self.manager.get_upcoming_events("UNPLANNED_INCIDENT")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_get_announcement_upcoming_events(self):
        self.manager.get_upcoming_events("ANNOUNCEMENT")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_add_planned_event_filter(self):
        event_type = 'PLANNED'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_add_unplanned_event_filter(self):
        event_type = 'UNPLANNED_INCIDENT'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_add_announcement_event_filter(self):
        event_type = 'ANNOUNCEMENT'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_ack_event(self):
        self.manager.ack_event(12345)
        self.assert_called_with(self.SLNOE,
                                'acknowledgeNotification',
                                identifier=12345)

    def test_get_event(self):
        self.manager.get_event(12345)
        self.assert_called_with(self.SLNOE, 'getObject', identifier=12345)

    def test_get_invoices(self):
        self.manager.get_invoices()
        self.assert_called_with('SoftLayer_Account', 'getInvoices')

    def test_get_invoices_closed(self):
        self.manager.get_invoices(closed=True)
        _filter = {
            'invoices': {
                'createDate': {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['DESC']
                    }]
                }
            }
        }
        self.assert_called_with('SoftLayer_Account',
                                'getInvoices',
                                filter=_filter)

    def test_get_billing_items(self):
        self.manager.get_billing_items(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice',
                                'getInvoiceTopLevelItems')

    def test_get_account_billing_items(self):
        self.manager.get_account_billing_items()
        object_filter = {
            "allTopLevelBillingItems": {
                "cancellationDate": {
                    "operation": "is null"
                },
                "createDate": {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['ASC']
                    }]
                }
            }
        }

        self.assert_called_with('SoftLayer_Account',
                                'getAllTopLevelBillingItems',
                                offset=0,
                                limit=100,
                                filter=object_filter)
        self.manager.get_account_billing_items(mask="id")
        self.assert_called_with('SoftLayer_Account',
                                'getAllTopLevelBillingItems',
                                mask="mask[id]")

    def test_get_billing_item(self):
        self.manager.get_billing_item(12345)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=12345)
        self.manager.get_billing_item(12345, mask="id")
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=12345,
                                mask="mask[id]")

    def test_cancel_item(self):
        self.manager.cancel_item(12345)
        reason = "No longer needed"
        note = "Cancelled by testAccount with the SLCLI"
        self.assert_called_with('SoftLayer_Billing_Item',
                                'cancelItem',
                                args=(False, True, reason, note),
                                identifier=12345)
        reason = "TEST"
        note = "note test"
        self.manager.cancel_item(12345, reason, note)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'cancelItem',
                                args=(False, True, reason, note),
                                identifier=12345)

    def test_get_billing_item_from_invoice(self):
        self.manager.get_billing_item_from_invoice(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice_Item',
                                'getBillingItem',
                                identifier=12345)

    def test_get_item_details_with_billing_item_id(self):
        self.manager.get_item_detail(12345)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=12345)

    def test_get_item_details_with_invoice_item_id(self):
        mock = self.set_mock('SoftLayer_Billing_Item', 'getObject')
        mock.side_effect = SoftLayerAPIError(
            404, "Unable to find object with id of '123456'.")
        self.manager.get_item_detail(123456)
        self.assert_called_with('SoftLayer_Billing_Item',
                                'getObject',
                                identifier=123456)
        self.assert_called_with('SoftLayer_Billing_Invoice_Item',
                                'getBillingItem',
                                identifier=123456)

    def test_get_routers(self):
        self.manager.get_routers()
        self.assert_called_with("SoftLayer_Account", "getRouters")
 def set_up(self):
     self.manager = AccountManager(self.client)
     self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
Ejemplo n.º 22
0
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))
class AccountManagerTests(testing.TestCase):

    def set_up(self):
        self.manager = AccountManager(self.client)
        self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'

    def test_get_summary(self):
        self.manager.get_summary()
        self.assert_called_with('SoftLayer_Account', 'getObject')

    def test_get_upcoming_events(self):
        self.manager.get_upcoming_events()
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_ack_event(self):
        self.manager.ack_event(12345)
        self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier=12345)

    def test_get_event(self):
        self.manager.get_event(12345)
        self.assert_called_with(self.SLNOE, 'getObject', identifier=12345)

    def test_get_invoices(self):
        self.manager.get_invoices()
        self.assert_called_with('SoftLayer_Account', 'getInvoices')

    def test_get_invoices_closed(self):
        self.manager.get_invoices(closed=True)
        _filter = {
            'invoices': {
                'createDate': {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['DESC']
                    }]
                }
            }
        }
        self.assert_called_with('SoftLayer_Account', 'getInvoices', filter=_filter)

    def test_get_billing_items(self):
        self.manager.get_billing_items(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems')