|
10 | 10 | logger = setup_logger(__name__) |
11 | 11 |
|
12 | 12 |
|
13 | | -def set_bmc_password(ip_address, required_password, username="root"): |
14 | | - """Access BMC via redfish and change password from factory default if needed. |
| 13 | +def set_bmc_password(ip_address, new_password, username="root", old_password=None): |
| 14 | + """Access BMC via redfish and change password from old password if needed. |
15 | 15 |
|
16 | | - Check that we can log in using the standard password. |
| 16 | + Old password, if not specified, is the maufacturer's factory default. |
17 | 17 |
|
18 | | - If that doesn't work, try the factory default password, if that succeeds |
19 | | - then we change the BMC password to our standard one. |
| 18 | + Check that we can log in using the standard password. |
20 | 19 |
|
21 | | - Once the password has been changed then we check that it works by logging in |
22 | | - again. |
| 20 | + If that doesn't work, try the old password, if that succeeds then we change |
| 21 | + the BMC password to our standard one. |
23 | 22 |
|
24 | | - Raises an Exception if the password is not confirmed working. |
| 23 | + Once the password has been changed, we check that it works by logging in |
| 24 | + again, otherwise raise an Exception. |
25 | 25 | """ |
26 | | - token, session = _verify_auth(ip_address, username, required_password) |
| 26 | + if not old_password: |
| 27 | + old_password = FACTORY_PASSWORD |
| 28 | + |
| 29 | + token, session = _verify_auth(ip_address, username, new_password) |
27 | 30 | if token: |
28 | 31 | logger.info("Production BMC credentials are working on this BMC.") |
29 | 32 | close_session(ip_address, token, session) |
30 | 33 | return |
31 | 34 |
|
32 | 35 | logger.info( |
33 | 36 | "Production BMC credentials don't work on this BMC. " |
34 | | - "Trying factory default credentials." |
| 37 | + "Trying old / factory default credentials." |
35 | 38 | ) |
36 | | - token, session = _verify_auth(ip_address, username, FACTORY_PASSWORD) |
| 39 | + token, session = _verify_auth(ip_address, username, old_password) |
37 | 40 | if not token: |
38 | 41 | raise Exception( |
39 | 42 | f"Unable to log in to BMC {ip_address} with any known password!" |
40 | 43 | ) |
41 | 44 |
|
42 | 45 | logger.info("Changing BMC password to standard") |
43 | | - _set_bmc_creds(ip_address, token, username, required_password) |
| 46 | + _set_bmc_creds(ip_address, token, username, new_password) |
44 | 47 | logger.info("BMC password has been set.") |
45 | 48 | close_session(ip_address, token, session) |
46 | 49 |
|
47 | | - token = _verify_auth(ip_address, username, required_password) |
| 50 | + token = _verify_auth(ip_address, username, new_password) |
48 | 51 | if token: |
49 | 52 | logger.info("Production BMC credentials are working on this BMC.") |
50 | 53 | close_session(ip_address, token, session) |
|
0 commit comments