[yast-commit] r40655 - in /trunk/ntp-client/src: Makefile.am NtpClient.ycp dialogs.ycp ntp-client_auto.ycp ntp-client_finish.ycp ntp-client_proposal.ycp widgets.ycp
Author: kmachalkova Date: Fri Aug 31 17:04:20 2007 New Revision: 40655 URL: http://svn.opensuse.org/viewcvs/yast?rev=40655&view=rev Log: New ntp installation client to handle ntp settings in 1st stage added + related changes in r/w functions (FaTE #302192, bugzilla #(#299238,#299557,#302389, #302433) Added: trunk/ntp-client/src/ntp-client_finish.ycp trunk/ntp-client/src/ntp-client_proposal.ycp Modified: trunk/ntp-client/src/Makefile.am trunk/ntp-client/src/NtpClient.ycp trunk/ntp-client/src/dialogs.ycp trunk/ntp-client/src/ntp-client_auto.ycp trunk/ntp-client/src/widgets.ycp Modified: trunk/ntp-client/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/Makefile.am?rev=40655&r1=40654&r2=40655&view=diff ============================================================================== --- trunk/ntp-client/src/Makefile.am (original) +++ trunk/ntp-client/src/Makefile.am Fri Aug 31 17:04:20 2007 @@ -8,7 +8,9 @@ client_DATA = \ ntp-client.ycp \ - ntp-client_auto.ycp + ntp-client_auto.ycp \ + ntp-client_proposal.ycp \ + ntp-client_finish.ycp ynclude_DATA = \ helps.ycp \ Modified: trunk/ntp-client/src/NtpClient.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/NtpClient.ycp?rev=40655&r1=40654&r2=40655&view=diff ============================================================================== --- trunk/ntp-client/src/NtpClient.ycp (original) +++ trunk/ntp-client/src/NtpClient.ycp Fri Aug 31 17:04:20 2007 @@ -58,7 +58,7 @@ /** * Should the daemon be started when system boots? */ -global boolean run_service = false; +global boolean run_service = true; /** * Service name of the NTP daemon @@ -124,6 +124,8 @@ global boolean simple_dialog = false; +global boolean already_proposed = false; + /** * Abort function * @return blah blah lahjk @@ -156,7 +158,7 @@ //workaround bug #241054: servers in United Kingdom are in domain .uk // domain .gb does not exist - add UK to the list of known countries - if (haskey(known_countries, "GB")){ + if (haskey(known_countries, "GB")){ known_countries["UK"] = known_countries["GB"]:""; known_countries = remove(known_countries,"GB"); } @@ -238,9 +240,10 @@ /** * Get list of public NTP servers for a country * @param country two-letter country code + * @param terse_output display additional data (location etc.) * @return list of servers (usable as combo-box items) */ -global list GetNtpServersByCountry ( string country ) { +global list GetNtpServersByCountry ( string country, boolean terse_output ) { map<string,string> country_names = $[]; map<string,map<string,string> > servers = GetNtpServers (); if (country != "") @@ -255,7 +258,7 @@ } list items = maplist (string s, map<string,string> o, servers, { - string label = o["location"]:""; + string label = o["location"]:""; string l_country = o["country"]:""; if (country != "") l_country = ""; @@ -267,7 +270,11 @@ label = s; else label = sformat ("%1 (%2%3)", s, label, l_country); - return `item (`id (s), label); + + if (terse_output) + return `item (`id(s), s); + else + return `item (`id (s), label); }); return items; @@ -275,79 +282,22 @@ } /** - * Read all ntp-client settings + * Read and parse /etc.ntp.conf * @return true on success */ -global define boolean Read() ``{ - - /* NtpClient read dialog caption */ - string caption = _("Initializing NTP Client Configuration"); - - integer steps = 2; - integer sl = 500; - // We do not set help text here, because it was set outside - Progress::New( caption, " ", steps, [ - // progress stage - _("Read network configuration"), - // progress stage - _("Read NTP settings"), - ], [ - // progress step - _("Reading network configuration..."), - // progress step - _("Reading NTP settings..."), - // progress step - _("Finished") - ], - "" - ); - - // read network configuration - if(Abort()) return false; - Progress::NextStage(); +global define boolean ProcessNtpConf() ``{ - boolean progress_orig = Progress::set (false); - NetworkDevices::Read (); - Progress::set (progress_orig); - config_dhcp = tolower ((string)SCR::Read (.sysconfig.network.dhcp.DHCLIENT_MODIFY_NTP_CONF)) == "yes"; - original_config_dhcp = config_dhcp; + map conf = nil; + if (FileUtils::Exists("/etc/ntp.conf")) + conf = (map)SCR::Read (.etc.ntp_conf.all); - GetNtpServers (); - GetCountryNames (); - // read current settings - if(Abort()) return false; - Progress::NextStage(); - - boolean failed = false; - - if (! Mode::testsuite () && ! Mode::installation () - && ! PackageSystem::CheckAndInstallPackagesInteractive (["xntp"]) - ) + if (conf == nil ) { + y2error("Failed to read /etc/ntp.conf, either it doesn't exist or contains no data"); return false; } - run_service = Service::Enabled (service_name); - - //Poke to /var/lib/YaST if there is Active Directory controller address dumped in .ycp file - string ad_ntp_file = Directory::vardir + "/ad_ntp_data.ycp"; - if(FileUtils::Exists(ad_ntp_file)) { - y2milestone("Reading %1", ad_ntp_file); - map <string, string> ad_ntp_data = (map <string, string>) SCR::Read(.target.ycp, ad_ntp_file); - ad_controller = ad_ntp_data["ads"]:""; - if(ad_controller != "") { - y2milestone("Got %1 for ntp sync, deleting %2, since it is no longer needed", ad_controller, ad_ntp_file); - SCR::Execute(.target.remove, ad_ntp_file); - } - } - - - map conf = (map)SCR::Read (.etc.ntp_conf.all); - if (conf == nil) - { - failed = true; - conf = $[]; - } + already_proposed = true; list<map<string, any> > value = conf["value"]:[]; integer index = -1; ntp_records = maplist (map<string, any> m, value, ``{ @@ -424,16 +374,6 @@ return m; }); - run_chroot = SCR::Read (.sysconfig.ntp.NTPD_RUN_CHROOTED) == "yes"; - - string initial_sync = (string)SCR::Read (.sysconfig.ntp.NTPD_INITIAL_NTPDATE); - if (initial_sync == nil) - { - initial_sync = ""; - failed = true; - y2error ("Failed reading .sysconfig.ntp.NTPD_INITIAL_NTPDATE"); - } - // mark local clock to be local clock and not real servers ntp_records = maplist (map<string,any> p, ntp_records, ``{ if (p["type"]:"" == "server" @@ -444,6 +384,89 @@ return p; }); + return true; + +} + +/** + * Read all ntp-client settings + * @return true on success + */ +global define boolean Read() ``{ + + /* NtpClient read dialog caption */ + string caption = _("Initializing NTP Client Configuration"); + + integer steps = 2; + integer sl = 500; + // We do not set help text here, because it was set outside + Progress::New( caption, " ", steps, [ + // progress stage + _("Read network configuration"), + // progress stage + _("Read NTP settings"), + ], [ + // progress step + _("Reading network configuration..."), + // progress step + _("Reading NTP settings..."), + // progress step + _("Finished") + ], + "" + ); + + // read network configuration + if(Abort()) return false; + Progress::NextStage(); + + boolean progress_orig = Progress::set (false); + NetworkDevices::Read (); + Progress::set (progress_orig); + config_dhcp = tolower ((string)SCR::Read (.sysconfig.network.dhcp.DHCLIENT_MODIFY_NTP_CONF)) == "yes"; + original_config_dhcp = config_dhcp; + + GetNtpServers (); + GetCountryNames (); + // read current settings + if(Abort()) return false; + Progress::NextStage(); + + boolean failed = false; + + if (! Mode::testsuite () && ! Mode::installation () + && ! PackageSystem::CheckAndInstallPackagesInteractive (["xntp"]) + ) + { + return false; + } + + run_service = Service::Enabled (service_name); + + //Poke to /var/lib/YaST if there is Active Directory controller address dumped in .ycp file + string ad_ntp_file = Directory::vardir + "/ad_ntp_data.ycp"; + if(FileUtils::Exists(ad_ntp_file)) { + y2milestone("Reading %1", ad_ntp_file); + map <string, string> ad_ntp_data = (map <string, string>) SCR::Read(.target.ycp, ad_ntp_file); + ad_controller = ad_ntp_data["ads"]:""; + if(ad_controller != "") { + y2milestone("Got %1 for ntp sync, deleting %2, since it is no longer needed", ad_controller, ad_ntp_file); + SCR::Execute(.target.remove, ad_ntp_file); + } + } + + ProcessNtpConf(); + + run_chroot = SCR::Read (.sysconfig.ntp.NTPD_RUN_CHROOTED) == "yes"; + + string initial_sync = (string)SCR::Read (.sysconfig.ntp.NTPD_INITIAL_NTPDATE); + if (initial_sync == nil) + { + initial_sync = ""; + failed = true; + y2error ("Failed reading .sysconfig.ntp.NTPD_INITIAL_NTPDATE"); + } + // mark those servers and peers that are used for initial syncing if (initial_sync == "AUTO") { Modified: trunk/ntp-client/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/dialogs.ycp?rev=40655&r1=40654&r2=40655&view=diff ============================================================================== --- trunk/ntp-client/src/dialogs.ycp (original) +++ trunk/ntp-client/src/dialogs.ycp Fri Aug 31 17:04:20 2007 @@ -16,6 +16,7 @@ import "Label"; import "NtpClient"; import "Popup"; +import "Stage"; import "SuSEFirewall"; import "Wizard"; import "Report"; @@ -51,14 +52,22 @@ */ define symbol ReadDialog() ``{ Wizard::RestoreHelp(HELPS["read"]:""); - - // checking for root permissions (#158483) - if (!Confirm::MustBeRoot()) - return `abort; - - NtpClient::AbortFunction = PollAbort; - boolean ret = NtpClient::Read(); - return ret ? `next : `abort; + + if(Stage::initial()) + { + NtpClient::ProcessNtpConf(); + return `next; + } + else + { + // checking for root permissions (#158483) + if (!Confirm::MustBeRoot()) + return `abort; + + NtpClient::AbortFunction = PollAbort; + boolean ret = NtpClient::Read(); + return ret ? `next : `abort; + } } /** @@ -66,6 +75,9 @@ * @return `abort if aborted and `next otherwise */ define symbol WriteDialog() ``{ + if (Stage::initial()) + return `next; + Wizard::RestoreHelp(HELPS["write"]:""); NtpClient::AbortFunction = PollAbort; boolean ret = NtpClient::Write(); Modified: trunk/ntp-client/src/ntp-client_auto.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/ntp-client_auto.ycp?rev=40655&r1=40654&r2=40655&view=diff ============================================================================== --- trunk/ntp-client/src/ntp-client_auto.ycp (original) +++ trunk/ntp-client/src/ntp-client_auto.ycp Fri Aug 31 17:04:20 2007 @@ -87,18 +87,11 @@ else if (func == "Write") { import "Progress"; boolean progress_orig = Progress::set (false); - //restart_service - also do 'rcntpd restart' and trigger time change - //otherwise - only write ntp.conf and stuff (default for autoyast) - if (param["restart_services"]:false == false) - NtpClient::write_only = true; + NtpClient::write_only = true; ret = NtpClient::Write(); Progress::set (progress_orig); } -else if (func == "GetNtpServersByCountry") { - string cc = param["country"]:NtpClient::GetCurrentLanguageCode(); - ret = NtpClient::GetNtpServersByCountry( cc ); -} /* Unknown function */ else { y2error("Unknown function: %1", func); Added: trunk/ntp-client/src/ntp-client_finish.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/ntp-client_finish.ycp?rev=40655&view=auto ============================================================================== --- trunk/ntp-client/src/ntp-client_finish.ycp (added) +++ trunk/ntp-client/src/ntp-client_finish.ycp Fri Aug 31 17:04:20 2007 @@ -0,0 +1,58 @@ +/** + * File: clients/ntp-client_finish.ycp + * Summary: Installation client for writing ntp configuration + * at the end of 1st stage + * Author: Bubli <kmachalkova@suse.cz> + * + */ +{ +textdomain "ntp-client"; + +import "NtpClient"; + +any ret = nil; +string func = ""; +map param = $[]; + +/* Check arguments */ +if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) { + func = (string)WFM::Args(0); + if(size(WFM::Args()) > 1 && is(WFM::Args(1), map)) + param = (map)WFM::Args(1); +} + +y2milestone ("starting ntp-client_finish"); +y2debug("func=%1", func); +y2debug("param=%1", param); + +if (func == "Info") +{ + return (any)$[ + "steps" : 1, + // progress step title + "title" : _("Writing NTP Configuration..."), + "when" : [ `installation, `autoinst ], + ]; +} +else if (func == "Write") +{ + map ex = NtpClient::Export(); + + NtpClient::Read(); + + NtpClient::Import( ex ); + + NtpClient::Write(); + +} +else +{ + y2error ("unknown function: %1", func); + ret = nil; +} + +y2debug("ret=%1", ret); +y2milestone("ntp-client_finish finished"); +return ret; + +} Added: trunk/ntp-client/src/ntp-client_proposal.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/ntp-client_proposal.ycp?rev=40655&view=auto ============================================================================== --- trunk/ntp-client/src/ntp-client_proposal.ycp (added) +++ trunk/ntp-client/src/ntp-client_proposal.ycp Fri Aug 31 17:04:20 2007 @@ -0,0 +1,168 @@ +/** + * File: clients/ntp-client_proposal.ycp + * Summary: Installation client for ntp configuration + * Author: Bubli <kmachalkova@suse.cz> + * + */ + +{ +textdomain "ntp-client"; + +import "Hostname"; +import "NetworkService"; +import "NtpClient"; +import "Service"; +import "String"; +import "Stage"; +import "Package"; +import "Pkg"; + +y2milestone("----------------------------------------"); +y2milestone("Ntp client proposal started"); +y2milestone("Arguments: %1", WFM::Args()); + +any ret = nil; +string func = ""; +map param = $[]; + +if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) { + func = (string)WFM::Args(0); + if(size(WFM::Args()) > 1 && is(WFM::Args(1), map)) + param = (map)WFM::Args(1); +} + +void ProposeSomething() +{ + list ntp_items = []; + if( NtpClient::already_proposed || NtpClient::ProcessNtpConf() ) + { + ntp_items = maplist(string server, NtpClient::GetUsedNtpServers(),{ + return `item(`id(server), server); + }); + } + if( ntp_items == []) + { + string cc = param["country"]:NtpClient::GetCurrentLanguageCode(); + y2milestone("Nothing found in /etc/ntp.conf, proposing current language-based NTP server list"); + ntp_items = NtpClient::GetNtpServersByCountry( cc, true ); + NtpClient::already_proposed = true; + } + UI::ChangeWidget(`id(`ntp_address), `Items, ntp_items); + +} + +void AddSingleServer( string server ) +{ + NtpClient::selected_record["address"] = server; + NtpClient::selected_record["type"] = "server"; + NtpClient::storeSyncRecord(); +} + +if (func == "CreateUI") +{ + term cont = + `Left (`VBox ( `id(`ntp_content), + `Left (`RadioButton (`id (`ntp), `opt (`notify), + // radio button label + _("Synchronize with NTP Server"), false) + ), + `VSpacing (0.5), + `HBox ( + `HSpacing (3), + `MinWidth (38, + `ComboBox (`id (`ntp_address), `opt (`editable), + // combo box label + _("NTP Server Address") + ) + ), + `VBox ( + `Label (""), + // push button label + `PushButton (`id (`ntp_configure), _("Configure...")) + ) + ) + )); + + if (UI::WidgetExists(`id(`rp))) + { + UI::ReplaceWidget(`id(`rp), cont); + + if (!NetworkService::isNetworkRunning()) + { + y2warning("Network is not running, NTP synchronization will not be available"); + UI::ChangeWidget(`id(`ntp_content), `Enabled, false); + } + + //does not really work ideally, need something better pkg binding :( + if (!Package::Available("xntp")) + { + y2warning("xntp package is not installable, NTP synchronization will not be available"); + UI::ChangeWidget(`id(`ntp_content), `Enabled, false); + } + } + + ret = true; +} + +else if (func == "MakeProposal") +{ + ProposeSomething(); + ret = true; +} + +else if (func == "Write") +{ + string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value); + if (!Hostname::CheckFQ(ntp_server)) + { + UI::SetFocus(`id(`ntp_address)); + ret = `invalid_hostname; + } + else + { + y2milestone("Running ntpdate to sync with %1", ntp_server); + + integer status = 0; + string service_name = "ntp"; + + //Stop NTP service on running system (during 1st stage, we don't care) + if( !Stage::initial() && status == 0) + { + Service::Stop(service_name); + } + + //Schedule package for installation + Pkg::PkgInstall("xntp"); + + integer r = (integer) SCR::Execute (.target.bash, sformat ("/usr/sbin/ntpdate '%1'", String::Quote(ntp_server))); + y2milestone ("'ntpdate %1' returned %2", ntp_server, r); + + if( !Stage::initial() && status == 0) + { + Service::Start(service_name); + } + + if (r == 0) + { + ret = `success; + AddSingleServer(ntp_server); + } + else + ret = `ntpdate_failed; + } +} + +else if (func == "AskUser") +{ + string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value); + AddSingleServer(ntp_server); + ret = (symbol) WFM::CallFunction("ntp-client"); + ProposeSomething(); +} + +y2milestone("Ntp client proposal finished"); +y2milestone("----------------------------------------"); +return ret; +} + + Modified: trunk/ntp-client/src/widgets.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/widgets.ycp?rev=40655&r1=40654&r2=40655&view=diff ============================================================================== --- trunk/ntp-client/src/widgets.ycp (original) +++ trunk/ntp-client/src/widgets.ycp Fri Aug 31 17:04:20 2007 @@ -887,7 +887,7 @@ { last_country = country; - list items = NtpClient::GetNtpServersByCountry ( country); + list items = NtpClient::GetNtpServersByCountry ( country, false); UI::ReplaceWidget (`servers_rp, `VBox( // Combobox has at least 40 characters -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
kmachalkova@svn.opensuse.org