[yast-devel] Re: [yast-commit] r64362 - in /trunk/cluster: agents/Makefile.am src/Cluster.ycp src/common.ycp src/dialogs.ycp src/helps.ycp src/wizards.ycp
On Wed, Jun 15, 2011 at 03:14:11AM -0000, xwhu@svn2.opensuse.org wrote:
Author: xwhu Date: Wed Jun 15 05:14:10 2011 New Revision: 64362
URL: http://svn.opensuse.org/viewcvs/yast?rev=64362&view=rev Log: Add support of csync2
Modified: trunk/cluster/agents/Makefile.am trunk/cluster/src/Cluster.ycp trunk/cluster/src/common.ycp trunk/cluster/src/dialogs.ycp trunk/cluster/src/helps.ycp trunk/cluster/src/wizards.ycp
Modified: trunk/cluster/agents/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/agents/Makefile.am?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/agents/Makefile.am (original) +++ trunk/cluster/agents/Makefile.am Wed Jun 15 05:14:10 2011 @@ -2,6 +2,7 @@
agent_SCRIPTS = ag_openais
-scrconf_DATA = openais.scr +scrconf_DATA = openais.scr \ + csync2_ha.scr
EXTRA_DIST = $(agent_SCRIPTS) $(scrconf_DATA)
Modified: trunk/cluster/src/Cluster.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/src/Cluster.ycp?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/src/Cluster.ycp (original) +++ trunk/cluster/src/Cluster.ycp Wed Jun 15 05:14:10 2011 @@ -42,6 +42,9 @@ import "PackageSystem"; import "SuSEFirewall";
+ +global string csync2_key_file = "/etc/csync2/key_hagroup"; + /** * Prototypes */ @@ -233,6 +236,30 @@ SCR::Write(.openais, ""); }
+global list<string> csync2_host = []; +global list<string> csync2_include = []; + +global void load_csync2_conf() +{ + csync2_host = (list<string>)SCR::Read(.csync2_ha.value.ha_group.host); + csync2_include = (list<string>)SCR::Read(.csync2_ha.value.ha_group.include); + + if (csync2_host == nil) csync2_host = []; + if (csync2_include == nil) csync2_include = []; + y2milestone("read csync2 conf: csync2_host = %1", csync2_host); + y2milestone("read csync2 conf: csync2_include = %1", csync2_include); +} + +global void save_csync2_conf() +{ + y2milestone("write csync2 conf: csync2_host = %1", csync2_host); + y2milestone("write csync2 conf: csync2_include = %1", csync2_include); + + SCR::Write(.csync2_ha.value.ha_group.host, csync2_host); + SCR::Write(.csync2_ha.value.ha_group.include, csync2_include); + SCR::Write(.csync2_ha.value.ha_group.key, [csync2_key_file]); +} + /** * Read all cluster settings * @return true on success @@ -271,7 +298,7 @@ );
boolean ret = false; - list<string> required_pack_list = ["pacemaker", "pacemaker-pygui"]; + list<string> required_pack_list = ["pacemaker", "pacemaker-pygui", "csync2"]; ret = PackageSystem::CheckAndInstallPackagesInteractive(required_pack_list); if (ret == false) { Report::Error(_("Cannot install required package")); @@ -295,6 +322,7 @@ if(false) Report::Error(_("Cannot read database1.")); sleep(sl);
+ load_csync2_conf();
Please keep the established indentation rules: four columns per level, \t is 8 columns wide, preferably use 8 spaces instead.
// read another database if(Abort()) return false; Progress::NextStep(); @@ -385,6 +413,8 @@ SuSEFirewall::AddService(mcastport2, "UDP", "EXT"); }
+ save_csync2_conf(); + // run SuSEconfig SuSEFirewall::Write(); if(Abort()) return false;
Modified: trunk/cluster/src/common.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/src/common.ycp?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/src/common.ycp (original) +++ trunk/cluster/src/common.ycp Wed Jun 15 05:14:10 2011 @@ -14,7 +14,8 @@ list<string> DIALOG = [ "communication", "security", - "service" + "service", + "csync2" ];
map PARENT = $[ @@ -23,7 +24,8 @@ map NAME = $[ "communication": _("Communication Channels"), "security": _("Security"), - "service": _("Service") + "service": _("Service"), + "csync2": _("Configure Csync2") ];
void myHelp(string help)
Modified: trunk/cluster/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/src/dialogs.ycp?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/src/dialogs.ycp (original) +++ trunk/cluster/src/dialogs.ycp Wed Jun 15 05:14:10 2011 @@ -45,6 +45,32 @@ include "cluster/helps.ycp"; include "cluster/common.ycp";
+list<string> csync2_suggest_files = []; +string csync2_port = "30865"; + +// return `cacel or a string +any text_input_dialog(string title, string value) +{ + any ret = nil; + + UI::OpenDialog( + `MarginBox(1, 1, `VBox( + `MinWidth(100, `TextEntry(`id(`text), title, value)), + `VSpacing(1), + `Right(`HBox( + `PushButton(`id(`ok), _("OK")), + `PushButton(`id(`cancel), _("Cancel")) + )) + )) + ); + + ret = UI::UserInput(); + if (ret == `ok) ret = UI::QueryWidget(`text, `Value); + UI::CloseDialog(); + return ret; +}
We should move this to Popup::TextEntry, improving it to return a string (nil on cancel). (really we don't have this already somewhere?)
+ + boolean ValidateCommunication () { if (IP::Check((string)UI::QueryWidget(`id(`bindnetaddr1), `Value)) == false) { @@ -554,6 +580,230 @@ return ret; }
+ +term csync2_layout() +{ + return + `VBox(`opt(`hvstretch), + `HBox( + `Frame(_("Sync Host"), + `VBox( + `SelectionBox(`id(`host_box), ""), + `HBox( + `PushButton(`id(`host_add), "Add"), + `PushButton(`id(`host_del), "Del"), + `PushButton(`id(`host_edit), "Edit") + ) + )), + `HSpacing(), + `Frame(_("Sync File"), + `VBox( + `SelectionBox(`id(`include_box), ""), + `HBox( + `PushButton(`id(`include_add), "Add"), + `PushButton(`id(`include_del), "Del"), + `PushButton(`id(`include_edit), "Edit"), + `PushButton(`id(`include_suggest), "Add Suggested Files")
Translation marks missing
+ ) + )) + ), + `HBox( + `PushButton(`id(`generate_key), `opt(`hstretch), _("Generate Pre-Shared-Keys")), + `PushButton(`id(`csync2_switch), `opt(`hstretch), "") + ) + ); +} + + +// return 1 if csync2 is not installed well +// return 2 if csync2 is OFF +// return 3 if csync2 is ON
wow. how about boolean: nil, false, true?
+integer csync2_status() +{ + map ret = nil; + + ret = (map)SCR::Execute(.target.bash_output, "/sbin/chkconfig csync2");
see Service::Enabled
+ y2milestone("chkconfig csync2 = %1", ret); + if (issubstring(ret["stderr"]:"", "command not found") == true) return 1; + if (issubstring(ret["stderr"]:"", "unknown service") == true) return 1; + if (issubstring(ret["stdout"]:"", "off") == true) return 2; + + return 3; +} + +void csync2_turn_off() +{ + SCR::Execute(.target.bash_output, "/sbin/chkconfig csync2 off");
Service::Disable
+ if (SuSEFirewall::HaveService(csync2_port, "TCP", "EXT")) + SuSEFirewall::RemoveService(csync2_port, "TCP", "EXT"); +} + +void csync2_turn_on() +{ + SCR::Execute(.target.bash_output, "/sbin/chkconfig csync2 on");
Service::Enable
+ if (!SuSEFirewall::HaveService(csync2_port, "TCP", "EXT")) + SuSEFirewall::AddService(csync2_port, "TCP", "EXT"); +} + +void fill_csync_entries() +{ + integer i = 0; + integer ret = 0; + integer current = 0; + list<term> items = []; + + // remove duplicated elements + Cluster::csync2_host = Cluster::csync2_host + []; + Cluster::csync2_include = Cluster::csync2_include + []; + + i = 0; + items = []; + foreach(string value, Cluster::csync2_host, { + items = add(items, `item(`id(i), value)); + i = i + 1; + }); + current = (integer)UI::QueryWidget(`host_box, `CurrentItem); + if (current == nil) current = 0; + if (current >= i) current = i - 1; + UI::ChangeWidget(`host_box, `Items, items); + UI::ChangeWidget(`host_box, `CurrentItem, current); + + i = 0; + items = []; + foreach(string value, Cluster::csync2_include, { + items = add(items, `item(`id(i), value)); + i = i + 1; + }); + current = (integer)UI::QueryWidget(`include_box, `CurrentItem); + if (current == nil) current = 0; + if (current >= i) current = i - 1; + UI::ChangeWidget(`include_box, `Items, items); + UI::ChangeWidget(`include_box, `CurrentItem, current); + + ret = csync2_status(); + UI::ChangeWidget(`id(`csync2_switch), `Enabled, (ret != 1)); + if (ret == 1) + UI::ChangeWidget(`id(`csync2_switch), `Label, "Csync2 Status Unknown"); + if (ret == 2) + UI::ChangeWidget(`id(`csync2_switch), `Label, "Turn csync2 ON"); + if (ret == 3) + UI::ChangeWidget(`id(`csync2_switch), `Label, "Turn csync2 OFF");
_() missing
+} + + +any Csync2Dialog() +{ + any ret = nil; + + my_SetContents("csync2", csync2_layout()); + + + while(true) { + fill_csync_entries(); + + ret = UI::UserInput(); + + if (ret == `abort || ret == `cancel) { + if (ReallyAbort()) break; + continue; + } + + if (ret == `next || ret == `back) { + break; + } + + if (ret == `wizardTree) + ret = (string)UI::QueryWidget(`id(`wizardTree), `CurrentItem); + + if (contains(DIALOG, (string)ret)) { + ret = symbolof(toterm(ret)); + //SaveCsync2(); + break; + } else { + Wizard::SelectTreeItem("csync2"); + continue; + } + + if (ret == `host_add) { + ret = text_input_dialog(_("Input a new host"), ""); + if (ret == `cancel) continue; + Cluster::csync2_host = add(Cluster::csync2_host, (string)ret); + } + + if (ret == `host_edit) { + integer current = 0; + string str = ""; + + current = (integer)UI::QueryWidget(`host_box, `CurrentItem); + ret = text_input_dialog(_("Edit a host"), Cluster::csync2_host[current]:""); + if (ret == `cancel) continue; + Cluster::csync2_host[current] = (string)ret; + } + + if (ret == `host_del) { + integer current = 0; + current = (integer)UI::QueryWidget(`host_box, `CurrentItem); + Cluster::csync2_host = remove(Cluster::csync2_host, current); + } + + if (ret == `include_add) { + ret = text_input_dialog(_("Input a new sync file"), ""); + if (ret == `cancel) continue; + Cluster::csync2_include = add(Cluster::csync2_include, (string)ret); + } + + if (ret == `include_edit) { + integer current = 0; + + current = (integer)UI::QueryWidget(`include_box, `CurrentItem); + ret = text_input_dialog(_("Edit a sync file"), Cluster::csync2_include[current]:""); + if (ret == `cancel) continue; + Cluster::csync2_include[current] = (string)ret; + } + + if (ret == `include_del) { + integer current = 0; + current = (integer)UI::QueryWidget(`include_box, `CurrentItem); + Cluster::csync2_include = remove(Cluster::csync2_include, current); + } + + if (ret == `include_suggest) { + Cluster::csync2_include = Cluster::csync2_include + csync2_suggest_files; + } + + if (ret == `generate_key) { + string key_file = Cluster::csync2_key_file; + + // key file exist + if (SCR::Read(.target.size, key_file) > 0) { + if (!Popup::YesNo(sformat(_("Key file %1 already exist.\nDo you want to overwrite it?"), key_file))) + continue; + + // remove exist key file + if (SCR::Execute(.target.remove, key_file) == false) { + Popup::Message(sformat(_("Delete key file %1 failed."), key_file)); + continue; + } + } + + // generate key file + ret = SCR::Execute(.target.bash, sformat("csync2 -k %1", key_file)); + if (ret == 0) + Popup::Message(sformat(_("Key file %1 is generated.\nPlease copy this file to all members of the cluster."), key_file)); + else + Popup::Message("Key generation failed.");
_()
+ } + + if (ret == `csync2_switch) { + string label = ""; + label = (string)UI::QueryWidget(`csync2_switch, `Label); + if (issubstring(label, "OFF")) csync2_turn_off(); + if (issubstring(label, "ON")) csync2_turn_on(); + } + } + + return ret; +} /* EOF */ }
Modified: trunk/cluster/src/helps.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/src/helps.ycp?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/src/helps.ycp (original) +++ trunk/cluster/src/helps.ycp Wed Jun 15 05:14:10 2011 @@ -50,6 +50,13 @@ <p><b><big>Booting</big></b><br>Starting openais service during boot or not</p> <p><b><big>Start mgmtd</big></b><br>Mgmtd daemon is a standalone service daemon. It is required by the GUI</p> "), + + "csync2" : _(" + <p><b><big>Sync Host</big></b><br>The hostnames used here must be the local hostnames of the cluster nodes. That means you must use exactly the same string as printed out by the hostname command.</p> + <p><b><big>Sync File</big></b><br>The full absolute filename to be synced.</p> + <p><b><big>Pre-Shared-Keys</big></b><br>Authentication is performed using the IP addresses and pre-shared-keys in Csync2. The key file is generated with csync2 -k /etc/csync2/key_hagroup. The file key_hagroup should be copied to all members of the cluster manually after it's created.</p> + "), + /* Read dialog help 1/2 */ "read" : _("<p><b><big>Initializing cluster Configuration</big></b><br> Please wait...<br></p>
Modified: trunk/cluster/src/wizards.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/cluster/src/wizards.ycp?rev=64362&r1=64361&r2=64362&view=diff ============================================================================== --- trunk/cluster/src/wizards.ycp (original) +++ trunk/cluster/src/wizards.ycp Wed Jun 15 05:14:10 2011 @@ -41,7 +41,8 @@ map Aliases = $[ "communication": ``(CommunicationDialog()), "security": ``(SecurityDialog()), - "service": ``(ServiceDialog()) + "service": ``(ServiceDialog()), + "csync2": ``(Csync2Dialog()) ];
@@ -86,7 +87,8 @@ "ws_start" : "communication", "communication": $[ `next:"security", `back:"communication", `abort:`abort ], "security": $[ `next:"service", `back:"communication", `abort:`abort ], - "service": $[ `next:`next, `back:"security", `abort:`abort ], + "service": $[ `next:"csync2", `back:"security", `abort:`abort ], + "csync2" : $[ `next:`next, `back:"service", `abort:`abort ], ];
any ret = Sequencer::Run(Aliases, sequence);
-- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
-- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
participants (1)
-
Martin Vidner