when running those cmds, check if the module do exist
or is disabled already.
also check if the module is enabled already.
Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
throw std::logic_error(oss.str());
}
+ bool module_enabled(const std::string& module_name) const
+ {
+ return modules.find(module_name) != modules.end();
+ }
+
+ bool any_supports_module(const std::string& module) const {
+ if (have_module(module)) {
+ return true;
+ }
+ for (auto& p : standbys) {
+ if (p.second.have_module(module)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
bool have_name(const string& name) const {
if (active_name == name) {
return true;
goto out;
}
+ if (pending_map.module_enabled(module)) {
+ ss << "module '" << module << "' is already enabled";
+ r = 0;
+ goto out;
+ }
pending_map.modules.insert(module);
} else if (prefix == "mgr module disable") {
string module;
r = -EINVAL;
goto out;
}
+ if (!pending_map.module_enabled(module)) {
+ ss << "module '" << module << "' is already disabled";
+ r = 0;
+ goto out;
+ }
+ if (!pending_map.any_supports_module(module)) {
+ ss << "module '" << module << "' does not exist";
+ }
pending_map.modules.erase(module);
} else {
ss << "Command '" << prefix << "' not implemented!";