ACC SHELL
/**
* File: modules/IscsiClient.ycp
* Package: Configuration of iscsi-client
* Summary: IscsiClient settings, input and output functions
* Authors: Michal Zugec <mzugec@suse.cz>
*
* $Id: IscsiClient.ycp 56867 2009-04-21 07:29:28Z mzugec $
*
* Representation of the configuration of iscsi-client.
* Input and output routines.
*/
{
module "IscsiClient";
textdomain "iscsi-client";
import "Progress";
import "Report";
import "Summary";
import "Message";
import "Service";
import "Package";
import "Packages";
import "Popup";
import "Mode";
import "Confirm";
import "Label";
import "NetworkService";
import "IscsiClientLib";
import "Stage";
global boolean configured = false;
/**
* Prototypes
*/
global boolean Modified();
/**
* Data was modified?
*/
global boolean modified = 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;
}
// check if package open-iscsi is installed
boolean installed_packages(){
// don't check interactively for packages (bnc#367300)
// skip it during second stage or when create AY profile
if(Stage::cont() || Stage::initial() || Mode::config()) return true;
y2milestone("Check if open-iscsi package installed");
boolean ret = false;
if( !Package::InstallMsg( "open-iscsi",
_("<p>To configure the iSCSI initiator, the <b>%1</b> package must be installed.</p>") +
_("<p>Install it now?</p>")) )
{
Popup::Error( Message::CannotContinueWithoutPackagesInstalled() );
} else ret = true;
return ret;
}
/**
* Dump the iscsi-client settings to a single map
* (For use by autoinstallation.)
* @return map Dumped settings (later acceptable by Import ())
*/
global map Export () {
list tgets = [];
foreach(string sess, IscsiClientLib::sessions, {
string target = splitstring(sess, " ")[1]:"";
string portal = splitstring(sess, " ")[0]:"";
IscsiClientLib::currentRecord = [portal, target];
map<string, any> auth = IscsiClientLib::getNode();
map new_target =
$["target": target,
"portal" : portal,
"startup" : IscsiClientLib::getStartupStatus(),
];
if (auth["authmethod"]:"None"=="None") new_target["authmethod"]="None";
else new_target = union(new_target, auth);
tgets = add(tgets, new_target);
});
map result = $[
"version" : "1.0",
"initiatorname" : IscsiClientLib::initiatorname,
"targets" : tgets
];
configured = true;
modified = true;
return result;
}
/**
* Read all iscsi-client settings
* @return true on success
*/
global boolean Read() {
/* IscsiClient read dialog caption */
string caption = _("Initializing iSCSI Initiator 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 - must be root
if(!Confirm::MustBeRoot()) return false;
if(!NetworkService::RunningNetworkPopup()) return false;
Progress::NextStage();
if(false) return false;
sleep(sl);
if(IscsiClientLib::getiBFT()==nil) return false;
/* Progress finished */
Progress::NextStage();
sleep(sl);
Progress::NextStage();
// check if required package is installed
if(!installed_packages()) return false;
// check initiatorname - create it if no exists
y2milestone("Check initiator name");
if(!IscsiClientLib::checkInitiatorName()) return false;
sleep(sl);
if(Abort()) return false;
// Progress::NextStep();
// read status of service
if(!IscsiClientLib::getServiceStatus()) return false;
sleep(sl);
// read current settings
// if(!IscsiClientLib::autoLogOn()) return false;
Progress::NextStage();
// read config file
if(IscsiClientLib::readSessions()==false)
{
Report::Error( Message::CannotReadCurrentSettings() );
return false;
}
sleep(sl);
if(Abort()) return false;
modified = false;
return true;
}
/**
* Write all iscsi-client settings
* @return true on success
*/
global boolean Write() {
/* IscsiClient read dialog caption */
string caption = _("Saving iSCSI Initiator Configuration");
// TODO FIXME And set the right number of stages
integer sl = 500;
sleep(sl);
list<string> descr = [
/* Progress stage 1/2 */
_("Write the autoYaST settings"),
/* Progress stage 2/2 */
_("Set up service status")
];
if (!Mode::autoinst()) descr=remove(descr, 0);
// TODO FIXME Names of real stages
// We do not set help text here, because it was set outside
Progress::New(caption, " ", size(descr), descr, [], "");
if (Mode::autoinst()){
if(Abort()) return false;
Progress::NextStage();
IscsiClientLib::autoyastPrepare();
IscsiClientLib::autoyastWrite();
sleep(sl);
}
if(Abort()) return false;
Progress::NextStage ();
// set open-iscsi service status
if(!IscsiClientLib::setServiceStatus()) return false;
sleep(sl);
if(Abort()) return false;
Progress::NextStage();
if (Stage::initial() && size(IscsiClientLib::sessions)>0 )
Packages::addAdditionalPackage("open-iscsi");
sleep(sl);
return true;
}
/**
* Get all iscsi-client 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) {
IscsiClientLib::ay_settings = settings;
return true;
}
/**
* 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 */
}
ACC SHELL 2018