]> git.proxmox.com Git - pve-storage.git/commitdiff
pbs: add scan datastore helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 1 Dec 2020 18:15:49 +0000 (19:15 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 1 Dec 2020 18:22:47 +0000 (19:22 +0100)
for use in both, the scan API and the on_add/on_update hooks

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Storage/PBSPlugin.pm

index f648291077e91591e8ed0d67185abe45ebdd5cb6..f04f9f74d75de14a6bf597ba951654c241838ace 100644 (file)
@@ -645,6 +645,24 @@ my sub pbs_api_connect {
     return $conn;
 }
 
+# can also be used for not (yet) added storages, pass $scfg with
+# {
+#   server
+#   user
+#   port          (optional default to 8007)
+#   fingerprint   (optional for trusted certs)
+# }
+sub scan_datastores {
+    my ($scfg, $password) = @_;
+
+    my $conn = pbs_api_connect($scfg, $password);
+
+    my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
+    die "error fetching datastores - $@" if $@;
+
+    return $response;
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;