Author: lslezak Date: Thu Apr 3 13:48:52 2008 New Revision: 46024 URL: http://svn.opensuse.org/viewcvs/yast?rev=46024&view=rev Log: - preliminary support for command line mode (fate#120045) Added: trunk/heartbeat/src/commandline.ycp Modified: trunk/heartbeat/src/Makefile.am trunk/heartbeat/src/heartbeat.ycp Modified: trunk/heartbeat/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/trunk/heartbeat/src/Makefile.am?rev=460... ============================================================================== --- trunk/heartbeat/src/Makefile.am (original) +++ trunk/heartbeat/src/Makefile.am Thu Apr 3 13:48:52 2008 @@ -17,6 +17,7 @@ media_conf.ycp \ ipfail_conf.ycp \ timeouts_conf.ycp \ + commandline.ycp \ common.ycp Added: trunk/heartbeat/src/commandline.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/heartbeat/src/commandline.ycp?rev... ============================================================================== --- trunk/heartbeat/src/commandline.ycp (added) +++ trunk/heartbeat/src/commandline.ycp Thu Apr 3 13:48:52 2008 @@ -0,0 +1,107 @@ +/** + * File: include/heartbeat/commandline.ycp + * Package: Configuration of HA + * Summary: Command line handlers + * Authors: Ladislav Slezak <lslezak@novell.com> + * + * $Id:$ + */ + +{ + import "Heartbeat"; + import "CommandLine"; + + textdomain "heartbeat"; + + /** + * Command line handler for List action: list available configurations + */ + boolean ListHandler(map params) + { + y2debug("list params: %1", params); + + // handle "list nodes" command + if (haskey(params, "nodes")) + { + list<string> nodes = Heartbeat::config["node"]:[]; + foreach(string node, nodes, + { + CommandLine::Print(node); + } + ); + } + + return false; // = do not try to write + } + + /** + * Command line handler for List action: list available configurations + */ + boolean AddHandler(map params) + { + y2debug("add params: %1", params); + + // handle "add node name='name'" command + if (haskey(params, "node") && haskey(params, "name")) + { + list<string> nodes = Heartbeat::config["node"]:[]; + string name = params["name"]:""; + + if (name != "" && !contains(nodes, name)) + { + // add the specified node + nodes = add(nodes, name); + Heartbeat::config["node"] = nodes; + Heartbeat::config["modified"] = true; + + // command line status message, %1 is name of the node + CommandLine::PrintVerbose(sformat(_("Added node '%1'"), name)); + + y2debug("New config: %1", Heartbeat::config); + return true; + } + } + + return false; // = do not try to write + } + + boolean DeleteHandler(map params) + { + y2debug("delete params: %1", params); + + // handle "delete node name='name'" command + if (haskey(params, "node") && haskey(params, "name")) + { + list<string> nodes = Heartbeat::config["node"]:[]; + string name = params["name"]:""; + + if (name != "" && contains(nodes, name)) + { + // remove the specified node + nodes = filter(string node, nodes, {return node != name;}); + Heartbeat::config["node"] = nodes; + Heartbeat::config["modified"] = true; + + // command line status message, %1 is name of the node + CommandLine::PrintVerbose(sformat(_("Removed node '%1'"), name)); + + y2debug("New config: %1", Heartbeat::config); + return true; + } + } + + return false; // = do not try to write + } + + boolean DoNotAbort() + { + return false; + } + + boolean ReadHandler() + { + // register abort callback + Heartbeat::AbortFunction = DoNotAbort; + return Heartbeat::Read(); + } +} Modified: trunk/heartbeat/src/heartbeat.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/heartbeat/src/heartbeat.ycp?rev=4... ============================================================================== --- trunk/heartbeat/src/heartbeat.ycp (original) +++ trunk/heartbeat/src/heartbeat.ycp Thu Apr 3 13:48:52 2008 @@ -27,22 +27,68 @@ import "CommandLine"; include "heartbeat/wizards.ycp"; +include "heartbeat/commandline.ycp"; map cmdline_description = $[ "id" : "heartbeat", /* Command line help text for the Xheartbeat module */ "help" : _("Configuration of Heartbeat"), "guihandler" : HeartbeatSequence, - "initialize" : Heartbeat::Read, + "initialize" : ReadHandler, "finish" : Heartbeat::Write, "actions" : $[ - // FIXME TODO: fill the functionality description here + // functionality description + "list" : $[ + "handler" : ListHandler, + // translators: command line help text for add action + "help" : _("List configured parameters."), + // options + "options" : [ "non_strict" ], + // help text for unknownd parameters + "non_strict_help" : _("Value of the specific module parameter."), + ], + // functionality description + "add" : $[ + "handler" : AddHandler, + // translators: command line help text for add action + "help" : _("Add/configure a new parameter."), + // options + "options" : [ "non_strict" ], + // help text for unknownd parameters + "non_strict_help" : _("Value of the specific module parameter."), + ], + // functionality description + "delete" : $[ + "handler" : DeleteHandler, + // translators: command line help text for add action + "help" : _("Delete a configured parameter."), + // options + "options" : [ "non_strict" ], + // help text for unknownd parameters + "non_strict_help" : _("Value of the specific module parameter."), + ], ], + // descriptions of options "options" : $[ - // FIXME TODO: fill the option descriptions here + "nodes" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + ], + "node" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + ], + "name" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], ], + // map options to commands "mapping" : $[ - // FIXME TODO: fill the mappings of actions and options here + "list" : ["nodes"], + "add" : ["node", "name"], + "delete" : ["node", "name"], ] ]; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org