2019-10-26 08:27:16 +00:00
|
|
|
import logging
|
|
|
|
from discovery import DiscoveryConfig
|
2019-10-26 08:54:31 +00:00
|
|
|
from utils.plugins import BaseMixin
|
2019-10-26 08:27:16 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
PLUGIN_PACKAGE_NAME = 'discovery.plugins'
|
|
|
|
|
|
|
|
|
2019-10-26 08:54:31 +00:00
|
|
|
class DiscoveryFactory(BaseMixin):
|
2019-10-26 08:27:16 +00:00
|
|
|
PLUGIN_TYPE = 'Discovery'
|
|
|
|
def __init__(self, searchpath=None):
|
2019-10-26 08:54:31 +00:00
|
|
|
super().__init__(searchpath=searchpath, package_name=PLUGIN_PACKAGE_NAME)
|
2019-10-26 08:27:16 +00:00
|
|
|
|
2019-10-26 08:54:31 +00:00
|
|
|
def _create(self, plugin_class, **kwargs):
|
2019-10-26 08:27:16 +00:00
|
|
|
conn_mgr = kwargs.pop('conn_mgr', None)
|
|
|
|
if not conn_mgr:
|
|
|
|
raise RuntimeError('Please pass conn_mgr to create discovery!')
|
|
|
|
|
|
|
|
plugin_config = DiscoveryConfig.Create()
|
|
|
|
plugin = plugin_class.create(plugin_config=plugin_config, conn_mgr=conn_mgr, **kwargs)
|
|
|
|
return plugin
|