salt-ext-modules-vmware
salt-ext-modules-vmware copied to clipboard
Profile behavior behaves badly when unsuccessful
See #351 for more info, but generally speaking there are two behaviors when using profiles that are just terrible.
<snip>
File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 45, in get_config
credentials = conf[profile]
KeyError: 'fnord'
A huge stack trace appears when doing something like salt-call vmware_vm.list profile=fnord
and the profile doesn't exist.
We could pretty easily catch a KeyError here and then look for profiles that might match, and provide a useful error/exit like "Profile 'fnord' does not exist. Perhaps you meant X?"
Alternatively, if you don't have any config data in the base and only have profiles, and do not provide a profile, you get this:
<snip>
File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 134, in get_service_instance
config = get_config(config=config, profile=profile, esxi_host=esxi_host)
File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 60, in get_config
raise ValueError("Cannot create service instance, VMware credentials incomplete.")
ValueError: Cannot create service instance, VMware credentials incomplete.
Also super useless.
Basically what we should do in this case is check if there's a host/user/pass, and if any of those things are missing then we should provide a useful message such as:
No credentials found in the base profile, and no profiles found.
Or
No credentials found in the base profile, but profiles <a, b, c> exist. Are you missing
profile=a
?
Something to that effect.