File: access.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 (25 lines) | stat: -rw-r--r-- 811 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
"""Get user access details a virtual server."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting


@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
    """Get user access details a virtual server."""

    vsi = SoftLayer.VSManager(env.client)
    access_logs = vsi.browser_access_log(identifier)

    table = formatting.KeyValueTable(['Username', 'Source IP', 'Port', 'Date', 'Event', 'Message'])
    for log in access_logs:
        table.add_row([log.get('username'), log.get('sourceIp'), log.get('sourcePort'), log.get('createDate'),
                       log.get('eventType'), log.get('message')])

    env.fout(table)