Author: lslezak Date: Wed Apr 9 14:18:08 2008 New Revision: 46282 URL: http://svn.opensuse.org/viewcvs/yast?rev=46282&view=rev Log: - CLI - support for media configuration Modified: trunk/heartbeat/src/commandline.ycp trunk/heartbeat/src/heartbeat.ycp Modified: trunk/heartbeat/src/commandline.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/heartbeat/src/commandline.ycp?rev=46282&r1=46281&r2=46282&view=diff ============================================================================== --- trunk/heartbeat/src/commandline.ycp (original) +++ trunk/heartbeat/src/commandline.ycp Wed Apr 9 14:18:08 2008 @@ -13,84 +13,280 @@ textdomain "heartbeat"; + // default values + const integer default_udp_port = 694; + const string default_udp_port_str = tostring(default_udp_port); + + const integer default_ttl = 2; + const string default_ttl_str = tostring(default_ttl); + + /** + * Command line handler for List action: list available configurations + */ + boolean ListNodes() + { + 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 ListHandler(map params) + boolean AddNode(string name) { - y2debug("list params: %1", params); + list<string> nodes = Heartbeat::config["node"]:[]; - // handle "list nodes" command - if (haskey(params, "nodes")) + if (name != "" && !contains(nodes, name)) { - list<string> nodes = Heartbeat::config["node"]:[]; - foreach(string node, nodes, - { - CommandLine::Print(node); - } - ); + // 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 DeleteNode(string name) + { + list<string> nodes = Heartbeat::config["node"]:[]; + + 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 + } + + /** * Command line handler for List action: list available configurations */ - boolean AddHandler(map params) + boolean NodeHandler(map params) { - y2debug("add params: %1", params); + if (haskey(params, "list")) + { + return ListNodes(); + } + + string name = params["name"]:""; - // handle "add node name='name'" command - if (haskey(params, "node") && haskey(params, "name")) + if (name != "") { - list<string> nodes = Heartbeat::config["node"]:[]; - string name = params["name"]:""; + if (haskey(params, "add")) + { + return AddNode(name); + } + else if (haskey(params, "delete")) + { + return DeleteNode(name); + } + } + else + { + CommandLine::Print("ERROR: Missing or empty 'name' option!"); + } + + return false; + } - if (name != "" && !contains(nodes, name)) + boolean ListMedia() + { + list<string> bcast = Heartbeat::config["bcast"]:[]; + list<string> mcast = Heartbeat::config["mcast"]:[]; + + foreach(string d, bcast, { - // add the specified node - nodes = add(nodes, name); - Heartbeat::config["node"] = nodes; - Heartbeat::config["modified"] = true; + CommandLine::Print(sformat(_("Broadcast device: %1"), d)); + } + ); - // command line status message, %1 is name of the node - CommandLine::PrintVerbose(sformat(_("Added node '%1'"), name)); + foreach(string d, mcast, + { + list<string> options = splitstring(d, " "); - y2debug("New config: %1", Heartbeat::config); - return true; + options = filter(string optn, options, {return optn != nil && optn != "";}); + + CommandLine::Print(sformat(_("Multicast device: %1, adress: %2, UDP: %3, TTL: %4"), + options[0]:"", options[1]:"", options[2]:"", options[3]:"")); } + ); + + return false; + } + + boolean GetUDP() + { + string udpport = Heartbeat::config["udpport"]:default_udp_port_str; + CommandLine::Print(udpport); + return false; + } + + boolean SetUDP(integer udpport) + { + string current_udpport = Heartbeat::config["udpport"]:default_udp_port_str; + string udpport_str = tostring(udpport); + + if (udpport_str != current_udpport) + { + CommandLine::PrintVerbose(sformat(_("Setting UDP port to %1"), udpport_str)); + Heartbeat::config["modified"] = true; + Heartbeat::config["udpport"] = udpport_str; + return true; } - return false; // = do not try to write + return false; + } + + string MCastDeviceString(string device, string address, integer ttl, integer udp) + { + return device + " " + address + " " + tostring(udp) + " " + tostring(ttl) + " 0"; } - boolean DeleteHandler(map params) + boolean AddMedium(string type, string device, string address, integer ttl, integer udp) { - y2debug("delete params: %1", params); + if (type == "bcast") + { + list<string> bcast_devices = Heartbeat::config["bcast"]:[]; - // handle "delete node name='name'" command - if (haskey(params, "node") && haskey(params, "name")) + if (!contains(bcast_devices, device)) + { + Heartbeat::config["modified"] = true; + Heartbeat::config["bcast"] = add(bcast_devices, device); + return true; + } + } + else if (type == "mcast") { - list<string> nodes = Heartbeat::config["node"]:[]; - string name = params["name"]:""; + string medium = MCastDeviceString(device, address, ttl, udp); + list<string> mcast_devices = Heartbeat::config["bcast"]:[]; - if (name != "" && contains(nodes, name)) + if (!contains(mcast_devices, medium)) { - // remove the specified node - nodes = filter(string node, nodes, {return node != name;}); - Heartbeat::config["node"] = nodes; Heartbeat::config["modified"] = true; + Heartbeat::config["mcast"] = add(mcast_devices, medium); + return true; + } + } + + return false; + } - // command line status message, %1 is name of the node - CommandLine::PrintVerbose(sformat(_("Removed node '%1'"), name)); + boolean DeleteMedium(string type, string device, string address, integer ttl, integer udp) + { + if (type == "bcast") + { + list<string> bcast_devices = Heartbeat::config["bcast"]:[]; + + if (contains(bcast_devices, device)) + { + Heartbeat::config["modified"] = true; + Heartbeat::config["bcast"] = filter(string dev, bcast_devices, {return dev != device;}); + return true; + } + } + else if (type == "mcast") + { + string medium = MCastDeviceString(device, address, ttl, udp); + list<string> mcast_devices = Heartbeat::config["mcast"]:[]; - y2debug("New config: %1", Heartbeat::config); + if (contains(mcast_devices, medium)) + { + Heartbeat::config["modified"] = true; + Heartbeat::config["mcast"] = filter(string dev, mcast_devices, {return dev != medium;}); return true; } } - return false; // = do not try to write + return false; + } + + /** + * Command line handler for List action: list available configurations + */ + boolean MediumHandler(map params) + { + if (haskey(params, "list")) + { + return ListMedia(); + } + + if (haskey(params, "set")) + { + if (haskey(params, "udp")) + { + integer udp = tointeger(params["udp"]:default_udp_port_str); + + if (udp != nil && udp > 0 && udp < 65536) + { + return SetUDP(udp); + } + else + { + CommandLine::Print(_("Missing or invalid 'udp' option")); + } + } + + return false; + } + + if (haskey(params, "get")) + { + if (haskey(params, "udp")) + { + return GetUDP(); + } + + return false; + } + + string device = params["device"]:""; + string address = params["address"]:""; + string type = params["type"]:""; + integer ttl = tointeger(params["ttl"]:default_ttl_str); + integer udp = tointeger(params["udp"]:default_udp_port_str); + + if (ttl == nil || udp == nil || device == nil || device == "") + { + return false; + } + + if (haskey(params, "add")) + { + return AddMedium(type, device, address, ttl, udp); + } + else if (haskey(params, "delete")) + { + return DeleteMedium(type, device, address, ttl, udp); + } + else + { + CommandLine::Print("ERROR: Missing or invalid command option!"); + } + + return false; } boolean DoNotAbort() Modified: trunk/heartbeat/src/heartbeat.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/heartbeat/src/heartbeat.ycp?rev=46282&r1=46281&r2=46282&view=diff ============================================================================== --- trunk/heartbeat/src/heartbeat.ycp (original) +++ trunk/heartbeat/src/heartbeat.ycp Wed Apr 9 14:18:08 2008 @@ -38,8 +38,8 @@ "finish" : Heartbeat::Write, "actions" : $[ // functionality description - "list" : $[ - "handler" : ListHandler, + "node" : $[ + "handler" : NodeHandler, // translators: command line help text for add action "help" : _("List configured parameters."), // options @@ -47,21 +47,10 @@ // 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, + "medium" : $[ + "handler" : MediumHandler, // translators: command line help text for add action - "help" : _("Delete a configured parameter."), + "help" : _("List configured parameters."), // options "options" : [ "non_strict" ], // help text for unknownd parameters @@ -70,11 +59,15 @@ ], // descriptions of options "options" : $[ - "nodes" : $[ + "add" : $[ // translators: command line help text for the 'play' option "help" : _("List all configured nodes (including this node)."), ], - "node" : $[ + "delete" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + ], + "list" : $[ // translators: command line help text for the 'play' option "help" : _("List all configured nodes (including this node)."), ], @@ -83,12 +76,47 @@ "help" : _("List all configured nodes (including this node)."), "type" : "string" ], + "type" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], + "device" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], + "address" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], + "ttl" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "integer" + ], + "udp" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "integer" + ], + "method" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], + "key" : $[ + // translators: command line help text for the 'play' option + "help" : _("List all configured nodes (including this node)."), + "type" : "string" + ], ], // map options to commands "mapping" : $[ - "list" : ["nodes"], - "add" : ["node", "name"], - "delete" : ["node", "name"], + "node" : ["add", "delete", "list", "name"], + "medium" : ["add", "delete", "list", "type", "device", "address", "ttl", "set", "udp"], + "authentication" : ["set", "list", "method", "key"], ] ]; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org