2014-10-06 21:27:41 +02:00
|
|
|
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
|
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> and others
|
2017-01-27 20:53:02 +01:00
|
|
|
# (c) 2017, Toshio Kuratomi <tkuratomi@ansible.com>
|
2014-10-02 19:07:05 +02:00
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-10-16 01:22:54 +02:00
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-08-15 22:38:59 +02:00
|
|
|
from abc import ABCMeta
|
2015-05-02 08:34:03 +02:00
|
|
|
|
2014-10-06 21:27:41 +02:00
|
|
|
from ansible import constants as C
|
2017-09-10 23:53:49 +02:00
|
|
|
from ansible.module_utils.six import with_metaclass, string_types
|
2014-10-06 21:27:41 +02:00
|
|
|
|
2015-07-23 16:24:50 +02:00
|
|
|
try:
|
|
|
|
from __main__ import display
|
|
|
|
except ImportError:
|
|
|
|
from ansible.utils.display import Display
|
|
|
|
display = Display()
|
|
|
|
|
2015-09-10 21:55:59 +02:00
|
|
|
# Global so that all instances of a PluginLoader will share the caches
|
2014-10-06 21:27:41 +02:00
|
|
|
MODULE_CACHE = {}
|
|
|
|
PATH_CACHE = {}
|
|
|
|
PLUGIN_PATH_CACHE = {}
|
|
|
|
|
2016-09-07 07:54:17 +02:00
|
|
|
|
2017-08-15 22:38:59 +02:00
|
|
|
def get_plugin_class(obj):
|
2017-09-10 23:53:49 +02:00
|
|
|
if isinstance(obj, string_types):
|
|
|
|
return obj.lower().replace('module', '')
|
|
|
|
else:
|
|
|
|
return obj.__class__.__name__.lower().replace('module', '')
|
2016-11-28 18:49:40 +01:00
|
|
|
|
2017-06-06 10:26:25 +02:00
|
|
|
|
2017-08-15 22:38:59 +02:00
|
|
|
class AnsiblePlugin(with_metaclass(ABCMeta, object)):
|
2017-06-06 10:26:25 +02:00
|
|
|
|
2017-08-20 17:20:30 +02:00
|
|
|
def __init__(self):
|
2017-09-10 23:53:49 +02:00
|
|
|
self._options = {}
|
2017-08-20 17:20:30 +02:00
|
|
|
|
|
|
|
def get_option(self, option, hostvars=None):
|
2017-09-10 23:53:49 +02:00
|
|
|
if option not in self._options:
|
2017-08-20 17:20:30 +02:00
|
|
|
option_value = C.config.get_config_value(option, plugin_type=get_plugin_class(self), plugin_name=self.name, variables=hostvars)
|
|
|
|
self.set_option(option, option_value)
|
2017-09-10 23:53:49 +02:00
|
|
|
return self._options.get(option)
|
2017-08-20 17:20:30 +02:00
|
|
|
|
|
|
|
def set_option(self, option, value):
|
2017-09-10 23:53:49 +02:00
|
|
|
self._options[option] = value
|
2017-08-20 17:20:30 +02:00
|
|
|
|
|
|
|
def set_options(self, options):
|
2017-09-10 23:53:49 +02:00
|
|
|
self._options = options
|
|
|
|
|
|
|
|
def _check_required(self):
|
|
|
|
# FIXME: standarize required check based on config
|
|
|
|
pass
|