[pve-devel] [PATCH V2 storage 08/10] Add cifsscan to API

Wolfgang Link w.link at proxmox.com
Fri Mar 16 10:22:57 CET 2018


---
 PVE/API2/Storage/Scan.pm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/PVE/API2/Storage/Scan.pm b/PVE/API2/Storage/Scan.pm
index 11d139f..e9ce18e 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,56 @@ __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' },
+	    username => { type => 'string', optional => 1 },
+	    password => { type => 'string', optional => 1 },
+	    domain => { type => 'string', optional => 1 },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {
+		share => { type => 'string'},
+		description => { type => 'string'},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $server = $param->{server};
+
+	my $username = $param->{username};
+	my $password = $param->{password};
+	my $domain = $param->{domain};
+
+	my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain);
+
+	my $data = [];
+	foreach my $k (keys %$res) {
+	    next if $k =~ m/NT_STATUS_/;
+	    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/
-- 
2.11.0





More information about the pve-devel mailing list