[pve-devel] [RFC pve-storage 2/2] add cifs_scan
Wolfgang Link
w.link at proxmox.com
Wed Oct 5 14:48:06 CEST 2016
---
PVE/API2/Storage/Scan.pm | 41 +++++++++++++++++++++++++++++++++++++++++
PVE/Storage.pm | 24 ++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/PVE/API2/Storage/Scan.pm b/PVE/API2/Storage/Scan.pm
index 11d139f..14e6a3c 100644
--- a/PVE/API2/Storage/Scan.pm
+++ b/PVE/API2/Storage/Scan.pm
@@ -45,6 +45,7 @@ __PACKAGE__->register_method ({
{ method => 'glusterfs' },
{ method => 'usb' },
{ method => 'zfs' },
+ { method => 'cifs' },
];
return $res;
@@ -121,6 +122,46 @@ __PACKAGE__->register_method ({
return $data;
}});
+__PACKAGE__->register_method ({
+ name => 'cifsscan',
+ path => 'cifs',
+ method => 'GET',
+ description => "Scan remote CIFS server.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ server => { type => 'string', format => 'pve-storage-server' },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ share => { type => 'string'},
+ description => { type => 'string'},
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $server = $param->{server};
+ my $res = PVE::Storage::scan_cifs($server);
+
+ my $data = [];
+ foreach my $k (keys %$res) {
+ push @$data, { share => $k, description => $res->{$k} };
+ }
+ return $data;
+ }});
+
# Note: GlusterFS currently does not have an equivalent of showmount.
# As workaround, we simply use nfs showmount.
# see http://www.gluster.org/category/volumes/
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 978a2fe..6988b71 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1108,6 +1108,30 @@ sub scan_nfs {
return $res;
}
+sub scan_cifs {
+ my ($server_in) = @_;
+
+ my $server;
+ if (!($server = resolv_server ($server_in))) {
+ die "unable to resolve address for server '${server_in}'\n";
+ }
+
+ my $cmd = ['/usr/bin/smbclient', '-N', '-L', $server];
+
+ my $res = {};
+ run_command($cmd, outfunc => sub {
+ my $line = shift;
+
+ if ($line =~ m/(\S+)\s*Disk\s*(\S*)/) {
+ $res->{$1} = $2;
+ }
+ },
+ errfunc => sub {}
+ );
+
+ return $res;
+}
+
sub scan_zfs {
my $cmd = ['zfs', 'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
--
2.1.4
More information about the pve-devel
mailing list