Author: jsuchome
Date: Fri Apr 20 17:28:41 2012
New Revision: 67977
URL: http://svn.opensuse.org/viewcvs/yast?rev=67977&view=rev
Log:
enhanced workflow: showing list of lxc
moving code to module
still WIP
Added:
branches/SuSE-Code-11-SP2-Branch/lxc/src/wizards.ycp (with props)
Modified:
branches/SuSE-Code-11-SP2-Branch/lxc/src/Lxc.ycp
branches/SuSE-Code-11-SP2-Branch/lxc/src/Makefile.am
branches/SuSE-Code-11-SP2-Branch/lxc/src/dialogs.ycp
branches/SuSE-Code-11-SP2-Branch/lxc/src/lxc.ycp
Modified: branches/SuSE-Code-11-SP2-Branch/lxc/src/Lxc.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/lxc/src/Lxc.ycp?rev=67977&r1=67976&r2=67977&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/lxc/src/Lxc.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/lxc/src/Lxc.ycp Fri Apr 20 17:28:41 2012
@@ -36,106 +36,76 @@
textdomain "lxc";
import "Progress";
-import "Report";
-import "Summary";
-import "Message";
+import "Security";
-/**
- * Prototypes
- */
-global boolean Modified();
-
-/**
- * Data was modified?
- */
-boolean modified = false;
-
-/**
- */
-boolean proposal_valid = false;
-
-/**
- * Write only, used during autoinstallation.
- * Don't run services and SuSEconfig, it's all done at one place.
- */
-boolean write_only = false;
-/**
- * Abort function
- * return boolean return true if abort
- */
-boolean() AbortFunction = Modified;
+// text or graphic mode?
+global boolean textmode = false;
-/**
- * Abort function
- * @return boolean return true if abort
- */
-global define boolean Abort() ``{
- if(AbortFunction != nil)
- {
- return AbortFunction () == true;
- }
- return false;
-}
+// current password encryption method
+string method = "des";
-/**
- * Data was modified?
- * @return true if modified
- */
-global boolean Modified() {
- y2debug("modified=%1",modified);
- return modified;
-}
-
-/**
- * Mark as modified, for Autoyast.
- */
-global void SetModified(boolean value) {
- modified = true;
+// read list of available templates
+global list<term> ReadTemplates () {
+
+ list<term> ret = [];
+ map out = (map) SCR::Execute (.target.bash_output, "rpm -ql lxc | grep 'templates/' | cut -f 2 -d -");
+ if (out["stdout"]:"" != "")
+ {
+ foreach (string line, sort (splitstring (out["stdout"]:"", "\n")), {
+ if (line != "")
+ {
+ ret = add (ret,
+ // sles goes later = selected if present
+ `item (line, line == "sles" || line == "opensuse"));
+ }
+ });
}
-
-global boolean ProposalValid() {
- return proposal_valid;
+ return ret;
}
-global void SetProposalValid(boolean value) {
- proposal_valid = value;
-}
+// encrypt given password using current method
+global string CryptPassword (string pw) {
-/**
- * @return true if module is marked as "write only" (don't start services etc...)
- */
-global boolean WriteOnly() {
- return write_only;
+ if (method == "md5")
+ return cryptmd5 (pw);
+ if (method == "blowfish")
+ return cryptblowfish (pw);
+ if (method == "sha256")
+ return cryptsha256 (pw);
+ if (method == "sha512")
+ return cryptsha512 (pw);
+ return crypt (pw);
}
-/**
- * Set write_only flag (for autoinstalation).
- */
-global void SetWriteOnly(boolean value) {
- write_only = value;
-}
+global list<string> ReadBridgesIds () {
+ map out = (map) SCR::Execute (.target.bash_output, "brctl show | tail -n +2 | cut -f 1");
+ list<string> ret = [];
-global void SetAbortFunction(boolean() function) {
- AbortFunction = function;
+ if (out["stdout"]:"" != "")
+ {
+ ret = maplist (string line, splitstring (out["stdout"]:"", "\n"), ``(line));
+ }
+ return ret;
}
+global list<term> GetContainers () {
-// Settings: Define all variables needed for configuration of lxc
-// TODO FIXME: Define all the variables necessary to hold
-// TODO FIXME: the configuration here (with the appropriate
-// TODO FIXME: description)
-// TODO FIXME: For example:
-// /**
-// * List of the configured cards.
-// */
-// list cards = [];
-//
-// /**
-// * Some additional parameter needed for the configuration.
-// */
-// boolean additional_parameter = true;
+ list<term> ret = [];
+ map out = (map) SCR::Execute (.target.bash_output, "lxc-ls -1");
+out["stdout"] = "suse1\nsles\n";
+ foreach (string line, sort (splitstring (out["stdout"]:"", "\n")), {
+ if (line != "")
+ {
+ string cmd= sformat ("lxc-info -n %1 | grep state", line);
+ out = (map) SCR::Execute (.target.bash_output, cmd, $[ "LANG" : "C" ]);
+ // FIXME read status
+ ret = add (ret, `item (line, _("Stopped")));
+ }
+ });
+ return ret;
+}
/**
* Read all lxc settings
@@ -144,180 +114,49 @@
global boolean Read() {
/* Lxc read dialog caption */
- string caption = _("Initializing lxc Configuration");
-
- // TODO FIXME Set the right number of stages
- integer steps = 4;
+ string caption = _("Initializing LXC Configuration");
- integer sl = 500;
- sleep(sl);
+ integer steps = 2;
- // TODO FIXME Names of real stages
// We do not set help text here, because it was set outside
Progress::New( caption, " ", steps, [
- /* Progress stage 1/3 */
- _("Read the database"),
- /* Progress stage 2/3 */
- _("Read the previous settings"),
- /* Progress stage 3/3 */
- _("Detect the devices")
+ // Progress stage
+ _("Check LXC availability"),
+ // Progress stage
+ _("Read system settings"),
], [
- /* Progress step 1/3 */
- _("Reading the database..."),
- /* Progress step 2/3 */
- _("Reading the previous settings..."),
- /* Progress step 3/3 */
- _("Detecting the devices..."),
- /* Progress finished */
+ // Progress step
+ _("Check LXC availability..."),
+ // Progress step
+ _("Reading system settings..."),
+ // Progress finished
_("Finished")
],
""
);
- // read database
- if(Abort()) return false;
- Progress::NextStage();
- /* Error message */
- if(false) Report::Error(_("Cannot read database1."));
- sleep(sl);
-
- // read another database
- if(Abort()) return false;
- Progress::NextStep();
- /* Error message */
- if(false) Report::Error(_("Cannot read database2."));
- sleep(sl);
- // read current settings
- if(Abort()) return false;
Progress::NextStage();
- /* Error message */
- if(false) Report::Error(Message::CannotReadCurrentSettings());
- sleep(sl);
- // detect devices
- if(Abort()) return false;
- Progress::NextStage();
- /* Error message */
- if(false) Report::Warning(_("Cannot detect devices."));
- sleep(sl);
+ // FIXME run lxc-checkconfig at start
- if(Abort()) return false;
- /* Progress finished */
Progress::NextStage();
- sleep(sl);
- if(Abort()) return false;
- modified = false;
- return true;
-}
+ boolean orig = Progress::set (false);
-/**
- * Write all lxc settings
- * @return true on success
- */
-global boolean Write() {
+ Security::Read ();
- /* Lxc read dialog caption */
- string caption = _("Saving lxc Configuration");
+ Progress::set (orig);
- // TODO FIXME And set the right number of stages
- integer steps = 2;
+ map security = Security::Export ();
+ method = tolower (security["PASSWD_ENCRYPTION"]:"des");
- integer sl = 500;
- sleep(sl);
+ textmode = UI::GetDisplayInfo()["TextMode"]:false;
- // TODO FIXME Names of real stages
- // We do not set help text here, because it was set outside
- Progress::New(caption, " ", steps, [
- /* Progress stage 1/2 */
- _("Write the settings"),
- /* Progress stage 2/2 */
- _("Run SuSEconfig")
- ], [
- /* Progress step 1/2 */
- _("Writing the settings..."),
- /* Progress step 2/2 */
- _("Running SuSEconfig..."),
- /* Progress finished */
- _("Finished")
- ],
- ""
- );
-
- // write settings
- if(Abort()) return false;
Progress::NextStage();
- /* Error message */
- if(false) Report::Error (_("Cannot write settings."));
- sleep(sl);
-
- // run SuSEconfig
- if(Abort()) return false;
- Progress::NextStage ();
- /* Error message */
- if(false) Report::Error (Message::SuSEConfigFailed());
- sleep(sl);
-
- if(Abort()) return false;
- /* Progress finished */
- Progress::NextStage();
- sleep(sl);
-
- if(Abort()) return false;
- return true;
-}
-/**
- * Get all lxc settings from the first parameter
- * (For use by autoinstallation.)
- * @param settings The YCP structure to be imported.
- * @return boolean True on success
- */
-global boolean Import (map settings) {
- // TODO FIXME: your code here (fill the above mentioned variables)...
return true;
}
-/**
- * Dump the lxc settings to a single map
- * (For use by autoinstallation.)
- * @return map Dumped settings (later acceptable by Import ())
- */
-global map Export () {
- // TODO FIXME: your code here (return the above mentioned variables)...
- return $[];
-}
-
-/**
- * Create a textual summary and a list of unconfigured cards
- * @return summary of the current configuration
- */
-global list Summary() {
- // TODO FIXME: your code here...
- /* Configuration summary text for autoyast */
- return [ _("Configuration summary..."), [] ];
-}
-
-/**
- * Create an overview table with all configured cards
- * @return table items
- */
-global list Overview() {
- // TODO FIXME: your code here...
- return [];
-}
-
-/**
- * Return packages needed to be installed and removed during
- * Autoinstallation to insure module has all needed software
- * installed.
- * @return map with 2 lists.
- */
-global map AutoPackages() {
- // TODO FIXME: your code here...
- return $[ "install":[], "remove":[] ];
-}
-
/* EOF */
}
Modified: branches/SuSE-Code-11-SP2-Branch/lxc/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/lxc/src/Makefile.am?rev=67977&r1=67976&r2=67977&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/lxc/src/Makefile.am (original)
+++ branches/SuSE-Code-11-SP2-Branch/lxc/src/Makefile.am Fri Apr 20 17:28:41 2012
@@ -6,6 +6,7 @@
lxc.ycp
ynclude_DATA = \
+ wizards.ycp \
dialogs.ycp
desktop_DATA = \
Modified: branches/SuSE-Code-11-SP2-Branch/lxc/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/lxc/src/dialogs.ycp?rev=67977&r1=67976&r2=67977&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/lxc/src/dialogs.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/lxc/src/dialogs.ycp Fri Apr 20 17:28:41 2012
@@ -41,67 +41,16 @@
import "Wizard";
-list<term> read_templates () {
-
- list<term> ret = [];
- map out = (map) SCR::Execute (.target.bash_output, "rpm -ql lxc | grep 'templates/' | cut -f 2 -d -");
- if (out["stdout"]:"" != "")
- {
- foreach (string line, splitstring (out["stdout"]:"", "\n"), {
- if (line != "")
- {
- ret = add (ret, `item (line, line == "sles"));
- }
- });
- }
- return ret;
-}
-
-// encrypt given password using current method
-string crypt_password (string pw, string method) {
-
- if (method == "md5")
- return cryptmd5 (pw);
- if (method == "blowfish")
- return cryptblowfish (pw);
- if (method == "sha256")
- return cryptsha256 (pw);
- if (method == "sha512")
- return cryptsha512 (pw);
- return crypt (pw);
-}
-
-list<string> read_bridges_ids () {
-
- map out = (map) SCR::Execute (.target.bash_output, "brctl show | tail -n +2 | cut -f 1");
- list<string> ret = [];
-
- if (out["stdout"]:"" != "")
- {
- ret = maplist (string line, splitstring (out["stdout"]:"", "\n"), ``(line));
- }
- return ret;
-}
-
/**
- * Configure1 dialog
+ * Adding new Linux Container
* @return dialog result
*/
-any LxcDialog () {
-
- boolean orig = Progress::set (false);
- Security::Read ();
- Progress::set (orig);
+any AddDialog () {
- map security = Security::Export ();
- string method = tolower (security["PASSWD_ENCRYPTION"]:"des");
-
- boolean textmode = UI::GetDisplayInfo()["TextMode"]:false;
-
- /* Lxc configure1 dialog caption */
- string caption = _("LXC Configuration");
+ // add dialog caption
+ string caption = _("Adding New Container");
- list<term> template_items = read_templates ();
+ list<term> template_items = Lxc::ReadTemplates ();
term contents = `HBox (`HSpacing (), `VBox (
`VSpacing (),
@@ -124,7 +73,7 @@
`TextEntry (`id (`subnet), _("Subnet"), "/24"),
`ReplacePoint (`id (`rp_lan),
// combo box label
- `ComboBox (`id (`bridge), _("Bridge"), read_bridges_ids ())
+ `ComboBox (`id (`bridge), _("Bridge"), Lxc::ReadBridgesIds ())
)
),
`VSpacing (0.5),
@@ -149,39 +98,23 @@
`ReplacePoint (`id (`rp_status),
`Label (`id (`status), "")
),
- `VSpacing (),
- `HBox (
- // button label
- `PushButton (`id (`create), _("Create")),
- `ReplacePoint (`id (`rpbutton),
- // button label
- `PushButton (`id (`start), _("Start"))
- ),
- // button label
- `PushButton (`id (`destroy), _("Destroy"))
- )
+ `VSpacing ()
), `HSpacing ());
string help_text = "";
- Wizard::CreateDialog();
Wizard::SetContentsButtons(caption, contents, help_text,
- Label::BackButton(), Label::CloseButton());
- Wizard::HideBackButton ();
- Wizard::HideAbortButton ();
+ // button label
+ Label::CancelButton(), _("Create"));
UI::ChangeWidget (`id (`ip), `ValidChars, IP::ValidChars4);
- foreach (any b, [ `start, `destroy ], {
- UI::ChangeWidget (`id (b), `Enabled, false);
- });
-
any ret = nil;
while(true) {
ret = UI::UserInput();
- if (ret == `abort || ret == `cancel || ret == `next || ret == `back) {
+ if (ret == `abort || ret == `cancel || ret == `back) {
break;
}
@@ -192,7 +125,7 @@
{
UI::ReplaceWidget (`id (`rp_lan),
// combo box label
- `ComboBox (`id (`bridge), _("Bridge"), read_bridges_ids ())
+ `ComboBox (`id (`bridge), _("Bridge"), Lxc::ReadBridgesIds ())
);
}
continue;
@@ -228,7 +161,7 @@
continue;
}
- if (ret == `create)
+ if (ret == `next)
{
// busy message
Popup::ShowFeedback ("", _("Creating Configuration..."));
@@ -303,7 +236,7 @@
// busy message
Popup::ShowFeedback ("", _("Saving Root Password..."));
- string password = crypt_password (pw1, method);
+ string password = Lxc::CryptPassword (pw1);
string file = sformat ("/var/lib/lxc/%1/rootfs/etc/shadow", name);
if (pw1 != "" && FileUtils::Exists (file))
@@ -316,34 +249,30 @@
y2security ("out: %1", out);
}
Popup::ClearFeedback ();
- foreach (any t, [ `create, `name, `ip, `subnet, `bridge, `lan, `template, `pw1, `pw2 ], {
- UI::ChangeWidget (`id (t), `Enabled, false);
- });
- UI::ChangeWidget (`id (`start), `Enabled, true);
- UI::ChangeWidget (`id (`destroy), `Enabled, true);
- UI::ReplaceWidget (`id (`rp_status),
- // status text
- `Label (`id (`status), sformat (_("Container '%1' was successfully created."), name))
- );
- continue;
+ Popup::Message (sformat (_("Container '%1' was successfully created."), name));
+ break;
}
- if (ret == `start)
- {
+ }
+ return ret;
+}
+
+
+void StartContainer (string name)
+{
string cmd = sformat ("xterm -e lxc-start -n %1", name);
- if (textmode)
+ if (Lxc::textmode)
{
cmd = sformat ("lxc-start -d -n %1", name);
}
- UI::ReplaceWidget (`id (`rp_status), `Label (`id (`status), ""));
-
integer id = (integer) SCR::Execute (.process.start_shell, cmd);
+ /*
UI::ReplaceWidget (`id (`rpbutton),
`PushButton (`id (`cancel), Label::CancelButton ())
);
- UI::ChangeWidget (`id (`destroy), `Enabled, false);
- if (textmode)
+ */
+ if (Lxc::textmode)
{
// message
Popup::Message (sformat (_("The Container '%1' was started in the background.
@@ -356,7 +285,8 @@
{
break;
}
- if (ui == `cancel)
+// FIXME nothing else could be clicked now, closing YaST probably means killing all bg processes
+ if (ui == `stop)
{
y2internal ("lxc-stop: %1",
SCR::Execute (.target.bash_output, "lxc-stop -n " + name)
@@ -364,50 +294,105 @@
break;
}
}
- UI::ChangeWidget (`id (`destroy), `Enabled, true);
- UI::ReplaceWidget (`id (`rpbutton),
- `PushButton (`id (`start), _("Start"))
- );
- continue;
- }
- if (ret == `destroy)
- {
- UI::ReplaceWidget (`id (`rp_status), `Label (`id (`status), ""));
+}
- // busy message
- Popup::ShowFeedback ("", sformat ("Destroying Container '%1'...", name));
+void StopContainer (string name)
+{
+ y2internal ("lxc-stop: %1",
+ SCR::Execute (.target.bash_output, "lxc-stop -n " + name)
+ );
+}
- string cmd = "lxc-destroy -f -n " + name;
- map out = (map) SCR::Execute (.target.bash_output, cmd);
+void DestroyContainer (string name)
+{
+ // busy message
+ Popup::ShowFeedback ("", sformat ("Destroying Container '%1'...", name));
- y2internal ("out: %1", out);
+ string cmd = "lxc-destroy -f -n " + name;
+ map out = (map) SCR::Execute (.target.bash_output, cmd);
- Popup::ClearFeedback ();
+ y2internal ("out: %1", out);
- if (out["exit"]:0 != 0)
- {
- // error message
- Report::Error (sformat (_("Error while destroying:
+ Popup::ClearFeedback ();
+
+ if (out["exit"]:0 != 0)
+ {
+ // error message
+ Report::Error (sformat (_("Error while destroying:
%1"), out["stdout"]:""));
- }
- else
- {
- foreach (any t, [ `create, `name, `ip, `subnet, `bridge, `lan, `template, `pw1, `pw2 ], {
- UI::ChangeWidget (`id (t), `Enabled, true);
- });
- UI::ChangeWidget (`id (`start), `Enabled, false);
- UI::ChangeWidget (`id (`destroy), `Enabled, false);
- }
+ }
+}
+
+/**
+ * Overview of existing Linux Containers
+ * @return dialog result
+ */
+any OverviewDialog () {
+
+ // LXC overview dialog caption
+ string caption = _("LXC Configuration");
+
+ list<term> lxc_list = Lxc::GetContainers ();;
+
+ term contents = `HBox (`HSpacing (), `VBox (
+ `VSpacing (),
+ // Table header
+ `Table (`id (`table), `opt (`notify), `header(_("Name"), _("Status")), lxc_list),
+ `HBox (
+ `PushButton (`id (`add_button), `opt (`key_F3), Label::CreateButton ()),
+ // button label
+ `PushButton (`id (`destroy), `opt (`key_F5), _("&Destroy")),
+ // button label
+ `Right (`PushButton (`id (`start), _("&Start"))),
+ // button label
+ `PushButton (`id (`stop), _("Sto&p"))
+ ),
+ `VSpacing ()
+ ), `HSpacing ());
+
+ Wizard::SetContentsButtons(caption, contents, "overview",
+ Label::BackButton(), Label::FinishButton());
+
+ foreach (any t, [ `table, `destroy, `start ], {
+ UI::ChangeWidget (`id (t), `Enabled, size (lxc_list) > 0);
+ });
+
+ any ret = nil;
+ while(true) {
+
+ ret = UI::UserInput();
+
+ if (ret == `abort || ret == `cancel || ret == `next || ret == `back) {
+ break;
+ }
+
+ if (ret == `add_button) {
+ ret = `add;
+ break;
+ }
+ string selected = (string) UI::QueryWidget (`id (`table), `CurrentItem);
+
+ if (ret == `start) {
+ StartContainer (selected);
continue;
}
- }
- UI::CloseDialog();
+ if (ret == `stop) {
+ StopContainer (selected);
+ continue;
+ }
+
+ if (ret == `destroy) {
+ // FIXME ask for confirmation
+ DestroyContainer (selected);
+ // FIXME adapt the table
+ continue;
+ }
+ }
return ret;
}
-
/* EOF */
}
Modified: branches/SuSE-Code-11-SP2-Branch/lxc/src/lxc.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/lxc/src/lxc.ycp?rev=67977&r1=67976&r2=67977&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/lxc/src/lxc.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/lxc/src/lxc.ycp Fri Apr 20 17:28:41 2012
@@ -46,13 +46,14 @@
import "Summary";
import "CommandLine";
-include "lxc/dialogs.ycp";
+include "lxc/wizards.ycp";
map cmdline_description = $[
"id" : "lxc",
/* Command line help text for the Xlxc module */
"help" : _("Configuration of LXC"),
- "guihandler" : LxcDialog,
+ "guihandler" : LxcSequence,
+ "initialize" : Lxc::Read,
"actions" : $[
],
"options" : $[
Added: branches/SuSE-Code-11-SP2-Branch/lxc/src/wizards.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/lxc/src/wizards.ycp?rev=67977&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/lxc/src/wizards.ycp (added)
+++ branches/SuSE-Code-11-SP2-Branch/lxc/src/wizards.ycp Fri Apr 20 17:28:41 2012
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------------------
+ * Copyright (c) 2006 Novell, Inc. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may find
+ * current contact information at www.novell.com.
+ * ------------------------------------------------------------------------------
+ */
+
+/**
+ * File: include/lxc/wizards.ycp
+ * Package: Configuration of lxc
+ * Summary: Wizards definitions
+ * Authors: Jiri Suchomel