|
| 1 | +"""Grants a user access to a given device""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | +import SoftLayer |
| 6 | + |
| 7 | +from SoftLayer.CLI.command import SLCommand as SLCommand |
| 8 | +from SoftLayer.CLI import environment |
| 9 | +from SoftLayer.CLI import exceptions |
| 10 | + |
| 11 | + |
| 12 | +@click.command(cls=SLCommand, ) |
| 13 | +@click.argument('identifier') |
| 14 | +@click.option('--hardware', help="Hardware ID") |
| 15 | +@click.option('--virtual', help="Virtual Guest ID") |
| 16 | +@click.option('--dedicated', help="dedicated host ID") |
| 17 | +@environment.pass_env |
| 18 | +def cli(env, identifier, hardware, virtual, dedicated): |
| 19 | + """Grants a user access to a given device. |
| 20 | +
|
| 21 | + Example: slcli user grant-access 123456 --hardware 123456789 |
| 22 | + """ |
| 23 | + |
| 24 | + mgr = SoftLayer.UserManager(env.client) |
| 25 | + result = False |
| 26 | + if hardware: |
| 27 | + result = mgr.grant_hardware_access(identifier, hardware) |
| 28 | + if result: |
| 29 | + click.secho(f"User {identifier} has been given access to hardware {hardware}", fg='green') |
| 30 | + |
| 31 | + if virtual: |
| 32 | + result = mgr.grant_virtual_access(identifier, virtual) |
| 33 | + if result: |
| 34 | + click.secho(f"User {identifier} has been given access to hardware {virtual}", fg='green') |
| 35 | + |
| 36 | + if dedicated: |
| 37 | + result = mgr.grant_dedicated_access(identifier, dedicated) |
| 38 | + if result: |
| 39 | + click.secho(f"User {identifier} has been given access to hardware {dedicated}", fg='green') |
| 40 | + |
| 41 | + if not result: |
| 42 | + raise exceptions.CLIAbort('A device option is required.\n' |
| 43 | + 'E.g slcli user grant-access 123456 --hardware 91803794\n' |
| 44 | + ' slcli user grant-access 123456 --dedicated 91803793\n' |
| 45 | + ' slcli user grant-access 123456 --virtual 91803792') |
0 commit comments