implement zfsscan to list local zfs pools
This commit is contained in:
@ -44,11 +44,43 @@ __PACKAGE__->register_method ({
|
|||||||
{ method => 'nfs' },
|
{ method => 'nfs' },
|
||||||
{ method => 'glusterfs' },
|
{ method => 'glusterfs' },
|
||||||
{ method => 'usb' },
|
{ method => 'usb' },
|
||||||
|
{ method => 'zfs' },
|
||||||
];
|
];
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
__PACKAGE__->register_method ({
|
||||||
|
name => 'zfsscan',
|
||||||
|
path => 'zfs',
|
||||||
|
method => 'GET',
|
||||||
|
description => "Scan zfs pool list on local node.",
|
||||||
|
protected => 1,
|
||||||
|
proxyto => "node",
|
||||||
|
permissions => {
|
||||||
|
check => ['perm', '/storage', ['Datastore.Allocate']],
|
||||||
|
},
|
||||||
|
parameters => {
|
||||||
|
additionalProperties => 0,
|
||||||
|
properties => {
|
||||||
|
node => get_standard_option('pve-node'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
returns => {
|
||||||
|
type => 'array',
|
||||||
|
items => {
|
||||||
|
type => "object",
|
||||||
|
properties => {
|
||||||
|
pool => { type => 'string'},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
code => sub {
|
||||||
|
my ($param) = @_;
|
||||||
|
|
||||||
|
return PVE::Storage::scan_zfs();
|
||||||
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
name => 'nfsscan',
|
name => 'nfsscan',
|
||||||
path => 'nfs',
|
path => 'nfs',
|
||||||
|
|||||||
@ -911,6 +911,25 @@ sub scan_nfs {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub scan_zfs {
|
||||||
|
|
||||||
|
my $cmd = ['zpool', 'list', '-H', '-o', 'name,size,free'];
|
||||||
|
|
||||||
|
my $res = [];
|
||||||
|
run_command($cmd, outfunc => sub {
|
||||||
|
my $line = shift;
|
||||||
|
|
||||||
|
if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
|
||||||
|
my ($pool, $size_str, $free_str) = ($1, $2, $3);
|
||||||
|
my $size = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($size_str);
|
||||||
|
my $free = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($free_str);
|
||||||
|
push @$res, { pool => $pool, size => $size, free => $free };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
sub resolv_portal {
|
sub resolv_portal {
|
||||||
my ($portal, $noerr) = @_;
|
my ($portal, $noerr) = @_;
|
||||||
|
|
||||||
|
|||||||
8
pvesm
8
pvesm
@ -172,6 +172,14 @@ my $cmddef = {
|
|||||||
printf "$rec->{vg}\n";
|
printf "$rec->{vg}\n";
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
zfsscan => [ "PVE::API2::Storage::Scan", 'zfsscan', [],
|
||||||
|
{ node => $nodename }, sub {
|
||||||
|
my $res = shift;
|
||||||
|
|
||||||
|
foreach my $rec (@$res) {
|
||||||
|
printf "$rec->{pool}\n";
|
||||||
|
}
|
||||||
|
}],
|
||||||
path => [ __PACKAGE__, 'path', ['volume']],
|
path => [ __PACKAGE__, 'path', ['volume']],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user