Comparison

plugins/mod_console.lua @ 3840:abcbce5e4240

mod_console: Removed redundant code for host:activate() and host:deactivate(), now that hostmanager has error checking.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 09 Dec 2010 22:17:28 +0500
parent 3614:8b436cc88c0e
comparison
equal deleted inserted replaced
3839:f408d586de9a 3840:abcbce5e4240
602 602
603 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); 603 return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s");
604 end 604 end
605 605
606 def_env.host = {}; def_env.hosts = def_env.host; 606 def_env.host = {}; def_env.hosts = def_env.host;
607
607 function def_env.host:activate(hostname, config) 608 function def_env.host:activate(hostname, config)
608 local hostmanager_activate = require "core.hostmanager".activate; 609 return hostmanager.activate(hostname, config);
609 if hosts[hostname] then 610 end
610 return false, "The host "..tostring(hostname).." is already activated";
611 end
612
613 local defined_hosts = config or configmanager.getconfig();
614 if not config and not defined_hosts[hostname] then
615 return false, "Couldn't find "..tostring(hostname).." defined in the config, perhaps you need to config:reload()?";
616 end
617 hostmanager_activate(hostname, config or defined_hosts[hostname]);
618 return true, "Host "..tostring(hostname).." activated";
619 end
620
621 function def_env.host:deactivate(hostname, reason) 611 function def_env.host:deactivate(hostname, reason)
622 local hostmanager_deactivate = require "core.hostmanager".deactivate; 612 return hostmanager.deactivate(hostname, reason);
623 local host = hosts[hostname];
624 if not host then
625 return false, "The host "..tostring(hostname).." is not activated";
626 end
627 if reason then
628 reason = { condition = "host-gone", text = reason };
629 end
630 hostmanager_deactivate(hostname, reason);
631 return true, "Host "..tostring(hostname).." deactivated";
632 end 613 end
633 614
634 function def_env.host:list() 615 function def_env.host:list()
635 local print = self.session.print; 616 local print = self.session.print;
636 local i = 0; 617 local i = 0;