|
| 1 | +"""User remove access to devices.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +import SoftLayer |
| 7 | +from SoftLayer.CLI import environment |
| 8 | + |
| 9 | + |
| 10 | +@click.command(cls=SoftLayer.CLI.command.SLCommand, ) |
| 11 | +@click.argument('identifier') |
| 12 | +@click.option('--hardware', '-h', |
| 13 | + help="Display hardware this user has access to.") |
| 14 | +@click.option('--virtual', '-v', |
| 15 | + help="Display virtual guests this user has access to.") |
| 16 | +@click.option('--dedicated', '-l', |
| 17 | + help="dedicated host ID ") |
| 18 | +@environment.pass_env |
| 19 | +def cli(env, identifier, hardware, virtual, dedicated): |
| 20 | + """Remove access from a user to an specific device. |
| 21 | +
|
| 22 | + Example: slcli user remove-access 123456 --hardware 123456789 |
| 23 | + """ |
| 24 | + |
| 25 | + mgr = SoftLayer.UserManager(env.client) |
| 26 | + device = '' |
| 27 | + result = False |
| 28 | + if hardware: |
| 29 | + device = hardware |
| 30 | + result = mgr.remove_hardware_access(identifier, hardware) |
| 31 | + |
| 32 | + if virtual: |
| 33 | + device = virtual |
| 34 | + result = mgr.remove_virtual_access(identifier, virtual) |
| 35 | + |
| 36 | + if dedicated: |
| 37 | + device = dedicated |
| 38 | + result = mgr.remove_dedicated_access(identifier, dedicated) |
| 39 | + |
| 40 | + if result: |
| 41 | + click.secho("Remove to access to device: %s" % device, fg='green') |
| 42 | + else: |
| 43 | + raise SoftLayer.exceptions.SoftLayerError('You need argument a hardware, virtual or dedicated identifier.\n' |
| 44 | + 'E.g slcli user 123456 --hardware 91803794\n' |
| 45 | + ' slcli user 123456 --dedicated 91803793\n' |
| 46 | + ' slcli user 123456 --virtual 91803792') |
0 commit comments