File: 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 (48 lines) | stat: -rw-r--r-- 1,460 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
43
44
45
46
47
48
"""List block storage assigned subnets for the given host id."""
# :license: MIT, see LICENSE for more details.

import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers


COLUMNS = [
    'id',
    'networkIdentifier',
    'cidr'
]


@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('access_id', type=int)
@environment.pass_env
def cli(env, access_id):
    """List block storage assigned subnets for the given host id.

    Example::

                slcli block subnets-list 12345678
                ACCESS_ID is the host_id obtained by: softlayer slcli block access-list <volume_id>

    access_id is the host_id obtained by: slcli block access-list <volume_id>
    """

    try:
        block_manager = SoftLayer.BlockStorageManager(env.client)
        resolved_id = helpers.resolve_id(block_manager.resolve_ids, access_id, 'Volume Id')
        subnets = block_manager.get_subnets_in_acl(resolved_id)

        table = formatting.Table(COLUMNS)
        for subnet in subnets:
            row = [f"{subnet['id']}",
                   f"{subnet['networkIdentifier']}",
                   f"{subnet['cidr']}"]
            table.add_row(row)

        env.fout(table)

    except SoftLayer.SoftLayerAPIError as ex:
        message = "Unable to list assigned subnets for access-id: {}.\nReason: {}".format(access_id, ex.faultString)
        click.echo(message)