Juan Hernandez has uploaded a new change for review. Change subject: cli: Try options from command line and settings ......................................................................
cli: Try options from command line and settings Currently the connect command doesn't try to get the options from the command line, only from the settings. This is a regression introduced by a previous patch that removed the dependency on the "optparse" module. This patch fixes that issue. Change-Id: I497a9269390fa62406099854cbebf273664c04a6 Bug-Url: https://bugzilla.redhat.com/1135544 Related: https://bugzilla.redhat.com/1135550 Related: https://gerrit.ovirt.org/36257 Signed-off-by: Juan Hernandez <[email protected]> --- M src/ovirtcli/command/connect.py 1 file changed, 42 insertions(+), 28 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/49/40449/1 diff --git a/src/ovirtcli/command/connect.py b/src/ovirtcli/command/connect.py index b8190a0..db89cd8 100644 --- a/src/ovirtcli/command/connect.py +++ b/src/ovirtcli/command/connect.py @@ -52,7 +52,7 @@ == Arguments == * url - The URL to connect to (http[s]://server[:port]/ovirt-engine/api). - * [username] - The user to connect as. (user@domain). + * [user] - The user to connect as. (user@domain). * [password] - The password to use. * [key-file] - The client PEM key file to use. * [cert-file] - The client PEM certificate file to use. @@ -66,24 +66,20 @@ """ def execute(self): - args = self.arguments - settings = self.context.settings - context = self.context - MIN_FORCE_CREDENTIALS_CHECK_VERSION = ('00000003', '00000001', '00000000', '00000004') - key_file = self.xNoneType(settings.get('ovirt-shell:key_file')) - cert_file = self.xNoneType(settings.get('ovirt-shell:cert_file')) - ca_file = self.xNoneType(settings.get('ovirt-shell:ca_file')) - port = settings.get('ovirt-shell:port') - timeout = settings.get('ovirt-shell:timeout') - session_timeout = settings.get('ovirt-shell:session_timeout') - renew_session = settings.get('ovirt-shell:renew_session') - debug = settings.get('cli:debug') - insecure = settings.get('ovirt-shell:insecure') - dont_validate_cert_chain = settings.get('ovirt-shell:dont_validate_cert_chain') - filter_ = settings.get('ovirt-shell:filter') - kerberos = settings.get('ovirt-shell:kerberos') + key_file = self.__option_or_setting('ke-file', 'ovirt-shell:key_file') + cert_file = self.__option_or_setting('cert-file', 'ovirt-shell:cert_file') + ca_file = self.__option_or_setting('ca-file', 'ovirt-shell:ca_file') + port = self.__option_or_setting('port', 'ovirt-shell:port') + timeout = self.__option_or_setting('timeout', 'ovirt-shell:timeout') + session_timeout = self.__option_or_setting('session-timeout', 'ovirt-shell:session_timeout') + renew_session = self.__option_or_setting(None, 'ovirt-shell:renew_session') + debug = self.__option_or_setting(None, 'cli:debug') + insecure = self.__option_or_setting('insecure', 'ovirt-shell:insecure') + dont_validate_cert_chain = self.__option_or_setting(None, 'ovirt-shell:dont_validate_cert_chain') + filter_ = self.__option_or_setting('filter', 'ovirt-shell:filter') + kerberos = self.__option_or_setting('kerberos', 'ovirt-shell:kerberos') if self.context.connection is not None and \ self.context.status != self.context.COMMUNICATION_ERROR and \ @@ -93,11 +89,11 @@ Messages.Warning.ALREADY_CONNECTED ) return - if len(args) == 3: - url, username, password = args + if len(self.arguments) == 3: + url, username, password = self.arguments else: - url = settings.get('ovirt-shell:url') - if not url: + url = self.__option_or_setting('url', 'ovirt-shell:url') + if url is None: self.error( Messages.Error.MISSING_CONFIGURATION_VARIABLE % 'url' ) @@ -105,13 +101,13 @@ username = None password = None else: - username = settings.get('ovirt-shell:username') - if not username: + username = self.__option_or_setting('user', 'ovirt-shell:username') + if username is None: self.error( Messages.Error.MISSING_CONFIGURATION_VARIABLE % 'username' ) - password = settings.get('ovirt-shell:password') - if not password: + password = self.__option_or_setting('password', 'ovirt-shell:password') + if password is None: self.error( Messages.Error.MISSING_CONFIGURATION_VARIABLE % 'password' ) @@ -145,7 +141,7 @@ url=url ) - if context.sdk_version < MIN_FORCE_CREDENTIALS_CHECK_VERSION: + if self.context.sdk_version < MIN_FORCE_CREDENTIALS_CHECK_VERSION: self.__test_connectivity() StateMachine.connected() # @UndefinedVariable @@ -252,5 +248,23 @@ finally: self.context.connection = None - def xNoneType(self, s): - return None if s == 'None' else s + def __option_or_setting(self, option_key, setting_key): + # Try to find a matching option: + if option_key is not None: + option_key = "--" + option_key + if option_key in self.options: + value = self.options[option_key] + if value == '' or value == 'None': + value = None + return value + + # Then try to find a matching setting: + if setting_key is not None: + if setting_key in self.context.settings: + value = self.context.settings[setting_key] + if value == '' or value == 'None': + value = None + return value + + # No luck: + return None -- To view, visit https://gerrit.ovirt.org/40449 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I497a9269390fa62406099854cbebf273664c04a6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> Gerrit-Reviewer: Ravi Nori <[email protected]> Gerrit-Reviewer: [email protected] _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
