def _get_plugins_nodes(self, request, jails): host = get_base_url(request) plugs = Plugins.objects.filter( plugin_enabled=True, plugin_jail__in=[jail.jail_host for jail in jails]) if len(plugs) > 1: timeout = len(plugs) * 5 else: timeout = 6 args = [(y, host, request, timeout) for y in plugs] with ThreadPool(10) as pool: for plugin, url, data in pool.imap(self._plugin_fetch, args): if not data: continue try: data = json.loads(data) nodes = unserialize_tree(data) for node in nodes: # We have our TreeNode's, find out where to place them found = False if node.append_to: log.debug( "Plugin %s requested to be appended to %s", plugin.plugin_name, node.append_to) places = node.append_to.split('.') places.reverse() for root in tree_roots: find = root.find_place(list(places)) if find is not None: find.append_child(node) found = True break else: log.debug( "Plugin %s didn't request to be appended " "anywhere specific", plugin.plugin_name) if not found: tree_roots.register(node) except Exception as e: log.warn( _("An error occurred while unserializing from " "%(url)s: %(error)s") % { 'url': url, 'error': e }) log.debug( _("Error unserializing %(url)s (%(error)s), data " "retrieved:") % { 'url': url, 'error': e, }) continue
def _get_plugins_nodes(self, request, jails): host = get_base_url(request) plugs = Plugins.objects.filter(plugin_enabled=True, plugin_jail__in=[jail.jail_host for jail in jails]) if len(plugs) > 1: timeout = len(plugs) * 5 else: timeout = 6 args = map( lambda y: (y, host, request, timeout), plugs) pool = eventlet.GreenPool(20) for plugin, url, data in pool.imap(self._plugin_fetch, args): if not data: continue try: data = json.loads(data) nodes = unserialize_tree(data) for node in nodes: # We have our TreeNode's, find out where to place them found = False if node.append_to: log.debug( "Plugin %s requested to be appended to %s", plugin.plugin_name, node.append_to) places = node.append_to.split('.') places.reverse() for root in tree_roots: find = root.find_place(list(places)) if find is not None: find.append_child(node) found = True break else: log.debug( "Plugin %s didn't request to be appended " "anywhere specific", plugin.plugin_name) if not found: tree_roots.register(node) except Exception, e: log.warn(_( "An error occurred while unserializing from " "%(url)s: %(error)s") % {'url': url, 'error': e}) log.debug(_( "Error unserializing %(url)s (%(error)s), data " "retrieved:" ) % { 'url': url, 'error': e, }) continue
def __init__(self, *args, **kwargs): super(ViewPluginJails, self).__init__(*args, **kwargs) request = kwargs.get('request') host = get_base_url(request) jails = Jails.objects.filter(jail_type=WARDEN_TYPE_PLUGINJAIL) for jail in jails: jail_node = self.new_jail_node(jail, u'JailPluginIcon') self.append_child(jail_node) jail_node_view = self.new_jail_node_view(jail) jail_node_view.order = 1 jail_node.append_child(jail_node_view) storage_node = self.new_storage_node(jail) storage_node.order = 2 jail_node.append_child(storage_node) storage_order = 1 nmps = NullMountPoint.objects.filter(jail=jail.jail_host) for nmp in nmps: storage_node_view = self.new_storage_node_view(nmp) storage_node_view.order = storage_order storage_node.append_child(storage_node_view) storage_order += 1 storage_node_mkdir = self.new_storage_node_mkdir(jail) storage_node_mkdir.order = storage_order storage_node.append_child(storage_node_mkdir) storage_order += 1 storage_node_add = self.new_storage_node_add(jail) storage_node_add.order = storage_order storage_node.append_child(storage_node_add) plugin_node = TreeNode() plugin_node.gname = 'Plugins' plugin_node.name = _(u'Plugins') plugin_node.icon = u'PluginIcon' plugin_node.order = 3 args = map( lambda y: (y, host, request), Plugins.objects.filter(plugin_enabled=True, plugin_jail=jail.jail_host)) plugin_order = 1 pool = eventlet.GreenPool(20) for plugin, url, data in pool.imap(self.plugin_fetch, args): if not data: continue try: data = simplejson.loads(data) nodes = unserialize_tree(data) for node in nodes: node.order = plugin_order plugin_node.append_child(node) plugin_order += 1 except Exception, e: log.warn(_( "An error occurred while unserializing from " "%(url)s: %(error)s") % {'url': url, 'error': e}) log.debug(_( "Error unserializing %(url)s (%(error)s), data " "retrieved:") % { 'url': url, 'error': e, }) for line in data.splitlines(): log.debug(line) continue plugin_node_add = TreeNode() plugin_node_add.name = _('Install Plugin') plugin_node_add.type = 'editobject' plugin_node_add.view = 'plugin_install' plugin_node_add.kwargs = {'jail_id': jail.id } plugin_node_add.model = 'Plugins' plugin_node_add.icon = u'PluginInstallIcon' plugin_node_add.app_name = 'jails' plugin_node_add.order = plugin_order plugin_node.append_child(plugin_node_add) jail_node.append_child(plugin_node)
def __init__(self, *args, **kwargs): super(ViewPluginJails, self).__init__(*args, **kwargs) request = kwargs.get('request') host = get_base_url(request) jails = Jails.objects.filter(jail_type=WARDEN_TYPE_PLUGINJAIL) for jail in jails: jail_node = self.new_jail_node(jail, u'JailPluginIcon') self.append_child(jail_node) jail_node_view = self.new_jail_node_view(jail) jail_node_view.order = 1 jail_node.append_child(jail_node_view) storage_node = self.new_storage_node(jail) storage_node.order = 2 jail_node.append_child(storage_node) storage_order = 1 nmps = NullMountPoint.objects.filter(jail=jail.jail_host) for nmp in nmps: storage_node_view = self.new_storage_node_view(nmp) storage_node_view.order = storage_order storage_node.append_child(storage_node_view) storage_order += 1 storage_node_mkdir = self.new_storage_node_mkdir(jail) storage_node_mkdir.order = storage_order storage_node.append_child(storage_node_mkdir) storage_order += 1 storage_node_add = self.new_storage_node_add(jail) storage_node_add.order = storage_order storage_node.append_child(storage_node_add) plugin_node = TreeNode() plugin_node.gname = 'Plugins' plugin_node.name = _(u'Plugins') plugin_node.icon = u'PluginIcon' plugin_node.order = 3 args = map( lambda y: (y, host, request), Plugins.objects.filter(plugin_enabled=True, plugin_jail=jail.jail_host)) plugin_order = 1 pool = eventlet.GreenPool(20) for plugin, url, data in pool.imap(self.plugin_fetch, args): if not data: continue try: data = simplejson.loads(data) nodes = unserialize_tree(data) for node in nodes: node.order = plugin_order plugin_node.append_child(node) plugin_order += 1 except Exception, e: log.warn( _("An error occurred while unserializing from " "%(url)s: %(error)s") % { 'url': url, 'error': e }) log.debug( _("Error unserializing %(url)s (%(error)s), data " "retrieved:") % { 'url': url, 'error': e, }) for line in data.splitlines(): log.debug(line) continue plugin_node_add = TreeNode() plugin_node_add.name = _('Install Plugin') plugin_node_add.type = 'editobject' plugin_node_add.view = 'plugin_install' plugin_node_add.kwargs = {'jail_id': jail.id} plugin_node_add.model = 'Plugins' plugin_node_add.icon = u'PluginInstallIcon' plugin_node_add.app_name = 'jails' plugin_node_add.order = plugin_order plugin_node.append_child(plugin_node_add) jail_node.append_child(plugin_node)