Ejemplo n.º 1
0
def _load_plugins(plugins, debug=True):
    """
    Do not use - will be removed in the next release!

    Merge this into StarClusterConfig._load_plugins in a future release.
    Currently used to provide backwards compatibility for the plugin kwarg for
    Cluster. Cluster now expects the plugins kwarg to be a list of plugin
    objects not a list of dicts. This should be merged into
    StarClusterConfig._load_plugins in a future release after warning about the
    change in a previous release.
    """
    plugs = []
    for plugin in plugins:
        setup_class = plugin.get('setup_class')
        plugin_name = plugin.get('__name__').split()[-1]
        mod_name = '.'.join(setup_class.split('.')[:-1])
        class_name = setup_class.split('.')[-1]
        try:
            mod = __import__(mod_name, globals(), locals(), [class_name])
        except SyntaxError, e:
            raise exception.PluginSyntaxError(
                "Plugin %s (%s) contains a syntax error at line %s" %
                (plugin_name, e.filename, e.lineno))
        except ImportError, e:
            raise exception.PluginLoadError("Failed to import plugin %s: %s" %
                                            (plugin_name, e[0]))
Ejemplo n.º 2
0
 def get_plugins(self):
     plugstxt = self.user_data.get(static.UD_PLUGINS_FNAME)
     payload = plugstxt.split('\n', 2)[2]
     plugins_metadata = utils.decode_uncompress_load(payload)
     plugs = []
     for klass, args, kwargs in plugins_metadata:
         mod_path, klass_name = klass.rsplit('.', 1)
         try:
             mod = __import__(mod_path, fromlist=[klass_name])
             plug = getattr(mod, klass_name)(*args, **kwargs)
         except SyntaxError, e:
             raise exception.PluginSyntaxError(
                 "Plugin %s (%s) contains a syntax error at line %s" %
                 (klass_name, e.filename, e.lineno))
         except ImportError, e:
             raise exception.PluginLoadError(
                 "Failed to import plugin %s: %s" % (klass_name, e[0]))
Ejemplo n.º 3
0
 def get_plugins(self, order, plugins_metadata=None):
     if plugins_metadata is None:
         plugins_metadata = self.get_plugins_full_metadata(order)
     plugs = []
     for klass, args, kwargs in plugins_metadata:
         mod_path, klass_name = klass.rsplit('.', 1)
         try:
             mod = __import__(mod_path, fromlist=[klass_name])
             plug = getattr(mod, klass_name)(*args, **kwargs)
         except SyntaxError, e:
             raise exception.PluginSyntaxError(
                 "Plugin %s (%s) contains a syntax error at line %s" %
                 (klass_name, e.filename, e.lineno))
         except ImportError, e:
             raise exception.PluginLoadError(
                 "Failed to import plugin %s: %s" %
                 (klass_name, e[0]))