mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime

Sat, 17 Oct 2009 15:26:32 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 17 Oct 2009 15:26:32 +0100
changeset 1977
325a49f8edab
parent 1976
5f3eaab987c3
child 1978
8f9dc8a25660

mod_console: Add commands host:activate(host, config) and host:deactivate(host, reason) to add/remove hosts at runtime

plugins/mod_console.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_console.lua	Sat Oct 17 15:25:30 2009 +0100
+++ b/plugins/mod_console.lua	Sat Oct 17 15:26:32 2009 +0100
@@ -572,6 +572,34 @@
 	return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
 end
 
+def_env.host = {}; def_env.hosts = def_env.host;
+function def_env.host:activate(hostname, config)
+	local hostmanager_activate = require "core.hostmanager".activate;
+	if hosts[hostname] then
+		return false, "The host "..tostring(hostname).." is already activated";
+	end
+	
+	local defined_hosts = config or configmanager.getconfig();
+	if not config and not defined_hosts[hostname] then
+		return false, "Couldn't find "..tostring(hostname).." defined in the config, perhaps you need to config:reload()?";
+	end
+	hostmanager_activate(hostname, config or defined_hosts[hostname]);
+	return true, "Host "..tostring(hostname).." activated";
+end
+
+function def_env.host:deactivate(hostname, reason)
+	local hostmanager_deactivate = require "core.hostmanager".deactivate;
+	local host = hosts[hostname];
+	if not host then
+		return false, "The host "..tostring(hostname).." is not activated";
+	end
+	if reason then
+		reason = { condition = "host-gone", text = reason };
+	end
+	hostmanager_deactivate(hostname, reason);
+	return true, "Host "..tostring(hostname).." deactivated";
+end
+
 -------------
 
 function printbanner(session)

mercurial