File: detail.py

package info (click to toggle)
python-softlayer 6.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,100 kB
  • sloc: python: 53,771; makefile: 289; sh: 57
file content (42 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Display details for a specified email account."""
# :license: MIT, see LICENSE for more details.

import click

from SoftLayer.CLI.command import SLCommand as SLCommand
from SoftLayer.CLI.email.list import build_statistics_table
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers.email import EmailManager
from SoftLayer import utils


@click.command(cls=SLCommand)
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
    """Display details for a specified email."""

    email_manager = EmailManager(env.client)
    result = email_manager.get_instance(identifier)

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

    table.add_row(['id', result.get('id')])
    table.add_row(['username', result.get('username')])
    table.add_row(['email_address', result.get('emailAddress')])
    table.add_row(['create_date', result.get('createDate')])
    table.add_row(['category_code', utils.lookup(result, 'billingItem', 'categoryCode')])
    table.add_row(['description', utils.lookup(result, 'billingItem', 'description')])
    table.add_row(['type_description', utils.lookup(result, 'type', 'description')])
    table.add_row(['type', utils.lookup(result, 'type', 'keyName')])
    table.add_row(['vendor', utils.lookup(result, 'vendor', 'keyName')])

    statistics = email_manager.get_statistics(identifier)

    for statistic in statistics:
        table.add_row(['statistics', build_statistics_table(statistic)])

    env.fout(table)