Use get_client from ara.clients.utils to get an API client
This simplifies the code in ara plugins and leaves the logic of client selection to ara.clients. Change-Id: I707efa35507ae9f292d21816c0606ee541df9f6c Depends-On: https://review.openstack.org/#/c/631828/
This commit is contained in:
parent
49ce188ab8
commit
19140f878a
|
@ -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
|
||||
|
||||
# To retrieve Ansible CLI options
|
||||
try:
|
||||
|
@ -104,6 +103,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
|
||||
|
@ -123,15 +125,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…
Reference in New Issue