def sync_plugins_metadata(cls, plugin_ids=None): """Sync metadata for plugins by given ids. If there is not ids all newest plugins will be synced """ if plugin_ids: plugins = PluginCollection.get_by_uids(plugin_ids) else: plugins = PluginCollection.all() for plugin in plugins: plugin_adapter = wrap_plugin(plugin) plugin_adapter.sync_metadata_to_db()
def sync_plugins_metadata(cls, plugin_ids=None): """Sync metadata for plugins by given ids. If there is not ids all newest plugins will be synced """ if plugin_ids: plugins = PluginCollection.get_by_uids(plugin_ids) else: plugins = PluginCollection.all_newest() for plugin in plugins: plugin_wrapper = wrap_plugin(plugin) plugin_wrapper.sync_metadata_to_db()
def get_plugin_attributes(cls, cluster): plugins_attrs = {} for plugin_db in PluginCollection.all_newest(): attr_plugin = wrap_plugin(plugin_db) attrs = attr_plugin.get_plugin_attributes(cluster) plugins_attrs.update(attrs) return plugins_attrs
def sync_plugins_metadata(cls, plugin_ids=None): """Sync metadata for plugins by given IDs. If there are no IDs, all newest plugins will be synced. :param plugin_ids: list of plugin IDs :type plugin_ids: list """ if plugin_ids: plugins = PluginCollection.get_by_uids(plugin_ids) else: plugins = PluginCollection.all() for plugin in plugins: plugin_adapter = wrap_plugin(plugin) plugin_adapter.sync_metadata_to_db()
def get_plugin_attributes(cls, cluster): plugin_attributes = {} for plugin_db in PluginCollection.all_newest(): plugin_adapter = wrap_plugin(plugin_db) attributes = plugin_adapter.get_plugin_attributes(cluster) plugin_attributes.update(attributes) return plugin_attributes
def get_components_metadata(cls, release): """Get components metadata for all plugins which related to release. :param release: A release instance :type release: Release model :return: list -- List of plugins components """ components = [] seen_components = \ dict((c['name'], 'release') for c in release.components_metadata) for plugin_adapter in map(wrap_plugin, PluginCollection.get_by_release(release)): plugin_name = plugin_adapter.name for component in plugin_adapter.components_metadata: name = component['name'] if seen_components.get(name, plugin_name) != plugin_name: raise errors.AlreadyExists( 'Plugin {0} is overlapping with {1} by introducing ' 'the same component with name "{2}"'.format( plugin_adapter.name, seen_components[name], name)) if name not in seen_components: seen_components[name] = plugin_adapter.name components.append(component) return components
def get_components_metadata(cls, release): """Get components metadata for all plugins which related to release. :param release: A release instance :type release: Release model :return: list -- List of plugins components """ components = [] seen_components = \ dict((c['name'], 'release') for c in release.components_metadata) for plugin_adapter in map( wrap_plugin, PluginCollection.get_by_release(release)): plugin_name = plugin_adapter.name for component in plugin_adapter.components_metadata: name = component['name'] if seen_components.get(name, plugin_name) != plugin_name: raise errors.AlreadyExists( 'Plugin {0} is overlapping with {1} by introducing ' 'the same component with name "{2}"' .format(plugin_adapter.name, seen_components[name], name)) if name not in seen_components: seen_components[name] = plugin_adapter.name components.append(component) return components
def sync_plugins_metadata(cls, plugin_ids=None): """Sync or install metadata for plugins by given IDs. If there are no IDs, all plugins will be synced. :param plugin_ids: list of plugin IDs :type plugin_ids: list """ if plugin_ids: for plugin in PluginCollection.get_by_uids(plugin_ids): cls._plugin_update(plugin) else: cls._install_or_update_or_delete_plugins()
def enable_plugins_by_components(cls, cluster): """Enable plugin by components. :param cluster: A cluster instance :type cluster: Cluster model """ cluster_components = set(cluster.components) plugin_ids = [p.id for p in PluginCollection.all_newest()] for plugin in ClusterPlugin.get_connected_plugins(cluster, plugin_ids): plugin_adapter = wrap_plugin(plugin) plugin_components = set( component['name'] for component in plugin_adapter.components_metadata) if cluster_components & plugin_components: ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)
def enable_plugins_by_components(cls, cluster): """Enable plugin by components. :param cluster: A cluster instance :type cluster: Cluster model """ cluster_components = set(cluster.components) plugin_ids = [p.id for p in PluginCollection.all_newest()] for plugin in ClusterPlugins.get_connected_plugins( cluster, plugin_ids): plugin_adapter = wrap_plugin(plugin) plugin_components = set( component['name'] for component in plugin_adapter.components_metadata) if cluster_components & plugin_components: ClusterPlugins.set_attributes( cluster.id, plugin.id, enabled=True)
def _install_or_update_or_delete_plugins(cls): """Sync plugins using FS and DB. If plugin: in DB and present on filesystem, it will be updated; in DB and not present on filesystem, it will be removed; not in DB, but present on filesystem, it will be installed """ installed_plugins = {} for plugin in PluginCollection.all(): plugin_adapter = wrap_plugin(plugin) installed_plugins[plugin_adapter.path_name] = plugin for plugin_dir in cls._list_plugins_on_fs(): if plugin_dir in installed_plugins: cls._plugin_update(installed_plugins.pop(plugin_dir)) else: cls._plugin_create(plugin_dir) for deleted_plugin in installed_plugins.values(): cls._plugin_delete(deleted_plugin)
def process_cluster_attributes(cls, cluster, attrs, query=None): if query is None: query = PluginCollection.all() for plugin_db in query: attr_plugin = ClusterAttributesPlugin(plugin_db) attr_plugin.process_cluster_attributes(cluster, attrs)