Skip to content

Commit

Permalink
baremetal: dedicated flags for credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Jan 13, 2024
1 parent bded7b2 commit b25df22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
24 changes: 15 additions & 9 deletions kvirt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ def start_baremetal_hosts(args):
iso_url = overrides.get('iso_url')
baremetal_hosts = [{'url': args.host}] if args.host is not None else overrides.get('baremetal_hosts', [])
bmc_url = overrides.get('bmc_url') or overrides.get('url')
bmc_user = overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
user = args.user or overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
or overrides.get('username') or baseconfig.bmc_user
bmc_password = overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
password = args.password or overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
if not baremetal_hosts:
if bmc_url is not None:
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': bmc_user, 'bmc_password': bmc_password}]
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': user, 'bmc_password': password}]
else:
error("Baremetal hosts need to be defined")
sys.exit(1)
Expand All @@ -169,12 +169,12 @@ def stop_baremetal_hosts(args):
baseconfig = Kbaseconfig(client=args.client, debug=args.debug, offline=True)
baremetal_hosts = [{'url': args.host}] if args.host is not None else overrides.get('baremetal_hosts', [])
bmc_url = overrides.get('bmc_url') or overrides.get('url')
bmc_user = overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
user = args.user or overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
or overrides.get('username') or baseconfig.bmc_user
bmc_password = overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
password = args.password or overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
if not baremetal_hosts:
if bmc_url is not None:
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': bmc_user, 'bmc_password': bmc_password}]
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': user, 'bmc_password': password}]
else:
error("Baremetal hosts need to be defined")
sys.exit(1)
Expand Down Expand Up @@ -3235,12 +3235,12 @@ def info_baremetal_host(args):
baseconfig = Kbaseconfig(client=args.client, debug=args.debug, offline=True)
baremetal_hosts = [{'url': args.host}] if args.host is not None else overrides.get('baremetal_hosts', [])
bmc_url = overrides.get('bmc_url') or overrides.get('url')
bmc_user = overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
user = args.user or overrides.get('bmc_user') or overrides.get('user') or overrides.get('bmc_username')\
or overrides.get('username') or baseconfig.bmc_user
bmc_password = overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
password = args.password or overrides.get('bmc_password') or overrides.get('password') or baseconfig.bmc_password
if not baremetal_hosts:
if bmc_url is not None:
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': bmc_user, 'bmc_password': bmc_password}]
baremetal_hosts = [{'bmc_url': bmc_url, 'bmc_user': user, 'bmc_password': password}]
else:
error("Couldnt figure out baremetal_hosts list")
sys.exit(1)
Expand Down Expand Up @@ -4623,6 +4623,8 @@ def cli():
epilog=baremetalhostinfo_epilog, formatter_class=rawhelp,
aliases=['baremetal-hosts', 'baremetal', 'bm'])
baremetalhostinfo_parser.add_argument('-f', '--full', action='store_true', help='Provide entire output')
baremetalhostinfo_parser.add_argument('-p', '--password', help='Bmc password')
baremetalhostinfo_parser.add_argument('-u', '--user', help='Bmc user')
baremetalhostinfo_parser.add_argument('host', metavar='HOST', nargs='?')
baremetalhostinfo_parser.set_defaults(func=info_baremetal_host)

Expand Down Expand Up @@ -5171,6 +5173,8 @@ def cli():
parents=[parent_parser], epilog=starthosts_epilog,
formatter_class=rawhelp,
aliases=['baremetal-hosts', 'baremetal', 'bm'])
starthosts_parser.add_argument('-p', '--password', help='Bmc password')
starthosts_parser.add_argument('-u', '--user', help='Bmc user')
starthosts_parser.add_argument('host', metavar='HOST', nargs='?')
starthosts_parser.set_defaults(func=start_baremetal_hosts)

Expand Down Expand Up @@ -5203,6 +5207,8 @@ def cli():
parents=[parent_parser], epilog=stophosts_epilog,
formatter_class=rawhelp,
aliases=['baremetal-hosts', 'baremetal', 'bm'])
stophosts_parser.add_argument('-p', '--password', help='Bmc password')
stophosts_parser.add_argument('-u', '--user', help='Bmc user')
stophosts_parser.add_argument('host', metavar='HOST', nargs='?')
stophosts_parser.set_defaults(func=stop_baremetal_hosts)

Expand Down
5 changes: 3 additions & 2 deletions kvirt/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,15 +2167,16 @@ def boot_baremetal_hosts(baremetal_hosts, iso_url, overrides={}, debug=False):
red.reset()
sleep(240)
msg = host['name'] if 'name' in host else f"with url {bmc_url}"
pprint(f"Booting Host {msg} with {index_iso_url}")
if iso_url is not None:
if index_iso_url is not None:
pprint(f"Booting Host {msg} with {index_iso_url}")
try:
red.set_iso(index_iso_url)
except Exception as e:
msg = f"Hit {e} when plugging iso to host {msg}"
error(msg)
return {'result': 'failure', 'reason': msg}
else:
pprint(f"Booting Host {msg}")
red.start()
else:
warning(f"Skipping entry {index} because either bmc_url, bmc_user or bmc_password is not set")
Expand Down
9 changes: 9 additions & 0 deletions kvirt/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@
# Start a single host
$ kcli start baremetal-host -P user=admin -P password=admin 10.10.10.10
# Start a single host with dedicated flags for credentials
$ kcli start baremetal-host -u admin -p admin 10.10.10.10
"""

stophosts = """# Stop bare metal hosts declared in a parameter file
Expand All @@ -507,6 +510,9 @@
# Stop a single host
$ kcli stop baremetal-host -P user=admin -P password=admin 10.10.10.10
# Stop a single host with dedicated flags for credentials
$ kcli stop baremetal-host -u admin -p admin 10.10.10.10
"""

infohosts = """# Report info on Baremetal hosts declared in a parameter file
Expand All @@ -522,6 +528,9 @@
# Report info on a single host
$ kcli info baremetal-host -P user=admin -P password=admin 10.10.10.10
# Report info on a single host with dedicated flags for credentials
$ kcli info baremetal-host -u admin -p admin 10.10.10.10
"""

ocdownload = """# Download 4.13 stable
Expand Down

0 comments on commit b25df22

Please sign in to comment.