Merge "Use get_client from ara.clients.utils to get an API client"
This commit is contained in:
commit
f7fa02c915
@ -19,8 +19,7 @@ from ansible import constants as ansible_constants
|
||||
from ansible.playbook.play import Play
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
from ara.clients.http import AraHttpClient
|
||||
from ara.clients.offline import AraOfflineClient
|
||||
from ara.clients import utils as client_utils
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
@ -145,12 +144,10 @@ class ActionModule(ActionBase):
|
||||
# Retrieves the runtime plugin options for the ara_default callback plugin
|
||||
options = ansible_constants.config.get_plugin_options("callback", "ara_default")
|
||||
|
||||
if options["api_client"] == "offline":
|
||||
self.client = AraOfflineClient()
|
||||
elif options["api_client"] == "http":
|
||||
self.client = AraHttpClient(endpoint=options["api_server"], timeout=options["timeout"])
|
||||
else:
|
||||
raise Exception("Unsupported API client: %s. Please use 'offline' or 'http'" % options["api_client"])
|
||||
client = options("api_client")
|
||||
endpoint = options("api_server")
|
||||
timeout = options("api_timeout")
|
||||
self.client = client_utils.get_client(client=client, endpoint=endpoint, timeout=timeout)
|
||||
|
||||
def create_or_update_key(self, playbook, key, value, type):
|
||||
changed = False
|
||||
|
@ -26,8 +26,7 @@ import six
|
||||
from ansible import __version__ as ansible_version
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
from ara.clients.http import AraHttpClient
|
||||
from ara.clients.offline import AraOfflineClient
|
||||
from ara.clients import utils as client_utils
|
||||
|
||||
# Ansible CLI options are now in ansible.context in >= 2.8
|
||||
# https://github.com/ansible/ansible/commit/afdbb0d9d5bebb91f632f0d4a1364de5393ba17a
|
||||
@ -114,6 +113,9 @@ class CallbackModule(CallbackBase):
|
||||
def __init__(self):
|
||||
super(CallbackModule, self).__init__()
|
||||
self.log = logging.getLogger("ara.plugins.callback.default")
|
||||
self.client = None
|
||||
self.ignored_facts = []
|
||||
self.ignored_arguments = []
|
||||
|
||||
self.result = None
|
||||
self.task = None
|
||||
@ -128,15 +130,10 @@ class CallbackModule(CallbackBase):
|
||||
self.ignored_facts = self.get_option("ignored_facts")
|
||||
self.ignored_arguments = self.get_option("ignored_arguments")
|
||||
|
||||
api_client = self.get_option("api_client")
|
||||
if api_client == "offline":
|
||||
self.client = AraOfflineClient()
|
||||
elif api_client == "http":
|
||||
server = self.get_option("api_server")
|
||||
timeout = self.get_option("api_timeout")
|
||||
self.client = AraHttpClient(endpoint=server, timeout=timeout)
|
||||
else:
|
||||
raise Exception("Unsupported API client: %s. Please use 'offline' or 'http'" % api_client)
|
||||
client = self.get_option("api_client")
|
||||
endpoint = self.get_option("api_server")
|
||||
timeout = self.get_option("api_timeout")
|
||||
self.client = client_utils.get_client(client=client, endpoint=endpoint, timeout=timeout)
|
||||
|
||||
def v2_playbook_on_start(self, playbook):
|
||||
self.log.debug("v2_playbook_on_start")
|
||||
|
Loading…
x
Reference in New Issue
Block a user