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