|
5 | 5 |
|
6 | 6 | import SoftLayer |
7 | 7 | from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import exceptions |
8 | 9 | from SoftLayer.CLI import formatting |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @click.command(cls=SoftLayer.CLI.command.SLCommand, ) |
12 | 13 | @click.argument('identifier') |
13 | | -@click.option('--username', '-U', help="The username part of the username/password pair") |
14 | | -@click.option('--password', '-P', help="The password part of the username/password pair.") |
| 14 | +@click.option('--username', '-U', required=True, help="The username part of the username/password pair") |
| 15 | +@click.option('--password', '-P', required=True, help="The password part of the username/password pair.") |
15 | 16 | @click.option('--notes', '-n', help="A note string stored for this username/password pair.") |
16 | | -@click.option('--system', help="The name of this specific piece of software.") |
| 17 | +@click.option('--system', required=True, help="The name of this specific piece of software.") |
17 | 18 | @environment.pass_env |
18 | 19 | def cli(env, identifier, username, password, notes, system): |
19 | 20 | """Create a password for a software component.""" |
20 | 21 |
|
21 | 22 | mgr = SoftLayer.HardwareManager(env.client) |
22 | 23 |
|
23 | 24 | software = mgr.get_software_components(identifier) |
24 | | - sw_id = None |
25 | | - for sw_instance in software: |
26 | | - if (sw_instance['softwareLicense']['softwareDescription']['name']).lower() == system: |
27 | | - sw_id = sw_instance['id'] |
28 | | - break |
29 | | - elif system: |
30 | | - if (sw_instance['softwareLicense']['softwareDescription']['name']) == 'Passmark Suite': |
| 25 | + sw_id = '' |
| 26 | + try: |
| 27 | + for sw_instance in software: |
| 28 | + if (sw_instance['softwareLicense']['softwareDescription']['name']).lower() == system: |
31 | 29 | sw_id = sw_instance['id'] |
| 30 | + except KeyError as ex: |
| 31 | + raise exceptions.CLIAbort('System id not found') from ex |
32 | 32 |
|
33 | 33 | template = { |
34 | 34 | "notes": notes, |
|
0 commit comments