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 43 44 45 46 47 48
|
"""List package categories."""
# :license: MIT, see LICENSE for more details.
import click
from SoftLayer.CLI.command import SLCommand as SLCommand
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import ordering
COLUMNS = ['name', 'categoryCode', 'isRequired']
@click.command(cls=SLCommand)
@click.argument('package_keyname')
@click.option('--required',
is_flag=True,
help="List only the required categories for the package")
@environment.pass_env
def cli(env, package_keyname, required):
"""List the categories of a package.
::
# List the categories of Bare Metal servers
slcli order category-list BARE_METAL_SERVER
# List the required categories for Bare Metal servers
slcli order category-list BARE_METAL_SERVER --required
"""
client = env.client
manager = ordering.OrderingManager(client)
table = formatting.Table(COLUMNS)
categories = manager.list_categories(package_keyname)
if required:
categories = [cat for cat in categories if cat['isRequired']]
for cat in categories:
table.add_row([
cat['itemCategory']['name'],
cat['itemCategory']['categoryCode'],
'Y' if cat['isRequired'] else 'N'
])
env.fout(table)
|