* Tue Mar 18 2025 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-9.sme

- update config for Nut 2.8.2 [SME: 12657]
  TODO review master/slave mode
  TODO convert master/slave to primary/secondary
  TODO convert to new config data + migrate
  TODO event and action
This commit is contained in:
Jean-Philippe Pialasse 2025-05-17 00:44:43 -04:00
parent 4743293464
commit 4e61b36891
9 changed files with 154 additions and 71 deletions

View File

@ -15,7 +15,11 @@ foreach (qw(bootstrap-console-save console-save smeserver-nutUPS-update nut-conf
templates2events("/etc/ups/upsd.conf", $_);
}
event_link("nut-config", "post-upgrade" , "4");
event_link("nut-config-drivers", "post-upgrade", "50");
my $event= "nut-conf";
event_link("nut-config", $event, "4");
event_link("nut-config-drivers", $event, "50");
event_link("systemd-default", $event, "88");
safe_symlink("try-restart", "root/etc/e-smith/events/$event/services2adjust/nut-driver\@ups");
@ -30,5 +34,6 @@ safe_symlink("try-restart", "root/etc/e-smith/events/$event/services2adjust/nut-
safe_symlink("try-restart", "root/etc/e-smith/events/$event/services2adjust/nut-monitor");
safe_symlink("try-restart", "root/etc/e-smith/events/$event/services2adjust/nut-server");
templates2events("/etc/systemd/system-preset/49-koozali.preset", $event);
event_link("nut-config", $event, "4");
event_link("nut-config-drivers", $event, "50");
event_link("systemd-default", $event, "88");

View File

@ -0,0 +1,22 @@
{
# migrate to SME11
# first we get ride of Master=no
# if Mode not set then set it according to Master
my $mnut = $DB->get('nut') || $DB->new_record('nut', {type => 'service'});
my $nutMaster = $DB->get_prop_and_delete ('nut','Master');
unless ( ${'nut'}{'Mode'} ) {
$mnut>set_prop('Mode','netserver') if $nutMaster eq "yes";
}
# if nut-driver@ups not existing create it
my $driverUPS = $DB->get('nut-driver@ups') || $DB->new_record('nut-driver@ups', {type => 'service'});
# then migrate to nut-driver@ups (first UPS) the following properties
my $mdl = $DB->get_prop_and_delete ('nut','mdl');
$driverUPS->set_prop('mdl',$mdl) unless ${'nut-driver@ups'}{'mdl'};
my $mfr = $DB->get_prop_and_delete ('nut','mfr');
$driverUPS->set_prop('mfr',$mfr) unless ${'nut-driver@ups'}{'mfr'};
my $model = $DB->get_prop_and_delete ('nut','Model');
$driverUPS->set_prop('Model',$model) unless ${'nut-driver@ups'}{'Model'};
my $Type = $DB->get_prop_and_delete ('nut','Type');
$driverUPS->set_prop('Type',$model) unless ${'nut-driver@ups'}{'Type'};
}

View File

@ -0,0 +1,52 @@
#!/bin/bash
# this script is called before template-expand
# then another script is called to run /usr/libexec/nut-driver-enumerator.sh and start/stop drivers
# then traditionnal services2adjust
# calling this script to configure unit and drivers
if [[ $(/sbin/e-smith/config getprop nut status || echo "disabled") == "disabled" ]] ; then
# disable server
/sbin/e-smith/config setprop nut-server status disabled
/sbin/e-smith/config setprop nut access localhost
# disable monitor
/sbin/e-smith/config setprop nut-monitor status disabled
# TODO get_all_by_prop filter nut-driver@ and foreach $UPS disabled
#config keys|grep nut-driver
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
do
/sbin/e-smith/config setprop $OUTPUT status disabled
done
exit 0;
fi
# nut is enabled
# we set services depending on Mode
Mode=$(/sbin/e-smith/config getprop nut Mode || echo "standelone")
if [[ $Mode == "netserver" ]] ; then
/sbin/e-smith/config setprop nut-server status enabled
/sbin/e-smith/config setprop nut access private
elif [[ $Mode == "netclient" ]] ; then
/sbin/e-smith/config setprop nut-server status disabled
/sbin/e-smith/config setprop nut access localhost
else
/sbin/e-smith/config setprop nut-server status enabled
/sbin/e-smith/config setprop nut access localhost
fi
# enable nut-monitor
/sbin/e-smith/config setprop nut-monitor status enabled
# get_all_by_prop filter nut-driver@ and foreach $UPS enable.
if [[ $Mode == "netclient" ]] ; then
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
do
/sbin/e-smith/config setprop $OUTPUT status disabled
done
else
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
do
/sbin/e-smith/config setprop $OUTPUT status enabled
done
fi

View File

@ -1,18 +1,33 @@
#!/bin/bash
#if MODE = netserver then access should be private
#if MODE = netclient only enable monitor
# calling this script to configure unit and drivers
if [[ $(/sbin/e-smith/config getprop nut status || echo "disabled") == "disabled" ]] ; then
# disable server
# leave monitor as is, we might want to monitor an external ups ?
# get_all_by_prop filter nut-driver@ and foreach $UPS disabled
exit 0;
fi
# nut is enabled
# enable nut-monitor
# enable nut-server "enable nut-server.service\n" if ($master eq 'yes');
# get_all_by_prop filter nut-driver@ and foreach $UPS enable.
# another script is called before template-expand to set services
# this script is called to run /usr/libexec/nut-driver-enumerator.sh and start/stop drivers
# then traditionnal services2adjust
# enumerate / configure drivers
/usr/libexec/nut-driver-enumerator.sh
event=$1
if [[ $i == "post-upgrade" ]] ; then
exit 0
fi
if [[ $i == "bootstrap-console-save" ]] ; then
exit 0
fi
if [[ $(/sbin/e-smith/config getprop nut status || echo "disabled") == "disabled" ]] ; then
# if disabled stop them
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
do
/usr/bin/systemctl stop $OUTPUT
done
exit 0
fi
# if we are there we want to restart / start them
for OUTPUT in $(/sbin/e-smith/config keys|grep nut-driver)
do
/usr/bin/systemctl restart $OUTPUT
done

View File

@ -3,12 +3,13 @@
foreach my $ups ( sort {$a cmp $b} @upses )
{
my $nnut = ${$ups};
my ($name )= $ups =~ /^nut-driver\@(.*)$/ ;
my $model = $nnut{Model} || "usbhid-ups";
my $device = $nnut{Device} || "auto"; #"/var/lib/ups/hiddev0";
my $type = $nnut{Type};
my $mfr = $nnut{mfr};
my $mdl = $nnut{mdl};
$OUT .= "[UPS]\n";
$OUT .= "[$name]\n";
$OUT .= "\tdriver = $model\n";
if ($model eq 'genericups')
{

View File

@ -49,7 +49,7 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
{$ret .= 'Validation for status failed';}
if (! TRUE) #validate $c->param('Nutmode')
{$ret .= 'Validation for Nutmode failed';}
#do we want the Slave validated ? we should just display read only
#do we want the Slave validated ? we should just display read only
if (! TRUE) #validate $c->param('SlaveUPS_Name')
{$ret .= 'Validation for SlaveUPS_Name failed';}
if (! TRUE) #validate $c->param('ClientUPS_Name')
@ -82,7 +82,7 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
# fields from Inputs in STATUS $fields['STATUS']
'UPSStatus'=>$c->get_ups_status(),
'ups_data' => $c->get_ups_status_as_hash(),
'Nutmode'=>$cdb->get_prop('nut', 'mode')||"none",
'Nutmode'=>$cdb->get_prop('nut', 'Mode')||"none",
'localip'=>$cdb->get_value('LocalIP'),
'SlaveUPS_Pass'=>$cdb->get_prop('nut', 'SecondaryPass'),
);
@ -97,20 +97,19 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
'Data1'=>'Data for CONFIG', #Example
'localip'=>$cdb->get_value('LocalIP'),
# fields from Inputs in CONFIG $fields['CONFIG']
'status'=>$cdb->get_prop('nut', 'status', 'disabled'),
'Nutmode'=>$cdb->get_prop('nut', 'mode', 'standalone'),
#'SlaveUPS_Name'=>$cdb->get_prop('nut', 'SlaveUPS'),
'status'=>$cdb->get_prop('nut', 'status') || 'disabled',
'Nutmode'=>$cdb->get_prop('nut', 'Mode') || 'standalone',
'ClientUPS_Name'=>$cdb->get_prop('nut', 'ClientUPS'),
'ClientUPS_User'=>$cdb->get_prop('nut', 'ClientUser'),
'ClientUPS_Pass'=>$cdb->get_prop('nut', 'ClientPass'),
'SlaveUPS_Pass'=>$cdb->get_prop('nut', 'SecondaryPass'),
'MasterUPS_Name'=>$cdb->get_prop('nut', 'MasterUPS'),
# TODO migrate to nut-driver@ups entry
'UPS_Model'=>$cdb->get_prop('nut', 'Model') || 'usbhid-ups',
'UPS_Device'=>$cdb->get_prop('nut', 'Device')|| 'auto',
'UPS_gen_Type'=>$cdb->get_prop('nut', 'Type', ''),
'UPS_gen_Mfr'=>$cdb->get_prop('nut', 'mfr', ''),
'UPS_gen_Model'=>$cdb->get_prop('nut', 'mdl', ''),
# nut-driver@ups entry
'UPS_Model'=>$cdb->get_prop('nut-driver@ups', 'Model') || 'usbhid-ups',
'UPS_Device'=>$cdb->get_prop('nut-driver@ups', 'Device')|| 'auto',
'UPS_gen_Type'=>$cdb->get_prop('nut-driver@ups', 'Type'),
'UPS_gen_Mfr'=>$cdb->get_prop('nut-driver@ups', 'mfr'),
'UPS_gen_Model'=>$cdb->get_prop('nut-driver@ups', 'mdl'),
);
return %ret;
}
@ -168,10 +167,10 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
if (!$db->set_prop($dbkey,'status',$c->param('status')))
{$ret .= 'Perform/save failed for status';}
if (!$db->set_prop($dbkey,'mode',$c->param('Nutmode')))
if (!$db->set_prop($dbkey,'Mode',$c->param('Nutmode')))
{$ret .= 'Perform/save failed for Nutmode';}
# let only save info regarding the current mode
# let only save info regarding the current mode
# if client mode
if (! $db->set_prop($dbkey,'ClientUPS',$c->param('ClientUPS_Name')))
{$ret .= 'Perform/save failed for ClientUPS_Name';}
@ -183,15 +182,15 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
{$ret .= 'Perform/save failed for ClientUPS_Pass';}
# if not client mode
if (! $db->set_prop($dbkey,'Model',$c->param('UPS_Model')))
if (! $db->set_prop($driverkey,'Model',$c->param('UPS_Model')))
{$ret .= 'Perform/save failed for UPS_Model';}
if (! $db->set_prop($dbkey,'Device',$c->param('UPS_Device')))
if (! $db->set_prop($driverkey,'Device',$c->param('UPS_Device')))
{$ret .= 'Perform/save failed for UPS_Device';}
if (! $db->set_prop($dbkey,'Type',$c->param('UPS_gen_Type')))
if (! $db->set_prop($driverkey,'Type',$c->param('UPS_gen_Type')))
{$ret .= 'Perform/save failed for UPS_gen_Type';}
if (! $db->set_prop($dbkey,'mfr',$c->param('UPS_gen_Mfr')))
if (! $db->set_prop($driverkey,'mfr',$c->param('UPS_gen_Mfr')))
{$ret .= 'Perform/save failed for UPS_gen_Mfr';}
if (! $db->set_prop($dbkey,'mdl',$c->param('UPS_gen_Model')))
if (! $db->set_prop($driverkey,'mdl',$c->param('UPS_gen_Model')))
{$ret .= 'Perform/save failed for UPS_gen_Model';}
#changes from sme10 to sme11
@ -208,17 +207,6 @@ my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
if ($ret eq "") {
$ret = 'ok';
#and set Master and access properties according to values
if ($db->get_prop($dbkey,"mode",'standalone') eq 'netclient'){
$db->set_prop($dbkey,'Master','no');
} else {
$db->set_prop($dbkey,'Master','yes');
}
if ($db->get_prop($dbkey,"mode",'standalone') eq 'netserver'){
$db->set_prop($dbkey,'access','private');
} else {
$db->set_prop($dbkey,'access','localhost');
}
#And run signal-event to apply templates for config files and start task.
my @result = qx{/usr/sbin/e-smith/signal-event smeserver-nutUPS-update};
if ($? != 0) {
@ -259,7 +247,7 @@ sub get_model_options {
sub get_ups_status {
my $c = shift;
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $nutmode = $cdb->get_prop('nut', 'mode','standalone');
my $nutmode = $cdb->get_prop('nut', 'Mode','standalone');
if ($cdb->get_prop('nut', 'status', 'disabled') eq 'disabled'){
return $c->l('nut_status_is_disabled')
} elsif ($nutmode eq 'netclient'){