mirror of
https://github.com/kolesa-team/pve-purestorage-plugin.git
synced 2026-08-12 21:53:06 -06:00
+20
-44
@@ -11,7 +11,7 @@ use File::Path ();
|
||||
|
||||
use PVE::JSONSchema ();
|
||||
use PVE::Network ();
|
||||
use PVE::Tools qw( run_command );
|
||||
use PVE::Tools qw( file_read_firstline run_command );
|
||||
use PVE::INotify ();
|
||||
use PVE::Storage::Plugin ();
|
||||
|
||||
@@ -172,7 +172,7 @@ sub scsi_scan_new {
|
||||
next unless $host =~ /^(\w+)$/;
|
||||
$path = '/sys/class/scsi_host/' . $1; # untaint
|
||||
if ( -d $path ) {
|
||||
device_op($path, 'scan', '- - -');
|
||||
device_op( $path, 'scan', '- - -' );
|
||||
++$count;
|
||||
} else {
|
||||
warn "Warning :: SCSI host path $path does not exist.\n";
|
||||
@@ -323,7 +323,7 @@ sub purestorage_name {
|
||||
sub get_device_path_wwn {
|
||||
my ( $serial ) = @_;
|
||||
|
||||
die "Error :: Volume serial is missing" unless length( $serial );
|
||||
die 'Error :: Volume serial is missing' unless length( $serial );
|
||||
|
||||
# Construct the WWN path
|
||||
my $wwn = lc( $purestorage_wwn_prefix . $serial );
|
||||
@@ -332,27 +332,20 @@ sub get_device_path_wwn {
|
||||
}
|
||||
|
||||
sub get_device_size {
|
||||
my ( $path ) = @_;
|
||||
print "Debug :: get_device_size($path)\n" if $DEBUG;
|
||||
my $size = 0;
|
||||
my ( $device ) = @_;
|
||||
print "Debug :: get_device_size($device)\n" if $DEBUG;
|
||||
|
||||
exec_command(
|
||||
[ 'blockdev', '--getsize64', $path ],
|
||||
1,
|
||||
outfunc => sub {
|
||||
$size = $_[0];
|
||||
chomp $size;
|
||||
}
|
||||
);
|
||||
my $path = '/sys/block/' . basename( $device ) . '/size';
|
||||
my $size = file_read_firstline( $path ) << 9;
|
||||
|
||||
print "Debug :: Detected size: $size\n" if $DEBUG;
|
||||
print "Debug :: Device \"$device\" size is $size bytes\n" if $DEBUG;
|
||||
return $size;
|
||||
}
|
||||
|
||||
sub device_op {
|
||||
my ( $device_path, $op, $value ) = @_;
|
||||
|
||||
open( my $fh, '>', $device_path . '/' . $op ) or die "Could not open file \"$device_path/$op\" for writing.\n";
|
||||
open( my $fh, '>', $device_path . '/' . $op ) or die "Error :: Could not open file \"$device_path/$op\" for writing.\n";
|
||||
print $fh $value;
|
||||
close( $fh );
|
||||
}
|
||||
@@ -981,49 +974,32 @@ sub free_image {
|
||||
|
||||
sub list_images {
|
||||
my ( $class, $storeid, $scfg, $vmid, $vollist, $cache ) = @_;
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::list_images\n" if $DEBUG;
|
||||
|
||||
my $key = type() . ':' . $storeid;
|
||||
if ( $cache->{ $key } ) {
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::list_images::cached\n" if $DEBUG;
|
||||
} else {
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::list_images\n" if $DEBUG;
|
||||
$cache->{ $key } = $class->purestorage_list_volumes( $scfg, $vmid, $storeid, 0 );
|
||||
}
|
||||
|
||||
return $cache->{ $key };
|
||||
return $class->purestorage_list_volumes( $scfg, $vmid, $storeid, 0 );
|
||||
}
|
||||
|
||||
sub status {
|
||||
my ( $class, $storeid, $scfg, $cache ) = @_;
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::status\n" if $DEBUG;
|
||||
|
||||
$cache = $cache->{ type() . ':' . $storeid } //= {};
|
||||
$cache->{ last_update } //= 0;
|
||||
my $response = purestorage_api_request( $scfg, { name => 'get array space', type => 'arrays/space', method => 'GET' } );
|
||||
|
||||
my $current_time = gettimeofday();
|
||||
if ( $current_time - $cache->{ last_update } >= 60 ) {
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::status\n" if $DEBUG;
|
||||
# Get storage capacity and used space from the response
|
||||
my $array = $response->{ items }->[0];
|
||||
my $total = $array->{ capacity };
|
||||
my $used = $array->{ space }->{ total_physical };
|
||||
|
||||
my $response = purestorage_api_request( $scfg, { name => 'get array space', type => 'arrays/space', method => 'GET' } );
|
||||
|
||||
# Get storage capacity and used space from the response
|
||||
$cache->{ total } = $response->{ items }->[0]->{ capacity };
|
||||
$cache->{ used } = $response->{ items }->[0]->{ space }->{ total_physical };
|
||||
|
||||
# $cache->{ used } = $response->{ items }->[0]->{ space }->{ total_used }; # Do not know what is correct
|
||||
|
||||
$cache->{ last_update } = $current_time;
|
||||
} else {
|
||||
print "Debug :: PVE::Storage::Custom::PureStoragePlugin::sub::status::cached\n" if $DEBUG;
|
||||
}
|
||||
# my $used = $array->{ space }->{ total_used }; # Do not know what is correct
|
||||
|
||||
# Calculate free space
|
||||
my $free = $cache->{ total } - $cache->{ used };
|
||||
my $free = $total - $used;
|
||||
|
||||
# Mark storage as active
|
||||
my $active = 1;
|
||||
|
||||
# Return total, free, used space and the active status
|
||||
return ( $cache->{ total }, $free, $cache->{ used }, $active );
|
||||
return ( $total, $free, $used, $active );
|
||||
}
|
||||
|
||||
sub activate_storage {
|
||||
|
||||
Reference in New Issue
Block a user