]> git.proxmox.com Git - pve-storage.git/commitdiff
api/cli: add pbs scan endpoint and command
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 1 Dec 2020 18:21:43 +0000 (19:21 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 1 Dec 2020 18:22:47 +0000 (19:22 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Storage/Scan.pm
PVE/CLI/pvesm.pm

index bd6c264923ef10414697721b4092ab04704ff0fb..76fbd812dfa21112ec27f2f38fa3f94bc1196cf7 100644 (file)
@@ -47,6 +47,7 @@ __PACKAGE__->register_method({
            { method => 'iscsi' },
            { method => 'lvm' },
            { method => 'nfs' },
+           { method => 'pbs' },
            { method => 'usb' },
            { method => 'zfs' },
        ];
@@ -174,6 +175,71 @@ __PACKAGE__->register_method({
        return $data;
     }});
 
+__PACKAGE__->register_method({
+    name => 'pbsscan',
+    path => 'pbs',
+    method => 'GET',
+    description => "Scan remote Proxmox Backup Server.",
+    protected => 1,
+    proxyto => "node",
+    permissions => {
+       check => ['perm', '/storage', ['Datastore.Allocate']],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           server => {
+               description => "The server address (name or IP).",
+               type => 'string', format => 'pve-storage-server',
+           },
+           username => {
+               description => "User-name or API token-ID.",
+               type => 'string',
+           },
+           password => {
+               description => "User password or API token secret.",
+               type => 'string',
+           },
+           fingerprint => get_standard_option('fingerprint-sha256', {
+               optional => 1,
+           }),
+           port => {
+               description => "Optional port.",
+               type => 'integer',
+               minimum => 1,
+               maximum => 65535,
+               default => 8007,
+               optional => 1,
+           },
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {
+               store => {
+                   description => "The datastore name.",
+                   type => 'string',
+               },
+               comment => {
+                   description => "Comment from server.",
+                   type => 'string',
+                   optional => 1,
+               },
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $password = delete $param->{password};
+
+       return PVE::Storage::PBSPlugin::scan_datastores($param, $password);
+    }
+});
+
 # Note: GlusterFS currently does not have an equivalent of showmount.
 # As workaround, we simply use nfs showmount.
 # see http://www.gluster.org/category/volumes/
index 8f7740e9ed145ce675d747cd5f1616ced102727e..3594774efb169ad1a8a8df0348313b797554be24 100755 (executable)
@@ -54,6 +54,7 @@ sub param_mapping {
     my $mapping = {
        'cifsscan' => [ $password_map ],
        'cifs' => [ $password_map ],
+       'pbs' => [ $password_map ],
        'create' => [ $password_map, $enc_key_map ],
        'update' => [ $password_map, $enc_key_map ],
     };
@@ -506,6 +507,11 @@ __PACKAGE__->register_method ({
        };
     }});
 
+my $print_api_result = sub {
+    my ($data, $schema, $options) = @_;
+    PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+};
+
 our $cmddef = {
     add => [ "PVE::API2::Storage::Config", 'create', ['type', 'storage'] ],
     set => [ "PVE::API2::Storage::Config", 'update', ['storage'] ],
@@ -577,6 +583,14 @@ our $cmddef = {
                printf "$rec->{lv}\n";
            }
        }],
+       pbs => [
+           "PVE::API2::Storage::Scan",
+           'pbsscan',
+           ['server', 'username'],
+           { node => $nodename },
+           $print_api_result,
+           $PVE::RESTHandler::standard_output_options,
+       ],
        zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub  {
            my $res = shift;