File: package_list.py

package info (click to toggle)
python-softlayer 6.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,508 kB
  • sloc: python: 57,195; makefile: 133; xml: 97; sh: 59
file content (54 lines) | stat: -rw-r--r-- 1,584 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
"""List packages."""
# :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 = ['id',
           'name',
           'keyName',
           'type']


@click.command(cls=SLCommand)
@click.option('--keyword', help="A word (or string) used to filter package names.")
@click.option('--package_type', help="The keyname for the type of package. BARE_METAL_CPU for example")
@environment.pass_env
def cli(env, keyword, package_type):
    """List packages that can be ordered via the placeOrder API.


    ::

        # List out all packages for ordering
        slcli order package-list

        # List out all packages with "server" in the name
        slcli order package-list --keyword server

        # Select only specifict package types
        slcli order package-list --package_type BARE_METAL_CPU
    """
    manager = ordering.OrderingManager(env.client)
    table = formatting.Table(COLUMNS)

    _filter = {'type': {'keyName': {'operation': '!= BLUEMIX_SERVICE'}}}
    if keyword:
        _filter['name'] = {'operation': '*= %s' % keyword}
    if package_type:
        _filter['type'] = {'keyName': {'operation': package_type}}

    packages = manager.list_packages(filter=_filter)

    for package in packages:
        table.add_row([
            package['id'],
            package['name'],
            package['keyName'],
            package['type']['keyName']
        ])
    env.fout(table)