Update CLI to read from pvc.conf

This commit is contained in:
Joshua Boniface 2023-12-01 01:53:33 -05:00
parent 7cb9ebae6b
commit 2afd064445
2 changed files with 10 additions and 9 deletions

View File

@ -5960,8 +5960,8 @@ def cli(
"PVC_COLOUR": Force colour on the output even if Click determines it is not a console (e.g. with 'watch')
If a "-c"/"--connection"/"PVC_CONNECTION" is not specified, the CLI will attempt to read a "local" connection
from the API configuration at "/etc/pvc/pvcapid.yaml". If no such configuration is found, the command will
abort with an error. This applies to all commands except those under "connection".
from the API configuration at "/etc/pvc/pvc.conf". If no such configuration is found, the command will abort
with an error. This applies to all commands except those under "connection".
"""
global CLI_CONFIG

View File

@ -40,7 +40,7 @@ import pvc.lib.vm
import pvc.lib.node
DEFAULT_STORE_DATA = {"cfgfile": "/etc/pvc/pvcapid.yaml"}
DEFAULT_STORE_DATA = {"cfgfile": "/etc/pvc/pvc.conf"}
DEFAULT_STORE_FILENAME = "pvc.json"
DEFAULT_API_PREFIX = "/api/v1"
DEFAULT_NODE_HOSTNAME = gethostname().split(".")[0]
@ -88,14 +88,15 @@ def read_config_from_yaml(cfgfile):
try:
with open(cfgfile) as fh:
api_config = yload(fh, Loader=BaseLoader)["pvc"]["api"]
api_config = yload(fh, Loader=BaseLoader)["api"]
host = api_config["listen_address"]
port = api_config["listen_port"]
scheme = "https" if strtobool(api_config["ssl"]["enabled"]) else "http"
host = api_config["listen"]["address"]
port = api_config["listen"]["port"]
scheme = "https" if api_config["ssl"]["enabled"] else "http"
api_key = (
api_config["authentication"]["tokens"][0]["token"]
if strtobool(api_config["authentication"]["enabled"])
api_config["token"][0]["token"]
if api_config["authentication"]["enabled"]
and api_config["authentication"]["source"] == "token"
else None
)
except KeyError: