|
14 | 14 | @click.option('--username', '-U', required=True, help="The username part of the username/password pair") |
15 | 15 | @click.option('--password', '-P', required=True, help="The password part of the username/password pair.") |
16 | 16 | @click.option('--notes', '-n', help="A note string stored for this username/password pair.") |
17 | | -@click.option('--system', required=True, help="The name of this specific piece of software.") |
| 17 | +@click.option('--software', required=True, help="The name of this specific piece of software.") |
18 | 18 | @environment.pass_env |
19 | | -def cli(env, identifier, username, password, notes, system): |
| 19 | +def cli(env, identifier, username, password, notes, software): |
20 | 20 | """Create a password for a software component.""" |
21 | 21 |
|
22 | 22 | mgr = SoftLayer.HardwareManager(env.client) |
23 | 23 |
|
24 | | - software = mgr.get_software_components(identifier) |
25 | | - sw_id = '' |
| 24 | + software_components = mgr.get_software_components(identifier) |
| 25 | + software_id = '' |
26 | 26 | try: |
27 | | - for sw_instance in software: |
28 | | - if (sw_instance['softwareLicense']['softwareDescription']['name']).lower() == system: |
29 | | - sw_id = sw_instance['id'] |
| 27 | + for software_component in software_components: |
| 28 | + if software_component['softwareLicense']['softwareDescription']['name'].lower() == software.lower(): |
| 29 | + software_id = software_component['id'] |
30 | 30 | except KeyError as ex: |
31 | | - raise exceptions.CLIAbort('System id not found') from ex |
| 31 | + raise exceptions.CLIAbort('Software not found') from ex |
32 | 32 |
|
33 | 33 | template = { |
34 | 34 | "notes": notes, |
35 | 35 | "password": password, |
36 | | - "softwareId": sw_id, |
37 | | - "username": username, |
38 | | - "software": { |
39 | | - "hardwareId": identifier, |
40 | | - "softwareLicense": { |
41 | | - "softwareDescription": { |
42 | | - "name": system |
43 | | - } |
44 | | - } |
45 | | - }} |
| 36 | + "softwareId": software_id, |
| 37 | + "username": username |
| 38 | + } |
46 | 39 |
|
47 | 40 | result = mgr.create_credential(template) |
48 | 41 |
|
49 | | - table = formatting.KeyValueTable(['name', 'value']) |
50 | | - table.align['name'] = 'r' |
51 | | - table.align['value'] = 'l' |
52 | | - table.add_row(['Software Id', result['id']]) |
| 42 | + table = formatting.KeyValueTable(['Name', 'Value']) |
| 43 | + table.align['Name'] = 'r' |
| 44 | + table.align['Value'] = 'l' |
| 45 | + table.add_row(['Software Credential Id', result['id']]) |
53 | 46 | table.add_row(['Created', result['createDate']]) |
54 | 47 | table.add_row(['Username', result['username']]) |
55 | 48 | table.add_row(['Password', result['password']]) |
56 | | - table.add_row(['Notes', result['notes']]) |
| 49 | + table.add_row(['Notes', result.get('notes') or formatting.blank()]) |
57 | 50 | env.fout(table) |
0 commit comments