get_option instead of internal dict (#33191)

* get_option instead of internal dict

* fix slack issue

* not a pugin, revert get_option
This commit is contained in:
Brian Coca 2017-11-28 12:00:22 -05:00 committed by GitHub
parent 9e9f2b9ad5
commit 22d983c5c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 50 additions and 60 deletions

View file

@ -84,6 +84,9 @@ class CallbackBase(AnsiblePlugin):
def set_option(self, k, v):
self._plugin_options[k] = v
def get_option(self, k):
return self._plugin_options[k]
def set_options(self, task_keys=None, var_options=None, direct=None):
''' This is different than the normal plugin method as callbacks get called early and really don't accept keywords.
Also _options was already taken for CLI args and callbacks use _plugin_options instead.

View file

@ -232,39 +232,26 @@ class CallbackModule(CallbackBase):
self.le_jobid = str(uuid.uuid4())
# FIXME: remove when done testing
# initialize configurable
self.api_url = 'data.logentries.com'
self.api_port = 80
self.api_tls_port = 443
self.use_tls = False
self.flatten = False
self.token = None
# FIXME: make configurable, move to options
self.timeout = 10
# FIXME: remove testing
# self.set_options({'api': 'data.logentries.com', 'port': 80,
# 'tls_port': 10000, 'use_tls': True, 'flatten': False, 'token': 'ae693734-4c5b-4a44-8814-1d2feb5c8241'})
def set_options(self, task_keys=None, var_options=None, direct=None):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
# get options
try:
self.api_url = self._plugin_options['api']
self.api_port = self._plugin_options['port']
self.api_tls_port = self._plugin_options['tls_port']
self.use_tls = self._plugin_options['use_tls']
self.flatten = self._plugin_options['flatten']
self.api_url = self.get_option('api')
self.api_port = self.get_option('port')
self.api_tls_port = self.get_option('tls_port')
self.use_tls = self.get_option('use_tls')
self.flatten = self.get_option('flatten')
except KeyError as e:
self._display.warning("Missing option for Logentries callback plugin: %s" % to_native(e))
self.disabled = True
try:
self.token = self._plugin_options['token']
self.token = self.get_option('token')
except KeyError as e:
self._display.warning('Logentries token was not provided, this is required for this callback to operate, disabling')
self.disabled = True

View file

@ -123,7 +123,7 @@ class CallbackModule(CallbackBase):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.sort_order = self._plugin_options['sort_order']
self.sort_order = self.get_option('sort_order')
if self.sort_order is not None:
if self.sort_order == 'ascending':
self.sort_order = False
@ -132,7 +132,7 @@ class CallbackModule(CallbackBase):
elif self.sort_order == 'none':
self.sort_order = None
self.task_output_limit = self._plugin_options['output_limit']
self.task_output_limit = self.get_option('output_limit')
if self.task_output_limit is not None:
if self.task_output_limit == 'all':
self.task_output_limit = None

View file

@ -93,7 +93,7 @@ class CallbackModule(CallbackBase):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
global DONT_COLORIZE
DONT_COLORIZE = self._plugin_options['nocolor']
DONT_COLORIZE = self.get_option('nocolor')
def _print_task(self, task_name=None):
if task_name is None:

View file

@ -93,9 +93,9 @@ class CallbackModule(CallbackBase):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.webhook_url = self._plugin_options['webhook_url']
self.channel = self._plugin_options['channel']
self.username = self._plugin_options['username']
self.webhook_url = self.get_option('webhook_url')
self.channel = self.get_option('channel')
self.username = self.get_option('username')
self.show_invocation = (self._display.verbosity > 1)
if self.webhook_url is None:
@ -133,12 +133,12 @@ class CallbackModule(CallbackBase):
]
invocation_items = []
if self._plugin_options and self.show_invocation:
tags = self._plugin_options.tags
skip_tags = self._plugin_options.skip_tags
extra_vars = self._plugin_options.extra_vars
subset = self._plugin_options.subset
tags = self.get_option('tags')
skip_tags = self.get_option('skip_tags')
extra_vars = self.get_option('extra_vars')
subset = self.get_option('subset')
inventory = os.path.basename(
os.path.realpath(self._plugin_options.inventory)
os.path.realpath(self.get_option('inventory'))
)
invocation_items.append('Inventory: %s' % inventory)
@ -152,7 +152,7 @@ class CallbackModule(CallbackBase):
invocation_items.append('Extra Vars: %s' %
' '.join(extra_vars))
title.append('by *%s*' % self._plugin_options.remote_user)
title.append('by *%s*' % self.get_options('remote_user'))
title.append('\n\n*%s*' % self.playbook_name)
msg_items = [' '.join(title)]