Skip to content

Commit 61dfb2d

Browse files
committed
Allow caller to specify current BMC password of baremetal node to enroll
We also get rid of some other unused CLI arguments to reduce confusion
1 parent 21624f8 commit 61dfb2d

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

python/understack-workflows/understack_workflows/bmc_credentials.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,44 @@
1010
logger = setup_logger(__name__)
1111

1212

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.
1515
16-
Check that we can log in using the standard password.
16+
Old password, if not specified, is the maufacturer's factory default.
1717
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.
2019
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.
2322
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.
2525
"""
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)
2730
if token:
2831
logger.info("Production BMC credentials are working on this BMC.")
2932
close_session(ip_address, token, session)
3033
return
3134

3235
logger.info(
3336
"Production BMC credentials don't work on this BMC. "
34-
"Trying factory default credentials."
37+
"Trying old / factory default credentials."
3538
)
36-
token, session = _verify_auth(ip_address, username, FACTORY_PASSWORD)
39+
token, session = _verify_auth(ip_address, username, old_password)
3740
if not token:
3841
raise Exception(
3942
f"Unable to log in to BMC {ip_address} with any known password!"
4043
)
4144

4245
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)
4447
logger.info("BMC password has been set.")
4548
close_session(ip_address, token, session)
4649

47-
token = _verify_auth(ip_address, username, required_password)
50+
token = _verify_auth(ip_address, username, new_password)
4851
if token:
4952
logger.info("Production BMC credentials are working on this BMC.")
5053
close_session(ip_address, token, session)

python/understack-workflows/understack_workflows/main/enroll_server.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def main():
4141
4242
This script has the following order of operations:
4343
44-
- connect to the BMC, trying standard password then factory default
44+
- connect to the BMC using standard password, if that fails then use
45+
password supplied in --old-bmc-password option, or factory default
4546
4647
- ensure standard BMC password is set
4748
@@ -98,8 +99,12 @@ def main():
9899
token = args.nautobot_token or credential("nb-token", "token")
99100
nautobot = pynautobot.api(url, token=token)
100101

101-
bmc = bmc_for_ip_address(bmc_ip_address, password=args.bmc_password)
102-
set_bmc_password(bmc.ip_address, bmc.password)
102+
bmc = bmc_for_ip_address(bmc_ip_address)
103+
set_bmc_password(
104+
ip_address=bmc.ip_address,
105+
new_password=bmc.password,
106+
old_password=args.old_bmc_password,
107+
)
103108

104109
device_info = chassis_info(bmc)
105110
logger.info(f"Discovered {pformat(device_info)}")
@@ -133,12 +138,11 @@ def main():
133138

134139
def argument_parser():
135140
parser = argparse.ArgumentParser(
136-
prog=os.path.basename(__file__), description="Ingest Baremetal"
141+
prog=os.path.basename(__file__), description="Ingest Baremetal Node"
137142
)
138143
parser.add_argument("--bmc-ip-address", type=str, required=True, help="BMC IP")
139-
parser.add_argument("--bmc-password", type=str, required=False, help="BMC Pass")
140144
parser.add_argument(
141-
"--bmc-mac-address", type=str, required=False, help="BMC MAC Addr"
145+
"--old-bmc-password", type=str, required=False, help="Old Password"
142146
)
143147
parser = parser_nautobot_args(parser)
144148
return parser

0 commit comments

Comments
 (0)