OpenSANd Code
Brought to you by:
hoefer
#!/usr/bin/perl -w
# This is opensand, an NBD base SAN system
# Copyright (C) 2008-2015 Stefan Hoefer <stefan@hoefer.ch>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
use strict;
use Tk;
#use X11::Protocol;
use Tk::NoteBook;
use Tk::Adjuster;
use Tk::Tree;
use Tk::ProgressBar;
use Tk::Pane;
use IPC::Open2;
#use Tk::DynaTabFrame;
use Tk::Balloon;
use Tk::DialogBox;
use Tk::Dialog;
use Tk::LabFrame;
use Tk::Table;
use Getopt::Long;
use Tk::Entry;
use Tk::BrowseEntry;
my $useid;
GetOptions("use=s" => \$useid);
# STHTODO activate this!
#if (! -e "/dev/vg_opensand") {
# die "OpenSAN is not running!\n";
#}
my %Bitmap;
$Bitmap{bm_run} = <<TheEnd;
........
.1......
.11.....
.111....
.1111...
.11111..
.111111.
.11111..
.1111...
.111....
.11.....
.1......
........
TheEnd
$Bitmap{bm_yes} = <<TheEnd;
............
.........11.
........11..
.......11...
......11....
......11....
.11..11.....
..11.11.....
...111......
....11......
............
TheEnd
$Bitmap{bm_no} = <<TheEnd;
............
.11......11.
..11....11..
...11..11...
....1111....
.....11.....
....1111....
...11..11...
..11....11..
.11......11.
............
TheEnd
$Bitmap{bm_stop} = <<TheEnd;
..........
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
.11111111.
..........
TheEnd
$Bitmap{bm_kill} = <<TheEnd;
..........
....11....
....11....
.11111111.
.11111111.
....11....
....11....
....11....
....11....
....11....
....11....
....11....
..........
TheEnd
$Bitmap{bm_delete} = <<TheEnd;
..........
...1111...
.,11,,11,.
.11111111.
..........
.11111111.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11111111.
..........
TheEnd
$Bitmap{bm_rename} = <<TheEnd;
..........
...1111...
..111111..
.11....11.
.11....11.
.11....11.
.11111111.
.11111111.
.11....11.
.11....11.
.11....11.
.11....11.
..........
TheEnd
$Bitmap{bm_create} = <<TheEnd;
..........
....11....
....11....
....11....
.11111111.
.11111111.
....11....
....11....
....11....
..........
TheEnd
$Bitmap{bm_info} = <<TheEnd;
..........
....11....
....11....
..........
..........
...1111...
....11....
....11....
....11....
....11....
....11....
...1111...
..........
TheEnd
$Bitmap{bm_pause} = <<TheEnd;
..........
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
.111..111.
..........
TheEnd
$Bitmap{bm_console} = <<TheEnd;
..........
.11111111.
.1......1.
.1..11..1.
.1.1..1.1.
.1.1111.1.
.1.1..1.1.
.1......1.
.11111111.
..........
.11111111.
.11111111.
..........
TheEnd
$Bitmap{bm_cdrom} = <<TheEnd;
.............
....11111....
...1.....1...
..1.......1..
.1...111...1.
.1..11.11..1.
.1..1...1..1.
.1..11.11..1.
.1...111...1.
..1...,...1..
...1.....1...
....11111....
.............
TheEnd
$Bitmap{bm_copy} = <<TheEnd;
.............
.11111111....
.1......1....
.1..11111111.
.1..1......1.
.1..1......1.
.1..1......1.
.1111......1.
....1......1.
....11111111.
.............
TheEnd
$Bitmap{bm_transcrypt} = <<TheEnd;
.............
.11111111....
.1......1....
.1..11111111.
.1..11111111.
.1..11111111.
.1..11111111.
.11111111111.
....11111111.
....11111111.
.............
TheEnd
$Bitmap{bm_reload} = <<TheEnd;
.............
......1......
.....11......
....111111...
...11111111..
....11111111.
..1..11..111.
.111..1..111.
.111.....111.
.111..1..111.
.111..11..1..
.11111111....
..11111111...
...111111....
......11.....
......1......
.............
TheEnd
$Bitmap{bm_cdromrun} = <<TheEnd;
.............
111111111....
...1.....1...
111.......1..
.1...111...1.
11..11.11..1.
.1..1...1..1.
11..11.11..1.
.1...111...1.
111.......1..
...1.....1...
111111111....
.............
TheEnd
$Bitmap{bm_edit} = <<TheEnd;
..........
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.11.11.11.
.1......1.
..1....1..
...1111...
....11....
TheEnd
$Bitmap{bm_backup} = <<TheEnd;
...........
.111111111.
.1.......1.
.11..111.1.
.1.1.1.1.1.
.1.1.111.1.
.1.1.....1.
.1.1.111.1.
.1.1.1.1.1.
.11..111.1.
.1.......1.
.111111111.
...........
TheEnd
$Bitmap{bm_migrate} = <<TheEnd;
.........
....1....
...111...
..11111..
.1111111.
...111...
...111...
...111...
.1111111.
..11111..
...111...
....1....
.........
TheEnd
Tk::CmdLine::SetArguments();
Tk::CmdLine::LoadResources();
Tk::CmdLine::SetResources( # set multiple resources
['*VM*background: beige',
'*Host*background: lightsteelblue',
'*font: verdana 10'
],
'widgetDefault' );
my $mw;
if (!defined($useid)) {
$mw = MainWindow->new();
}
else {
$mw = MainWindow->new(-use => $useid);
}
my $diskfree = get_diskfree();
my $diskmax = get_diskmax();
my $tooltip = $mw->Balloon();
packBitmaps($mw, \%Bitmap);
$mw->minsize(450,200);
my $buttons = $mw->Frame(-relief => 'raised', -background => 'lightsteelblue', -borderwidth => 2, -padx => 10)->pack(-side => 'top', -fill => 'x');
my $leftframe = $buttons->Frame(-background => 'lightsteelblue')->pack(-side => 'left');
my $hostname = 'local';
if (open my $fd, "hostname |") {
$hostname = <$fd>;
chomp $hostname;
close $fd;
}
$leftframe->Label(-background => 'lightsteelblue', -text => $hostname)->pack(-side => 'top');
#my $osframe = $mw->Scrolled('Pane', -scrollbars => 'osoe', -sticky => 'nwe')->pack(-expand => 1, -fill => 'both');
#my $table = $mw->Table(-scrollbars => 'osoe', -fixedrows => 1, -fixedcolumns => 3, -foreground => 'blue')->pack(-expand => 1, -fill => 'both', -side => 'bottom');
my $table;
reload(\$table);
my $command = sub {
my $dialog = $mw->DialogBox(-title => 'Create Disk', -default_button => 'Cancel', -buttons => [qw/OK Cancel/]);
my $frame = $dialog->add('Frame')->pack();
my $lframe = $frame->Frame()->pack(-side => 'top', -fill => 'x');
$lframe->Label(-text => 'Name:')->pack(-side => 'left', -fill => 'y');
my $newname = "New disk";
$lframe->Entry(-textvariable => \$newname)->pack(-side => 'left', -fill => 'both');
$lframe = $frame->Frame()->pack(-side => 'top', -fill => 'x');
$lframe->Label(-text => 'Size (MB):')->pack(-side => 'left', -fill => 'y');
my $newsize = "20000";
my $be = $lframe->BrowseEntry(-variable => \$newsize)->pack(-side => 'left', -fill => 'both');
$be->insert('end', 1000);
$be->insert('end', 10000);
$be->insert('end', 20000);
$be->insert('end', 40000);
$be->insert('end', 200000);
my $answer = $dialog->Show();
if ($answer eq "OK") {
$mw->Busy();
my $result = 0;
my $newid = -1;
if (open my $fd, "/usr/sbin/oscontrol create $newsize '".$newname."' |") {
my $answer = "";
$answer = <$fd>;
if ($answer =~ /ok (\d+)/) {
$result = 1;
$newid = $1;
}
close $fd;
}
$mw->Unbusy();
if ($result == 1) {
$dialog = $mw->Dialog(-text => "New disk successfully created with id $newid.", -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
$mw->Busy();
reload(\$table);
$mw->Unbusy();
}
else {
$dialog = $mw->Dialog(-text => 'Disk was not successfully created!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
}
};
my $addbutton = $leftframe->Button(-bitmap => 'bm_create', -command => $command, -background => 'lightsteelblue')->pack(-side => 'bottom', -anchor => 'w');
my $reloadbutton = $buttons->Button(-bitmap => 'bm_reload', -background => 'lightsteelblue', -command => sub { reload(\$table); })->pack(-side => 'right');
$tooltip->attach($reloadbutton, -msg => 'Reload Disk Data');
#my $subframe = $buttons->Frame(-background => 'lightsteelblue')->pack(-side => 'right', -padx => 10);
#my $label4 = $subframe->Label(-text => "Free Disk (GB)", -background => 'lightsteelblue')->pack(-side => 'top');
#my $sizepb = $subframe->ProgressBar(-from => 0, -to => 100, -blocks => 10, -colors => [0, 'green', 50, 'yellow' , 80, 'red'], -variable => \$diskfree)->pack(-side => 'bottom');
#my $sizelabel = $subframe->Label(-text => \$diskfree, -background => 'lightsteelblue')->pack(-side => 'bottom');
#$tooltip->attach($sizepb, -msg => 'Disk Capacity Free (%)');
#$tooltip->attach($sizelabel, -msg => 'Disk Capacity Free (%)');
my $dfscale = $buttons->Scale(-background => 'lightsteelblue', -from => 0, -to => $diskmax, -length => 100, -showvalue => 1, -state => 'disabled', -variable => \$diskfree, -orient => 'horizontal', -borderwidth => 1, -relief => 'flat', -highlightthickness => 0, -troughcolor => '#888888', -sliderlength => 14)->pack(-side => 'right', -padx => 10);
$tooltip->attach($dfscale, -msg => 'Disk Capacity Free (GB)');
$buttons->Label(-background => 'lightsteelblue', -text => ':')->pack(-side => 'right');
my $subframe = $buttons->Frame(-background => 'lightsteelblue')->pack(-side => 'right');
my $dflabel = $subframe->Label(-background => 'lightsteelblue', -text => 'Disk Free (GB)')->pack(-side => 'top');
my $dfmaxlabel = $subframe->Label(-background => 'lightsteelblue', -text => '(of '.$diskmax.')')->pack(-side => 'bottom');
reload(\$table);
$::SIG{PIPE} = sub {
wait();
};
MainLoop();
sub packBitmaps {
my $mw = shift;
my $bmref = shift;
for my $bmkey ( keys( %$bmref ) ){
my @lines = split( /\s*\n/, $bmref->{$bmkey} );
my $w = length( $lines[0] );
my $h = @lines;
$bmref->{$bmkey} = pack( "b$w"x$h, @lines );
$mw->DefineBitmap( $bmkey, $w, $h, $bmref->{$bmkey} );
}
}
sub reload {
my $table = shift;
#$table->clear();
if (defined($$table)) {
$$table->destroy();
}
$$table = $mw->Table(-scrollbars => 'osoe', -fixedrows => 1, -fixedcolumns => 7, -foreground => 'blue')->pack(-expand => 1, -fill => 'both', -side => 'bottom');
my $entries = load_data();
my $row = 1;
my $count = 7;
foreach my $label ('ID', 'Name', 'Size (GB)', 'Active', 'Protected', 'Encrypted', 'Backuped') {
my $widget = $$table->Label(-background => 'lightsteelblue', -text => $label, -relief => 'raised')->pack();
$$table->put(0, $count++, $widget);
}
my $entrynum = 0;
foreach my $entry (@$entries) {
$count = 7;
my $curbg = 'beige';
if ($entrynum % 2 == 1) {
$curbg = 'lightblue';
}
$entrynum++;
my $widget = $$table->Label(-background => 'orange', -text => $entry->{id}, -relief => 'raised')->pack();
$$table->put($row, $count++, $widget);
$widget = $$table->Label(-background => $curbg, -text => $entry->{name}, -anchor => 'w', -relief => 'groove', -padx => 5)->pack();
$$table->put($row, $count++, $widget);
my $size = sprintf("%0.2f", int(($entry->{size}/1024/1024/1024)*100)/100);
$widget = $$table->Label(-background => $curbg, -text => $size, -anchor => 'e', -relief => 'groove')->pack();
$$table->put($row, $count++, $widget);
my $button;
foreach my $label ("active", "protected", "encrypted", "backuped") {
if ($entry->{$label}) {
$button = $$table->Label(-bitmap => 'bm_yes', -foreground => 'darkgreen', -relief => 'groove', -background => $curbg)->pack();
}
else {
$button = $$table->Label(-bitmap => 'bm_no', -foreground => 'red', -relief => 'groove', -background => $curbg)->pack();
}
$$table->put($row, $count++, $button);
}
my $command;
$command = sub {
my $dialog = $mw->DialogBox(-title => 'Edit Disk', -default_button => 'Cancel', -buttons => [qw/OK Cancel/]);
my $frame = $dialog->add('Frame')->pack();
my $encrypted = $entry->{encrypted};
my $protected = $entry->{protected};
my $backuped = $entry->{backuped};
$frame->Checkbutton(-text => 'Encrypted', -variable => \$encrypted)->pack(-side => 'top', -anchor => 'w');
$frame->Checkbutton(-text => 'Backuped', -variable => \$backuped)->pack(-side => 'top', -anchor => 'w');
$frame->Checkbutton(-text => 'Protected', -variable => \$protected)->pack(-side => 'top', -anchor => 'w');
my $answer = $dialog->Show();
if ($answer eq "OK") {
$mw->Busy();
my $result = 0;
$result = system("/usr/sbin/oscontrol", "protect", int($entry->{id}), $protected) || $result;
$result = system("/usr/sbin/oscontrol", "backup", int($entry->{id}), $backuped) || $result;
$result = system("/usr/sbin/oscontrol", "encrypt", int($entry->{id}), $encrypted) || $result;
$mw->Unbusy();
if ($result == 0) {
$dialog = $mw->Dialog(-text => "Disk with ID ".int($entry->{id})." successfully edited.", -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
}
else {
$dialog = $mw->Dialog(-text => 'Disk was not successfully edited!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
$mw->Busy();
reload($table);
$mw->Unbusy();
}
};
$button = $$table->Button(-bitmap => 'bm_edit', -command => $command, -background => $curbg)->pack();
$tooltip->attach($button, -msg => 'Edit Disk');
$$table->put($row, 0, $button);
$command = sub {
my $dialog = $mw->DialogBox(-title => 'Copy Disk', -default_button => 'Cancel', -buttons => [qw/OK Cancel/]);
my $frame = $dialog->add('Frame')->pack();
$frame->Label(-text => 'Name:')->pack(-side => 'left', -fill => 'y');
my $newname = "Copy of ".$entry->{name};
$frame->Entry(-textvariable => \$newname)->pack(-side => 'left', -fill => 'both');
my $answer = $dialog->Show();
if ($answer eq "OK") {
$mw->Busy();
my $result = 0;
my $newid = -1;
if (open my $fd, "/usr/sbin/oscontrol copy ".int($entry->{id})." '".$newname."' |") {
my $answer = <$fd>;
if ($answer =~ /ok (\d+)/) {
$result = 1;
$newid = $1;
}
close $fd;
}
$mw->Unbusy();
if ($result == 1) {
$dialog = $mw->Dialog(-text => "Copy process for disk with ID $entry->{id} successfully started. New disk has id $newid.", -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
$mw->Busy();
reload($table);
$mw->Unbusy();
}
else {
$dialog = $mw->Dialog(-text => 'Disk was not successfully copied!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
}
};
$button = $$table->Button(-bitmap => 'bm_copy', -command => $command, -background => $curbg)->pack();
$tooltip->attach($button, -msg => 'Copy Disk');
$$table->put($row, 1, $button);
$command = sub {
my $dialog = $mw->DialogBox(-title => 'Transcrypt Disk', -default_button => 'Cancel', -buttons => [qw/OK Cancel/]);
my $frame = $dialog->add('Frame')->pack();
$frame->Label(-text => 'Name:')->pack(-side => 'left', -fill => 'y');
my $newname = "Copy of ".$entry->{name};
$frame->Entry(-textvariable => \$newname)->pack(-side => 'left', -fill => 'both');
my $answer = $dialog->Show();
if ($answer eq "OK") {
$mw->Busy();
my $result = 0;
my $newid = -1;
if (open my $fd, "/usr/sbin/oscontrol transcrypt ".int($entry->{id})." '".$newname."' |") {
my $answer = <$fd>;
if ($answer =~ /ok (\d+)/) {
$result = 1;
$newid = $1;
}
close $fd;
}
$mw->Unbusy();
if ($result == 1) {
$dialog = $mw->Dialog(-text => "Transcrypt process for disk with ID $entry->{id} successfully started. New disk has id $newid.", -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
$mw->Busy();
reload($table);
$mw->Unbusy();
}
else {
$dialog = $mw->Dialog(-text => 'Disk was not successfully transcrypted!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
}
};
$button = $$table->Button(-bitmap => 'bm_transcrypt', -command => $command, -background => $curbg)->pack();
$tooltip->attach($button, -msg => 'Transcrypt Disk');
$$table->put($row, 2, $button);
$command = sub {
my $dialog = $mw->Dialog(-text => 'Are you sure you want to delete the disk with ID '.int($entry->{id})." (".$entry->{name}.")?", -bitmap => 'question', -title => 'Delete Disk', -default_button => 'No', -buttons => [qw/Yes No/]);
my $answer = $dialog->Show();
if ($answer eq "Yes") {
$mw->Busy();
my $result = system("/usr/sbin/oscontrol delete ".int($entry->{id}));
$mw->Unbusy();
if ($result == 0) {
$dialog = $mw->Dialog(-text => 'Disk with ID '.int($entry->{id}).' successfully deleted.', -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
$mw->Busy();
reload($table);
$mw->Unbusy();
}
else {
$dialog = $mw->Dialog(-text => 'Disk could not be deleted!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
}
};
$button = $$table->Button(-bitmap => 'bm_delete', -command => $command, -background => $curbg, -state => $entry->{protected} || $entry->{active} ? 'disabled' : 'normal')->pack();
$tooltip->attach($button, -msg => 'Delete Disk');
$$table->put($row, 3, $button);
$command = sub {
system("osbackuppanel '".int($entry->{id})."'");
};
$button = $$table->Button(-bitmap => 'bm_backup', -command => $command, -background => $curbg, -state => 'normal')->pack();
$tooltip->attach($button, -msg => 'Disk Backups Dialog');
$$table->put($row, 4, $button);
$command = sub {
my $dialog = $mw->DialogBox(-title => 'Rename Disk', -default_button => 'Cancel', -buttons => [qw/OK Cancel/]);
my $frame = $dialog->add('Frame')->pack();
my $lframe = $frame->Frame()->pack(-side => 'top', -fill => 'x');
$lframe->Label(-text => 'Name:')->pack(-side => 'left', -fill => 'y');
my $newname = $entry->{name};
$lframe->Entry(-textvariable => \$newname)->pack(-side => 'left', -fill => 'both');
my $answer = $dialog->Show();
if ($answer eq "OK") {
$mw->Busy();
my $result = 0;
if (open my $fd, "/usr/sbin/oscontrol rename ".$entry->{id}." '".$newname."' |") {
my $answer = "";
$answer = <$fd>;
if ($answer =~ /ok/) {
$result = 1;
}
close $fd;
}
$mw->Unbusy();
if ($result == 1) {
$dialog = $mw->Dialog(-text => "Successfully renamed disk with id ".$entry->{id}, -title => 'Success', -buttons => [qw/OK/], -bitmap => 'info');
$dialog->Show();
$mw->Busy();
reload($table);
$mw->Unbusy();
}
else {
$dialog = $mw->Dialog(-text => 'Disk was not successfully renamed!', -title => 'Failed', -buttons => [qw/OK/], -bitmap => 'error');
$dialog->Show();
}
}
};
$button = $$table->Button(-bitmap => 'bm_rename', -command => $command, -background => $curbg, -state => 'normal')->pack();
$tooltip->attach($button, -msg => 'Rename Disk');
$$table->put($row, 5, $button);
$command = sub {
my $dialog = $mw->DialogBox(-title => "Migration Destination", -buttons => ["OK", "Cancel"]);
my $name;
my $validatecommand = sub {
my $data = shift;
if ($data =~ /^[-0-9a-zA-Z_\\.]+$/) {
return 1;
}
return 0;
};
$dialog->add("Entry", -width => 20, -textvariable => \$name, -validate => 'key', -validatecommand => $validatecommand)->pack();
my $button = $dialog->Show();
if ($button eq "OK") {
$mw->Busy();
system("sudo -u opensand ostransfer $entry->{id} $name");
reload($table);
$mw->Unbusy();
}
};
$button = $$table->Button(-bitmap => 'bm_migrate', -command => $command, -background => $curbg, -state => $entry->{active} ? 'disabled': 'normal')->pack();
$tooltip->attach($button, -msg => 'Migrate Disk');
$$table->put($row, 6, $button);
$row++;
}
update_diskfree();
}
sub load_data {
my $result = [];
if (open my $fd, "/usr/sbin/oscontrol list |") {
<$fd>;
while (my $line = <$fd>) {
chomp $line;
my ($id, $uuid, $size, $timestamp, $type, $status, $encrypted, $protected, $backuped, $snapshots, $backups, $comment) = split ':', $line, 12;
if ($type eq "disk") {
push @$result, ({id => $id, uuid => $uuid, name => $comment, size => $size, protected => $protected, backuped => $backuped, active => $status, encrypted => $encrypted});
}
}
close $fd;
}
@$result = sort { return lc($a->{name}) cmp lc($b->{name}); } @$result;
#push @$result, ({id => 54, name => 'Testdisk', size => '2002342424423', protected => 1, backuped => 0, encrypted => 1, active => 0}, {id => 20, name => 'Zweite Disk', size => 1024*1024*1024, protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk lsjflkjsdf lkjsd fkljs lkjs df', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1}, {id => 20, name => 'Zweite Disk', size => '2423423422352323', protected => 0, backuped => 1, encrypted => 0, active => 1});
return $result;
}
sub get_diskmax {
if (open my $fd, "/usr/sbin/oscontrol resources |") {
my $result = <$fd>;
if ($result =~ /\/(\d+)/) {
return int(${1}/1024);
}
}
return 0;
}
sub get_diskfree {
if (open my $fd, "/usr/sbin/oscontrol resources |") {
my $result = <$fd>;
if ($result =~ /(\d+)\//) {
return int(${1}/1024);
}
}
return 0;
}
sub update_diskfree {
$diskfree = get_diskfree();
}
__DATA__