Exemplo n.º 1
0
    def post(self, **kwargs):
        """
        Upload a plugin
        """
        storage_manager = get_storage_manager()
        is_caravan = False
        installed_plugins = []
        get_resource_manager().assert_no_snapshot_creation_running_or_queued()
        try:
            plugins, code = UploadedCaravanManager().receive_uploaded_data(
                **kwargs)
            is_caravan = True
        except UploadedCaravanManager.InvalidCaravanException:
            plugin, code = UploadedPluginsManager().receive_uploaded_data(
                str(uuid4()),
                **kwargs
            )
            plugins = [plugin]
        for plugin in plugins:
            try:
                get_resource_manager().install_plugin(plugin)
                installed_plugins.append(plugin)
            except manager_exceptions.ExecutionTimeout:
                tp, ex, tb = sys.exc_info()
                if not is_caravan:
                    raise manager_exceptions.PluginInstallationTimeout(
                        'Timed out during plugin installation.'
                        '({0}: {1})'.format(tp.__name__, ex)), None, tb
            except Exception:
                get_resource_manager().remove_plugin(plugin_id=plugin.id,
                                                     force=True)
                tp, ex, tb = sys.exc_info()
                if not is_caravan:
                    raise manager_exceptions.PluginInstallationError(
                        'Failed during plugin installation.'
                        '({0}: {1})'.format(tp.__name__, ex)), None, tb

        if is_caravan:
            storage_plugins = storage_manager.list(
                models.Plugin,
                filters={'id': [p.id for p in installed_plugins]})

            return ListResponse(items=storage_plugins.items,
                                metadata=storage_plugins.metadata), code
        else:
            return plugins[0], code
Exemplo n.º 2
0
 def post(self, **kwargs):
     """
     Upload a plugin
     """
     plugin, code = UploadedPluginsManager().receive_uploaded_data(
         str(uuid4()))
     try:
         get_resource_manager().install_plugin(plugin)
     except manager_exceptions.ExecutionTimeout:
         tp, ex, tb = sys.exc_info()
         raise manager_exceptions.PluginInstallationTimeout(
             'Timed out during plugin installation. ({0}: {1})'
             .format(tp.__name__, ex)), None, tb
     except Exception:
         get_resource_manager().remove_plugin(
             plugin_id=plugin.id, force=True)
         tp, ex, tb = sys.exc_info()
         raise manager_exceptions.PluginInstallationError(
             'Failed during plugin installation. ({0}: {1})'
             .format(tp.__name__, ex)), None, tb
     return plugin, code
Exemplo n.º 3
0
 def delete(self, plugin_id, **kwargs):
     """
     Delete plugin by ID
     """
     request_dict = get_json_and_verify_params()
     force = verify_and_convert_bool('force',
                                     request_dict.get('force', False))
     try:
         return get_resource_manager().remove_plugin(plugin_id=plugin_id,
                                                     force=force)
     except manager_exceptions.ManagerException:
         raise
     except manager_exceptions.ExecutionTimeout:
         tp, ex, tb = sys.exc_info()
         raise manager_exceptions.PluginInstallationTimeout(
             'Timed out during plugin un-installation. ({0}: {1})'.format(
                 tp.__name__, ex)), None, tb
     except Exception:
         tp, ex, tb = sys.exc_info()
         raise manager_exceptions.PluginInstallationError(
             'Failed during plugin un-installation. ({0}: {1})'.format(
                 tp.__name__, ex)), None, tb