mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-05 19:15:03 +00:00
Implements unbind of configsets across all pools instances
This commit is contained in:
parent
96484c01ab
commit
a6ffb62bf2
3 changed files with 93 additions and 1 deletions
|
|
@ -470,6 +470,33 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Unbind a `configset_id` from all pools which are currently using it, and sets them the defauls configset.
|
||||
function base_pools:unbind_all_configset_id(configset_id)
|
||||
configset_id = tonumber(configset_id)
|
||||
|
||||
if not configset_id then
|
||||
-- Invalid argument
|
||||
return
|
||||
end
|
||||
|
||||
local locked = self:_lock()
|
||||
|
||||
if locked then
|
||||
local all_pools = self:get_all_pools()
|
||||
|
||||
for _, pool in pairs(all_pools) do
|
||||
if pool["configset_id"] == configset_id then
|
||||
-- Rewrite the pool using the default configset id
|
||||
self:_persist(pool["pool_id"], pool["name"], pool["members"], user_scripts.DEFAULT_CONFIGSET_ID)
|
||||
end
|
||||
end
|
||||
|
||||
self:_unlock()
|
||||
end
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Returns available confset ids which can be added to a pool
|
||||
function base_pools:get_available_configset_ids()
|
||||
-- Currently, confset_ids are shared across pools of all types
|
||||
|
|
|
|||
60
scripts/lua/modules/pools/pools_lua_utils.lua
Normal file
60
scripts/lua/modules/pools/pools_lua_utils.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
--
|
||||
-- (C) 2017-20 - ntop.org
|
||||
--
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local json = require "dkjson"
|
||||
local os_utils = require "os_utils"
|
||||
local base_pools = require "base_pools"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local pools_lua_utils = {}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Returns an array of pool Lua class instances, for all available pools
|
||||
-- e.g., {interface_pools:create(), local_network_pools:create(), snmp_device_pools:create(), ...}
|
||||
--
|
||||
-- This method is useful to perform operations (such as the deletion of a configset id) which are
|
||||
-- global and affect all the pool instances. Indeed a configset id is shared across all pools
|
||||
local function all_pool_instances_factory()
|
||||
local pools_dir = os_utils.fixPath(dirs.installdir .. "/scripts/lua/modules/pools/")
|
||||
local res = {}
|
||||
|
||||
for pool_file in pairs(ntop.readdir(pools_dir)) do
|
||||
if pool_file:match("%.lua$") then
|
||||
local pool_file_path = os_utils.fixPath(string.format("%s/%s", pools_dir, pool_file))
|
||||
|
||||
local pool = dofile(pool_file_path)
|
||||
|
||||
-- Make sure pool is actually a pool Lua class by checking if it has method create
|
||||
-- this is to avoid instantiating modules such as pool_lua_utils.lua and pool_rest_utils.lua
|
||||
-- which are not classes and thus cannot be instantiated
|
||||
if pool.create then
|
||||
-- If it has a method create, then we can instantiate it and add it to the result
|
||||
local instance = pool:create()
|
||||
res[#res + 1] = instance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Call `instance:unbind_all_configset_id` for every available pools `instance`
|
||||
function pools_lua_utils.unbind_all_configset_id(configset_id)
|
||||
local all_instances = all_pool_instances_factory()
|
||||
|
||||
for _, instance in pairs(all_instances) do
|
||||
instance:unbind_all_configset_id(configset_id)
|
||||
end
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
return pools_lua_utils
|
||||
Loading…
Add table
Add a link
Reference in a new issue