|
| 1 | +"""User grant access to devices.""" |
| 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 | + |
| 10 | + |
| 11 | +@click.command(cls=SLCommand, ) |
| 12 | +@click.argument('identifier') |
| 13 | +@click.option('--hardware', help="Hardware ID") |
| 14 | +@click.option('--virtual', help="Virtual Guest ID") |
| 15 | +@click.option('--dedicated', help="dedicated host ID") |
| 16 | +@environment.pass_env |
| 17 | +def cli(env, identifier, hardware, virtual, dedicated): |
| 18 | + """Grant access from a user to an specific device. |
| 19 | +
|
| 20 | + Example: slcli user grant-access 123456 --hardware 123456789 |
| 21 | + """ |
| 22 | + |
| 23 | + mgr = SoftLayer.UserManager(env.client) |
| 24 | + result = False |
| 25 | + if hardware: |
| 26 | + result = mgr.grant_hardware_access(identifier, hardware) |
| 27 | + if result: |
| 28 | + click.secho("Grant to access to hardware: %s" % hardware, fg='green') |
| 29 | + |
| 30 | + if virtual: |
| 31 | + result = mgr.grant_virtual_access(identifier, virtual) |
| 32 | + if result: |
| 33 | + click.secho("Grant to access to virtual guest: %s" % virtual, fg='green') |
| 34 | + |
| 35 | + if dedicated: |
| 36 | + result = mgr.grant_dedicated_access(identifier, dedicated) |
| 37 | + if result: |
| 38 | + click.secho("Grant to access to dedicated host: %s" % dedicated, fg='green') |
| 39 | + |
| 40 | + if not result: |
| 41 | + raise SoftLayer.exceptions.SoftLayerError('You need argument a hardware, virtual or dedicated identifier.\n' |
| 42 | + 'E.g slcli user grant-access 123456 --hardware 91803794\n' |
| 43 | + ' slcli user grant-access 123456 --dedicated 91803793\n' |
| 44 | + ' slcli user grant-access 123456 --virtual 91803792') |
0 commit comments