Improved handling of partially missing parameters
This commit is contained in:
parent
b23d4751e1
commit
93d8723b98
28
proxmox.py
28
proxmox.py
|
@ -94,21 +94,25 @@ class ProxmoxAPI(object):
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
os.path.splitext(os.path.basename(__file__))[0]+".json"
|
os.path.splitext(os.path.basename(__file__))[0]+".json"
|
||||||
)
|
)
|
||||||
|
if not options.url or not options.username or not options.password:
|
||||||
if os.path.isfile(config_path):
|
if os.path.isfile(config_path):
|
||||||
with open(config_path, "r") as config_file:
|
with open(config_path, "r") as config_file:
|
||||||
config_data = json.load(config_file)
|
config_data = json.load(config_file)
|
||||||
try:
|
if not options.url:
|
||||||
options.url = config_data["url"]
|
try:
|
||||||
except KeyError:
|
options.url = config_data["url"]
|
||||||
options.url = None
|
except KeyError:
|
||||||
try:
|
options.url = None
|
||||||
options.username = config_data["username"]
|
if not options.username:
|
||||||
except KeyError:
|
try:
|
||||||
options.username = None
|
options.username = config_data["username"]
|
||||||
try:
|
except KeyError:
|
||||||
options.password = config_data["password"]
|
options.username = None
|
||||||
except KeyError:
|
if not options.password:
|
||||||
options.password = None
|
try:
|
||||||
|
options.password = config_data["password"]
|
||||||
|
except KeyError:
|
||||||
|
options.password = None
|
||||||
|
|
||||||
if not options.url:
|
if not options.url:
|
||||||
raise Exception('Missing mandatory parameter --url (or PROXMOX_URL or "url" key in config file).')
|
raise Exception('Missing mandatory parameter --url (or PROXMOX_URL or "url" key in config file).')
|
||||||
|
|
Reference in New Issue