Update cliconf get_config api (#43472)

*  Change `filter` parameter to `flag` to be in sync
   with original naming convention
pull/43483/head
Ganesh Nalawade 6 years ago committed by GitHub
parent c8fcbdef71
commit 857200fa7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -136,7 +136,7 @@ class Cli:
except KeyError: except KeyError:
conn = self._get_connection() conn = self._get_connection()
try: try:
out = conn.get_config(filter=flags) out = conn.get_config(flags=flags)
except ConnectionError as exc: except ConnectionError as exc:
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))

@ -111,7 +111,7 @@ def get_config(module, flags=None):
except KeyError: except KeyError:
connection = get_connection(module) connection = get_connection(module)
try: try:
out = connection.get_config(filter=flags) out = connection.get_config(flags=flags)
except ConnectionError as exc: except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
cfg = to_text(out, errors='surrogate_then_replace').strip() cfg = to_text(out, errors='surrogate_then_replace').strip()

@ -140,7 +140,7 @@ class Cli:
except KeyError: except KeyError:
connection = self._get_connection() connection = self._get_connection()
try: try:
out = connection.get_config(filter=flags) out = connection.get_config(flags=flags)
except ConnectionError as exc: except ConnectionError as exc:
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))

@ -165,7 +165,7 @@ class CliconfBase(AnsiblePlugin):
self.response_logging = False self.response_logging = False
@abstractmethod @abstractmethod
def get_config(self, source='running', filter=None, format=None): def get_config(self, source='running', flag=None, format=None):
"""Retrieves the specified configuration from the device """Retrieves the specified configuration from the device
This method will retrieve the configuration specified by source and This method will retrieve the configuration specified by source and
@ -175,7 +175,7 @@ class CliconfBase(AnsiblePlugin):
:param source: The configuration source to return from the device. :param source: The configuration source to return from the device.
This argument accepts either `running` or `startup` as valid values. This argument accepts either `running` or `startup` as valid values.
:param filter: For devices that support configuration filtering, this :param flag: For devices that support configuration filtering, this
keyword argument is used to filter the returned configuration. keyword argument is used to filter the returned configuration.
The use of this keyword argument is device dependent adn will be The use of this keyword argument is device dependent adn will be
silently ignored on devices that do not support it. silently ignored on devices that do not support it.

@ -75,7 +75,7 @@ class Cliconf(CliconfBase):
return resp return resp
@enable_mode @enable_mode
def get_config(self, source='running', format='text', filter=None): def get_config(self, source='running', format='text', flag=None):
options_values = self.get_option_values() options_values = self.get_option_values()
if format not in options_values['format']: if format not in options_values['format']:
raise ValueError("'format' value %s is invalid. Valid values are %s" % (format, ','.join(options_values['format']))) raise ValueError("'format' value %s is invalid. Valid values are %s" % (format, ','.join(options_values['format'])))
@ -88,7 +88,7 @@ class Cliconf(CliconfBase):
if format and format is not 'text': if format and format is not 'text':
cmd += '| %s ' % format cmd += '| %s ' % format
cmd += ' '.join(to_list(filter)) cmd += ' '.join(to_list(flag))
cmd = cmd.strip() cmd = cmd.strip()
return self.send_command(cmd) return self.send_command(cmd)

@ -37,21 +37,21 @@ from ansible.plugins.cliconf import CliconfBase, enable_mode
class Cliconf(CliconfBase): class Cliconf(CliconfBase):
@enable_mode @enable_mode
def get_config(self, source='running', filter=None, format=None): def get_config(self, source='running', flag=None, format=None):
if source not in ('running', 'startup'): if source not in ('running', 'startup'):
return self.invalid_params("fetching configuration from %s is not supported" % source) return self.invalid_params("fetching configuration from %s is not supported" % source)
if format: if format:
raise ValueError("'format' value %s is not supported for get_config" % format) raise ValueError("'format' value %s is not supported for get_config" % format)
if not filter: if not flag:
filter = [] flag = []
if source == 'running': if source == 'running':
cmd = 'show running-config ' cmd = 'show running-config '
else: else:
cmd = 'show startup-config ' cmd = 'show startup-config '
cmd += ' '.join(to_list(filter)) cmd += ' '.join(to_list(flag))
cmd = cmd.strip() cmd = cmd.strip()
return self.send_command(cmd) return self.send_command(cmd)

@ -131,7 +131,7 @@ class Cliconf(CliconfBase):
diff['config_diff'] = dumps(configdiffobjs, 'commands') if configdiffobjs else '' diff['config_diff'] = dumps(configdiffobjs, 'commands') if configdiffobjs else ''
return diff return diff
def get_config(self, source='running', format='text', filter=None): def get_config(self, source='running', format='text', flag=None):
options_values = self.get_option_values() options_values = self.get_option_values()
if format not in options_values['format']: if format not in options_values['format']:
raise ValueError("'format' value %s is invalid. Valid values are %s" % (format, ','.join(options_values['format']))) raise ValueError("'format' value %s is invalid. Valid values are %s" % (format, ','.join(options_values['format'])))
@ -144,8 +144,8 @@ class Cliconf(CliconfBase):
if format and format is not 'text': if format and format is not 'text':
cmd += '| %s ' % format cmd += '| %s ' % format
if filter: if flag:
cmd += ' '.join(to_list(filter)) cmd += ' '.join(to_list(flag))
cmd = cmd.strip() cmd = cmd.strip()
return self.send_command(cmd) return self.send_command(cmd)

@ -54,7 +54,7 @@ class Cliconf(CliconfBase):
return device_info return device_info
def get_config(self, filter=None, format=None): def get_config(self, flag=None, format=None):
if format: if format:
option_values = self.get_option_values() option_values = self.get_option_values()
if format not in option_values['format']: if format not in option_values['format']:

Loading…
Cancel
Save