Exemplo n.º 1
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)
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 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)
Exemplo n.º 5
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)
Exemplo n.º 6
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")