Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] r57862 - /trunk/isns/src/IsnsServer.ycp
  • From: mzugec@xxxxxxxxxxxxxxxx
  • Date: Fri, 03 Jul 2009 10:01:06 -0000
  • Message-id: <E1MMfZq-0000kT-6V@xxxxxxxxxxxxxxxx>
Author: mzugec
Date: Fri Jul 3 12:01:05 2009
New Revision: 57862

URL: http://svn.opensuse.org/viewcvs/yast?rev=57862&view=rev
Log:
added IsnsServer.ycp

Added:
trunk/isns/src/IsnsServer.ycp

Added: trunk/isns/src/IsnsServer.ycp
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/isns/src/IsnsServer.ycp?rev=57862&view=auto
==============================================================================
--- trunk/isns/src/IsnsServer.ycp (added)
+++ trunk/isns/src/IsnsServer.ycp Fri Jul 3 12:01:05 2009
@@ -0,0 +1,615 @@
+/**
+ * File: modules/IsnsServer.ycp
+ * Package: Configuration of isns-server
+ * Summary: IsnsServer settings, input and output functions
+ * Authors: Michal Zugec <mzugec@xxxxxxx>
+ *
+ * $Id: IsnsServer.ycp 35355 2007-01-15 15:06:49Z mzugec $
+ *
+ * Representation of the configuration of iscsi-server.
+ * Input and output routines.
+ */
+
+{
+
+module "isnsServer";
+textdomain "isns";
+
+import "Progress";
+import "Report";
+import "Summary";
+import "Message";
+import "Service";
+import "Package";
+import "Popup";
+import "SuSEFirewall";
+import "Confirm";
+import "Mode";
+import "String";
+import "Map";
+
+boolean serviceStatus = false;
+boolean statusOnStart = false;
+
+/**
+ * Prototypes
+ */
+global boolean Modified();
+
+/**
+ * Data was modified?
+ */
+global boolean modified = false;
+global boolean configured = false;
+
+/**
+ */
+global boolean proposal_valid = false;
+
+/**
+ * Write only, used during autoinstallation.
+ * Don't run services and SuSEconfig, it's all done at one place.
+ */
+global boolean write_only = false;
+
+/**
+ * Abort function
+ * return boolean return true if abort
+ */
+global boolean() AbortFunction = Modified;
+
+/**
+ * Abort function
+ * @return boolean return true if abort
+ */
+global define boolean Abort() ``{
+ if(AbortFunction != nil)
+ {
+ return AbortFunction () == true;
+ }
+ return false;
+}
+
+/**
+ * Data was modified?
+ * @return true if modified
+ */
+global boolean Modified() {
+ y2debug("modified=%1",modified);
+ return modified;
+}
+
+// read configuration file /etc/ietd.conf
+global boolean readConfig(){
+ map<string, any> read_values = (map<string, any>)SCR::Read(.etc.isns.all);
+// IsnsServerFunctions::parseConfig( read_values );
+ y2milestone("isns readConfig");
+ return true;
+}
+
+// write configuration file /etc/ietd.conf
+boolean writeConfig(){
+// prepare map, because perl->ycp lost information about data types (integers
in this case)
+// map <string, any> config_file = IsnsServerFunctions::writeConfig();
+// config_file["type"]=tointeger(config_file["type"]:"1");
+// config_file["file"]=tointeger(config_file["file"]:"1");
+// list <map<string, any> > value = [];
+// foreach(map<string, any> row, config_file["value"]:[], {
+// row["type"]=tointeger(row["type"]:"1");
+// row["file"]=tointeger(row["file"]:"1");
+// value = add(value, row);
+// });
+//
+// config_file["value"] = value;
+// y2milestone("config_file to write %1", config_file);
+// // write it
+// SCR::Write(.etc.ietd.all, config_file);
+// SCR::Write(.etc.ietd, nil);
+ return true;
+}
+
+
+
+// test if required package ("isns") is installed
+boolean installed_packages(){
+ boolean ret = false;
+ y2milestone("Check if isns is installed");
+ if( !Package::InstallMsg( "isns",
+ _("<p>To configure the isns service, the <b>%1</b> package must be
installed.</p>") +
+ _("<p>Install it now?</p>")) )
+ {
+ Popup::Error( Message::CannotContinueWithoutPackagesInstalled() );
+ } else ret = true;
+
+ return ret;
+}
+
+// check status of isns service
+// if not enabled, start it manually
+boolean getServiceStatus(){
+ boolean ret = true;
+ if (Service::Status("isns") == 0) {
+ statusOnStart=true;
+ serviceStatus=true;
+ }
+y2milestone("Service status = %1", statusOnStart);
+ if (!statusOnStart) Service::Start("isns");
+ return ret;
+}
+
+// set service status
+boolean setServiceStatus(){
+ boolean start=true;
+ if (!serviceStatus) start = statusOnStart;
+
+ if (!start) {
+ y2milestone("Stop isns service");
+ Service::Stop("isns");
+ } else {
+ y2milestone("Start isns service");
+ serviceStatus=true;
+ Service::Start("isns");
+ }
+ return true;
+}
+
+global string testISNSAccess(string address) {
+ string value = "OK";
+ map <string,any> temp = $[];
+
+ string command = sformat("isnsadm -a %1 -t -q iscsi",address);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ if (row == "TCP error on connection")
+ {
+ y2milestone("TCP error: %1 ",row);
+ value = "ERROR";
+ }
+
+ if (row == "Error Sending TCP request.")
+ {
+ y2milestone("Failed to resolve host error: %1 ",row);
+ value = "ERROR";
+ }
+
+ });
+
+return value;
+}
+global list <map <string,any> > readISCSI(string address) {
+ list <map <string,any> > values = [];
+ map <string,any> temp = $[];
+
+ string command = sformat("isnsadm -a %1 -t -q iscsi",address);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ }
+
+ if (key == "iSCSI ID ") {
+ val = substring(row, pos + 2);
+ temp["NODE"] = val;
+ }
+
+ if (key == "Type") {
+ val = substring(row, pos + 6);
+ temp["TYPE"] = val;
+ values = add(values, temp );
+ }
+ });
+
+return values;
+}
+
+global string readISCSI_type(string address,string index) {
+ string temp = "";
+
+ y2milestone("iSCSIRead_type index:%1", index);
+
+ string command = sformat("isnsadm -a %1 -t -q iscsi -n %2",address,index);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ val = substring(row, pos + 6);
+ }
+
+ y2milestone("iSCSIRead_type %1",key);
+
+ if (key == "Type") {
+ y2milestone("iSCSIRead_type return value is %1",val);
+ temp = val;
+ }
+ });
+
+return temp;
+}
+
+
+global list <string> readDDS(string address) {
+ list <string> values = [];
+ string ddid = "";
+
+ y2milestone("readDDS %1",address);
+ string command = sformat("isnsadm -a %1 -t -q dds",address);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ val = substring(row, pos + 2);
+ }
+
+ if (key == "DDS ID ") {
+ values = add(values, val );
+ }
+ else if (key == "DDS Sym Name ") {
+ values = add(values, val );
+ }
+ });
+
+return values;
+}
+
+global list <map <string,any> > readDDMembers(string address, string id) {
+ list <map <string,any> > values = [];
+ map <string,any> temp = $[];
+ string ddid = "";
+
+ y2milestone("readDDSMembers %1 %2",address, id);
+ string command = sformat("isnsadm -a %1 -t -q dd -n %2",address,id);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ y2milestone("results: %1",row);
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ val = substring(row, pos + 2);
+ }
+
+ if (key == " DD iSCSI Member ") {
+ temp["NODE"] = val;
+ }
+
+ if (key == " DD iSCSI Member Index ") {
+ temp["TYPE"] = readISCSI_type(address,val);
+ values = add(values, temp );
+ }
+
+ });
+
+return values;
+}
+
+global list <string> readDDSMembers(string address, string id) {
+ list <string> values = [];
+ string ddid = "";
+
+ y2milestone("readDDSMembers %1 %2",address, id);
+ string command = sformat("isnsadm -a %1 -t -q dds -n %2",address,id);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ y2milestone("results: %1",row);
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ val = substring(row, pos + 2);
+ }
+
+ if (key == " DD ID ") {
+ values = add(values, val );
+ }
+ else if (key == " DD Sym Name ") {
+ values = add(values, val );
+ }
+ });
+
+return values;
+}
+
+global list <string> readDD(string address) {
+ list <string> values = [];
+ string ddid = "";
+
+ y2milestone("readDD");
+ string command = sformat("isnsadm -a %1 -t -q dd",address);
+ map<string, any> result= (map<string, any>)
SCR::Execute(.target.bash_output, command, $[]);
+ foreach(string row, splitstring(result["stdout"]:"","\n"), {
+
+ integer pos = findfirstof(row,":");
+ string key = "";
+ string val = "";
+
+ if (pos != nil && pos > 0)
+ {
+ key = substring(row, 0, pos );
+ val = substring(row, pos + 2);
+ }
+
+ if (key == "DD ID ") {
+ values = add(values, val );
+ }
+ else if (key == "DD Sym Name ") {
+ values = add(values, val );
+ }
+
+
+ });
+
+return values;
+}
+
+global boolean addISCSI(string address, string name, string entityid) {
+ y2milestone("addDDS");
+ string command = sformat("isnsadm -a %1 -t -r iscsi -n '%2' -m
'%3'",address, name, entityid);
+ SCR::Execute(.target.bash_output, command, $[]);
+ return true;
+}
+
+global boolean addDDS(string address, string name) {
+ y2milestone("addDDS");
+ string command = sformat("isnsadm -a %1 -t -r dds -n '%2'", address, name);
+ SCR::Execute(.target.bash_output, command, $[]);
+ return true;
+}
+
+global boolean addDDMember(string address, string dd_id, string iqn) {
+ y2milestone("addDDMember");
+ string command = sformat("isnsadm -a %1 -t -r ddmember -n %2 -m %3",
address, dd_id, iqn);
+ SCR::Execute(.target.bash_output, command, $[]);
+ return true;
+}
+
+global boolean addDDSMember(string address, string dds_id, string dd_id) {
+ y2milestone("addDDSMember");
+ string command = sformat("isnsadm -a %1 -t -r ddsmember -n %2 -m %3",
address, dds_id, dd_id);
+ SCR::Execute(.target.bash_output, command, $[]);
+ return true;
+}
+
+global boolean addDD(string address, string name) {
+ y2milestone("addDD");
+ string command = sformat("isnsadm -a %1 -t -r dd -n '%2'", address, name);
+ SCR::Execute(.target.bash_output, command, $[]);
+ return true;
+}
+
+global boolean deleteISCSI(string address, string id) {
+ y2milestone("deleteISCSI");
+ string command = sformat("isnsadm -a %1 -t -d iscsi -n '%2'",address, id);
+ SCR::Execute(.target.bash_output, command, $[]);
+
+ return true;
+}
+
+global boolean deleteDDS(string address, string id) {
+ y2milestone("deleteDDS");
+ string command = sformat("isnsadm -a %1 -t -d dds -n '%2'",address, id);
+ SCR::Execute(.target.bash_output, command, $[]);
+
+ return true;
+}
+
+global boolean deleteDDMember (string address, string dd_id, string iqn) {
+ y2milestone("deleteDDSMember:%1",iqn);
+ string command = sformat("isnsadm -a %1 -t -d ddmember -n %2 -m
%3",address, dd_id, iqn);
+ SCR::Execute(.target.bash_output, command, $[]);
+
+ return true;
+}
+
+global boolean deleteDDSMember (string address, string dds_id, string dd_id) {
+ y2milestone("deleteDDSMember");
+ string command = sformat("isnsadm -a %1 -t -d ddsmember -n %2 -m
%3",address, dds_id, dd_id);
+ SCR::Execute(.target.bash_output, command, $[]);
+
+ return true;
+}
+
+global boolean deleteDD(string address, string id) {
+ y2milestone("deleteDDS");
+ string command = sformat("isnsadm -a %1 -t -d dd -n '%2'",address, id);
+ SCR::Execute(.target.bash_output, command, $[]);
+
+ return true;
+}
+
+
+/**
+ * Read all iscsi-server settings
+ * @return true on success
+ */
+global boolean Read() {
+
+ /* IsnsServer read dialog caption */
+ string caption = _("Initializing isns daemon configuration");
+
+ // TODO FIXME Set the right number of stages
+ integer steps = 4;
+
+ integer sl = 500;
+ sleep(sl);
+
+ // 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 step 1/3 */
+ _("Reading the database..."),
+ /* Progress step 2/3 */
+ _("Reading the previous settings..."),
+ /* Progress step 3/3 */
+ _("Detecting the devices..."),
+ /* Progress finished */
+ _("Finished")
+ ],
+ ""
+ );
+
+ // check if user is root
+ if(!Confirm::MustBeRoot()) return false;
+ Progress::NextStage();
+ // check if required packages ("isns") is installed
+ if(!installed_packages()) return false;
+ sleep(sl);
+
+ if(Abort()) return false;
+ Progress::NextStep();
+ // get status of isns init script
+ if(!getServiceStatus()) return false;
+ sleep(sl);
+
+ if(Abort()) return false;
+ Progress::NextStage();
+ // read configuration (/etc/ietd.conf)
+ if(!readConfig()) {
+ Report::Error(Message::CannotReadCurrentSettings());
+ return false;
+ }
+ sleep(sl);
+
+ // detect devices
+ Progress::set(false);
+ SuSEFirewall::Read();
+ Progress::set(true);
+
+ Progress::NextStage();
+ /* Error message */
+ if(false) return false;
+ sleep(sl);
+
+ if(Abort()) return false;
+ /* Progress finished */
+ Progress::NextStage();
+ sleep(sl);
+
+ if(Abort()) return false;
+ modified = false;
+ configured = true;
+ return true;
+}
+
+/**
+ * Write all iscsi-server settings
+ * @return true on success
+ */
+global boolean Write() {
+
+ /* IsnsServer write dialog caption */
+ string caption = _("Saving isns Configuration");
+
+ // TODO FIXME And set the right number of stages
+ integer steps = 2;
+
+ integer sl = 500;
+ sleep(sl);
+
+ // 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")
+ ],
+ ""
+ );
+
+
+ Progress::set(false);
+ SuSEFirewall::Write();
+ Progress::set(true);
+
+ Progress::NextStage();
+ // write configuration (/etc/isns.conf)
+ if(!writeConfig()) Report::Error (_("Cannot write settings."));
+ sleep(sl);
+
+
+ if(Abort()) return false;
+ Progress::NextStage ();
+// ask user whether reload or restart server and do it
+// if ( (serviceStatus) || (statusOnStart) )
+// if (!reloadServer()) return false;
+// sleep(sl);
+
+ if(Abort()) return false;
+ Progress::NextStage();
+ sleep(sl);
+
+ // set isns initscript status
+ if(!setServiceStatus()) return false;
+ return true;
+}
+
+/**
+ * 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":[] ];
+}
+
+
+// get/set service accessors for CWMService component
+global boolean GetStartService() {
+ boolean status = Service::Enabled("isns");
+ y2milestone("isns service status %1", status);
+ return status;
+}
+
+global void SetStartService(boolean status) {
+ y2milestone("Set service status %1", status);
+ serviceStatus = status;
+ if (status == true) Service::Enable("isns");
+ else Service::Disable("isns");
+}
+/* EOF */
+}

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages