Example #1
0
 def _input_to_table(item):
     "Input metric data to table"
     pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
     pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
     pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
     pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
     table.add_row([
         item['type'],
         item['name'],
         formatting.b_to_gb(pub_in),
         formatting.b_to_gb(pub_out),
         formatting.b_to_gb(pri_in),
         formatting.b_to_gb(pri_out),
         item.get('pool') or formatting.blank(),
     ])
Example #2
0
def cli(env, start, end, sortby):
    """Bandwidth report for every pool/server.

    This reports on the total data transfered for each virtual sever, hardware
    server and bandwidth pool.
    """

    env.err('Generating bandwidth report for %s to %s' % (start, end))

    table = formatting.Table([
        'type',
        'name',
        'public_in',
        'public_out',
        'private_in',
        'private_out',
        'pool',
    ])
    table.sortby = sortby

    def f_type(key, results):
        "Filter metric data by type"
        return (result['counter'] for result in results
                if result['type'] == key)

    try:
        for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
                                    _get_virtual_bandwidth(env, start, end),
                                    _get_hardware_bandwidth(env, start, end)):
            pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
            pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
            pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
            pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
            table.add_row([
                item['type'],
                item['name'],
                formatting.b_to_gb(pub_in),
                formatting.b_to_gb(pub_out),
                formatting.b_to_gb(pri_in),
                formatting.b_to_gb(pri_out),
                item.get('pool') or formatting.blank(),
            ])
    except KeyboardInterrupt:
        env.err("Printing collected results and then aborting.")

    env.out(env.fmt(table))
Example #3
0
def cli(env, start, end, sortby):
    """Bandwidth report for every pool/server.

    This reports on the total data transfered for each virtual sever, hardware
    server and bandwidth pool.
    """

    env.err('Generating bandwidth report for %s to %s' % (start, end))

    table = formatting.Table([
        'type',
        'name',
        'public_in',
        'public_out',
        'private_in',
        'private_out',
        'pool',
    ])
    table.sortby = sortby

    def f_type(key, results):
        "Filter metric data by type"
        return (result['counter'] for result in results
                if result['type'] == key)

    try:
        for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
                                    _get_virtual_bandwidth(env, start, end),
                                    _get_hardware_bandwidth(env, start, end)):
            pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
            pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
            pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
            pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
            table.add_row([
                item['type'],
                item['name'],
                formatting.b_to_gb(pub_in),
                formatting.b_to_gb(pub_out),
                formatting.b_to_gb(pri_in),
                formatting.b_to_gb(pri_out),
                item.get('pool') or formatting.blank(),
            ])
    except KeyboardInterrupt:
        env.err("Printing collected results and then aborting.")

    env.out(env.fmt(table))
Example #4
0
def cli(env, identifier):
    """Get details for an image."""

    image_mgr = SoftLayer.ImageManager(env.client)
    image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image')

    image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK)
    disk_space = 0
    datacenters = []
    for child in image.get('children'):
        disk_space = int(child.get('blockDevicesDiskSpaceTotal', 0))
        if child.get('datacenter'):
            datacenters.append(utils.lookup(child, 'datacenter', 'name'))

    table = formatting.KeyValueTable(['name', 'value'])
    table.align['name'] = 'r'
    table.align['value'] = 'l'

    table.add_row(['id', image['id']])
    table.add_row([
        'global_identifier',
        image.get('globalIdentifier', formatting.blank())
    ])
    table.add_row(['name', image['name'].strip()])
    table.add_row([
        'status',
        formatting.FormattedItem(
            utils.lookup(image, 'status', 'keyname'),
            utils.lookup(image, 'status', 'name'),
        )
    ])
    table.add_row([
        'active_transaction',
        formatting.transaction_status(image.get('transaction')),
    ])
    table.add_row(['account', image.get('accountId', formatting.blank())])
    table.add_row([
        'visibility', image_mod.PUBLIC_TYPE
        if image['publicFlag'] else image_mod.PRIVATE_TYPE
    ])
    table.add_row([
        'type',
        formatting.FormattedItem(
            utils.lookup(image, 'imageType', 'keyName'),
            utils.lookup(image, 'imageType', 'name'),
        )
    ])
    table.add_row(['flex', image.get('flexImageFlag')])
    table.add_row(['note', image.get('note')])
    table.add_row(['created', image.get('createDate')])
    table.add_row(['disk_space', formatting.b_to_gb(disk_space)])
    table.add_row([
        'datacenters',
        formatting.listing(sorted(datacenters), separator=',')
    ])

    env.fout(table)
Example #5
0
def cli(env, identifier):
    """Get details for an image."""

    image_mgr = SoftLayer.ImageManager(env.client)
    image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image')
    image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK)

    children_images = image.get('children')
    total_size = utils.lookup(image, 'firstChild',
                              'blockDevicesDiskSpaceTotal') or 0

    table = formatting.KeyValueTable(['name', 'value'])
    table.align['name'] = 'r'
    table.align['value'] = 'l'

    table.add_row(['id', image['id']])
    table.add_row([
        'global_identifier',
        image.get('globalIdentifier', formatting.blank())
    ])
    table.add_row(['name', image['name'].strip()])
    table.add_row([
        'status',
        formatting.FormattedItem(
            utils.lookup(image, 'status', 'keyname'),
            utils.lookup(image, 'status', 'name'),
        )
    ])

    table.add_row([
        'active_transaction',
        formatting.listing(_get_transaction_groups(children_images),
                           separator=','),
    ])
    table.add_row(['account', image.get('accountId', formatting.blank())])
    table.add_row([
        'visibility', image_mod.PUBLIC_TYPE
        if image['publicFlag'] else image_mod.PRIVATE_TYPE
    ])
    table.add_row([
        'type',
        formatting.FormattedItem(
            utils.lookup(image, 'imageType', 'keyName'),
            utils.lookup(image, 'imageType', 'name'),
        )
    ])
    table.add_row(['flex', image.get('flexImageFlag')])
    table.add_row(['note', image.get('note')])
    table.add_row(['created', image.get('createDate')])
    table.add_row(['total_size', formatting.b_to_gb(total_size)])
    table.add_row(['datacenters', _get_datacenter_table(children_images)])

    env.fout(table)
Example #6
0
def _get_datacenter_table(children_images):
    """Returns image details as datacenter, size, and transaction within a formatting table.

      :param children_images: A list of images.
      """
    table_datacenter = formatting.Table(['DC', 'size', 'transaction'])
    for child in children_images:
        table_datacenter.add_row([
            utils.lookup(child, 'datacenter', 'name'),
            formatting.b_to_gb(child.get('blockDevicesDiskSpaceTotal', 0)),
            formatting.transaction_status(child.get('transaction'))
        ])

    return table_datacenter
Example #7
0
def cli(env, identifier):
    """Get details for an image."""

    image_mgr = SoftLayer.ImageManager(env.client)
    image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image')

    image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK)
    disk_space = 0
    datacenters = []
    for child in image.get('children'):
        disk_space = int(child.get('blockDevicesDiskSpaceTotal', 0))
        if child.get('datacenter'):
            datacenters.append(utils.lookup(child, 'datacenter', 'name'))

    table = formatting.KeyValueTable(['name', 'value'])
    table.align['name'] = 'r'
    table.align['value'] = 'l'

    table.add_row(['id', image['id']])
    table.add_row(['global_identifier',
                   image.get('globalIdentifier', formatting.blank())])
    table.add_row(['name', image['name'].strip()])
    table.add_row(['status', formatting.FormattedItem(
        utils.lookup(image, 'status', 'keyname'),
        utils.lookup(image, 'status', 'name'),
    )])
    table.add_row([
        'active_transaction',
        formatting.transaction_status(image.get('transaction')),
    ])
    table.add_row(['account', image.get('accountId', formatting.blank())])
    table.add_row(['visibility',
                   image_mod.PUBLIC_TYPE if image['publicFlag']
                   else image_mod.PRIVATE_TYPE])
    table.add_row(['type',
                   formatting.FormattedItem(
                       utils.lookup(image, 'imageType', 'keyName'),
                       utils.lookup(image, 'imageType', 'name'),
                   )])
    table.add_row(['flex', image.get('flexImageFlag')])
    table.add_row(['note', image.get('note')])
    table.add_row(['created', image.get('createDate')])
    table.add_row(['disk_space', formatting.b_to_gb(disk_space)])
    table.add_row(['datacenters', formatting.listing(sorted(datacenters),
                                                     separator=',')])

    env.fout(table)
Example #8
0
    def execute(self, args):
        image_mgr = SoftLayer.ImageManager(self.client)
        image_id = helpers.resolve_id(image_mgr.resolve_ids,
                                      args.get('<identifier>'),
                                      'image')

        image = image_mgr.get_image(image_id, mask=DETAIL_MASK)
        disk_space = 0
        datacenters = []
        for child in image.get('children'):
            disk_space = int(child.get('blockDevicesDiskSpaceTotal', 0))
            if child.get('datacenter'):
                datacenters.append(utils.lookup(child, 'datacenter', 'name'))

        table = formatting.KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        table.add_row(['id', image['id']])
        table.add_row(['global_identifier',
                       image.get('globalIdentifier', formatting.blank())])
        table.add_row(['name', image['name'].strip()])
        table.add_row(['status', formatting.FormattedItem(
            utils.lookup(image, 'status', 'keyname'),
            utils.lookup(image, 'status', 'name'),
        )])
        table.add_row(['account', image.get('accountId', formatting.blank())])
        table.add_row(['visibility',
                       PUBLIC_TYPE if image['publicFlag'] else PRIVATE_TYPE])
        table.add_row(['type',
                       formatting.FormattedItem(
                           utils.lookup(image, 'imageType', 'keyName'),
                           utils.lookup(image, 'imageType', 'name'),
                       )])
        table.add_row(['flex', image.get('flexImageFlag')])
        table.add_row(['note', image.get('note')])
        table.add_row(['created', image.get('createDate')])
        table.add_row(['disk_space', formatting.b_to_gb(disk_space)])
        table.add_row(['datacenters', formatting.listing(sorted(datacenters),
                                                         separator=',')])

        return table