Skip to content

Commit 77c5057

Browse files
Merge pull request #1891 from BrianSantivanez/issue1885
Fix `slcli hardware create-credential` command
2 parents cde769b + ba5274d commit 77c5057

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

SoftLayer/CLI/hardware/create_credential.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,37 @@
1414
@click.option('--username', '-U', required=True, help="The username part of the username/password pair")
1515
@click.option('--password', '-P', required=True, help="The password part of the username/password pair.")
1616
@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.")
1818
@environment.pass_env
19-
def cli(env, identifier, username, password, notes, system):
19+
def cli(env, identifier, username, password, notes, software):
2020
"""Create a password for a software component."""
2121

2222
mgr = SoftLayer.HardwareManager(env.client)
2323

24-
software = mgr.get_software_components(identifier)
25-
sw_id = ''
24+
software_components = mgr.get_software_components(identifier)
25+
software_id = ''
2626
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']
3030
except KeyError as ex:
31-
raise exceptions.CLIAbort('System id not found') from ex
31+
raise exceptions.CLIAbort('Software not found') from ex
3232

3333
template = {
3434
"notes": notes,
3535
"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+
}
4639

4740
result = mgr.create_credential(template)
4841

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']])
5346
table.add_row(['Created', result['createDate']])
5447
table.add_row(['Username', result['username']])
5548
table.add_row(['Password', result['password']])
56-
table.add_row(['Notes', result['notes']])
49+
table.add_row(['Notes', result.get('notes') or formatting.blank()])
5750
env.fout(table)

tests/CLI/modules/server_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def test_notification_delete(self):
10551055
def test_create_credential(self):
10561056
result = self.run_command(['hw', 'create-credential', '123456',
10571057
'--username', 'testslcli', '--password', 'test-123456',
1058-
'--notes', 'test slcli', '--system', 'system'])
1058+
'--notes', 'test slcli', '--software', 'system'])
10591059
self.assert_no_fail(result)
10601060

10611061
def test_list_hw_search_noargs(self):

0 commit comments

Comments
 (0)