]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/API2/Storage/Config.pm
config: add missing whitespace
[pve-storage.git] / PVE / API2 / Storage / Config.pm
index 434b1f3a7e5ea30f6a5fa201fd048f1de3e5e159..09c5d5928727785a248e14be7f833002ffc6b631 100755 (executable)
@@ -39,20 +39,20 @@ my $api_storage_config = sub {
 };
 
 __PACKAGE__->register_method ({
-    name => 'index', 
+    name => 'index',
     path => '',
     method => 'GET',
     description => "Storage index.",
-    permissions => { 
+    permissions => {
        description => "Only list entries where you have 'Datastore.Audit' or 'Datastore.AllocateSpace' permissions on '/storage/<storage>'",
        user => 'all',
     },
     parameters => {
-       additionalProperties => 0,
+       additionalProperties => 0,
        properties => {
-           type => { 
+           type => {
                description => "Only list storage of specific type",
-               type => 'string', 
+               type => 'string',
                enum => $storage_type_enum,
                optional => 1,
            },
@@ -90,15 +90,15 @@ __PACKAGE__->register_method ({
     }});
 
 __PACKAGE__->register_method ({
-    name => 'read', 
+    name => 'read',
     path => '{storage}',
     method => 'GET',
     description => "Read storage configuration.",
-    permissions => { 
+    permissions => {
        check => ['perm', '/storage/{storage}', ['Datastore.Allocate']],
     },
     parameters => {
-       additionalProperties => 0,
+       additionalProperties => 0,
        properties => {
            storage => get_standard_option('pve-storage-id'),
        },
@@ -115,10 +115,10 @@ __PACKAGE__->register_method ({
 __PACKAGE__->register_method ({
     name => 'create',
     protected => 1,
-    path => '', 
+    path => '',
     method => 'POST',
     description => "Create a new storage.",
-    permissions => { 
+    permissions => {
        check => ['perm', '/storage', ['Datastore.Allocate']],
     },
     parameters => PVE::Storage::Plugin->createSchema(),
@@ -136,17 +136,13 @@ __PACKAGE__->register_method ({
        my $password;
        # always extract pw, else it gets written to the www-data readable scfg
        if (my $tmp_pw = extract_param($param, 'password')) {
-           if ($type eq 'cifs' && $param->{username}) {
+           if (($type eq 'pbs') || ($type eq 'cifs' && $param->{username})) {
                $password = $tmp_pw;
            } else {
                warn "ignore password parameter\n";
            }
        }
 
-       if ($param->{portal}) {
-           $param->{portal} = PVE::Storage::resolv_portal($param->{portal});
-       }
-
        my $plugin = PVE::Storage::Plugin->lookup($type);
        my $opts = $plugin->check_config($storeid, $param, 1, 1);
 
@@ -163,8 +159,6 @@ __PACKAGE__->register_method ({
 
                $plugin->on_add_hook($storeid, $opts, password => $password);
 
-               my $cred_file = undef;
-
                eval {
                    # try to activate if enabled on local node,
                    # we only do this to detect errors/problems sooner
@@ -172,15 +166,14 @@ __PACKAGE__->register_method ({
                        PVE::Storage::activate_storage($cfg, $storeid);
                    }
                };
-               if(my $err = $@) {
+               if (my $err = $@) {
                    eval { $plugin->on_delete_hook($storeid, $opts) };
                    warn "$@\n" if $@;
-                   unlink $cred_file if defined($cred_file);
                    die $err;
                }
 
                PVE::Storage::write_config($cfg);
-           
+
            }, "create storage failed");
 
        return undef;
@@ -192,7 +185,7 @@ __PACKAGE__->register_method ({
     path => '{storage}',
     method => 'PUT',
     description => "Update storage configuration.",
-    permissions => { 
+    permissions => {
        check => ['perm', '/storage', ['Datastore.Allocate']],
     },
     parameters => PVE::Storage::Plugin->updateSchema(),
@@ -202,26 +195,60 @@ __PACKAGE__->register_method ({
 
        my $storeid = extract_param($param, 'storage');
        my $digest = extract_param($param, 'digest');
+       my $delete = extract_param($param, 'delete');
 
-        PVE::Storage::lock_storage_config(
-        sub {
+        PVE::Storage::lock_storage_config(sub {
 
            my $cfg = PVE::Storage::config();
 
            PVE::SectionConfig::assert_if_modified($cfg, $digest);
 
            my $scfg = PVE::Storage::storage_config($cfg, $storeid);
+           my $type = $scfg->{type};
+
+           my $password;
+           # always extract pw, else it gets written to the www-data readable scfg
+           if (my $tmp_pw = extract_param($param, 'password')) {
+               if (($type eq 'pbs') || ($type eq 'cifs' && $param->{username})) {
+                   $password = $tmp_pw;
+               } else {
+                   warn "ignore password parameter\n";
+               }
+           }
 
-           my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+           my $plugin = PVE::Storage::Plugin->lookup($type);
            my $opts = $plugin->check_config($storeid, $param, 0, 1);
 
-           foreach my $k (%$opts) {
+           my $delete_password = 0;
+
+           if ($delete) {
+               my $options = $plugin->private()->{options}->{$type};
+               foreach my $k (PVE::Tools::split_list($delete)) {
+                   my $d = $options->{$k} || die "no such option '$k'\n";
+                   die "unable to delete required option '$k'\n" if !$d->{optional};
+                   die "unable to delete fixed option '$k'\n" if $d->{fixed};
+                   die "cannot set and delete property '$k' at the same time!\n"
+                       if defined($opts->{$k});
+
+                   delete $scfg->{$k};
+
+                   $delete_password = 1 if $k eq 'password';
+               }
+           }
+
+           if ($delete_password || defined($password)) {
+               $plugin->on_update_hook($storeid, $opts, password => $password);
+           } else {
+               $plugin->on_update_hook($storeid, $opts);
+           }
+
+           for my $k (keys %$opts) {
                $scfg->{$k} = $opts->{$k};
            }
 
            PVE::Storage::write_config($cfg);
 
-           }, "update storage failed");
+       }, "update storage failed");
 
        return undef;
     }});
@@ -232,12 +259,12 @@ __PACKAGE__->register_method ({
     path => '{storage}', # /storage/config/{storage}
     method => 'DELETE',
     description => "Delete storage configuration.",
-    permissions => { 
+    permissions => {
        check => ['perm', '/storage', ['Datastore.Allocate']],
     },
     parameters => {
-       additionalProperties => 0,
-       properties => { 
+       additionalProperties => 0,
+       properties => {
            storage => get_standard_option('pve-storage-id', {
                 completion => \&PVE::Storage::complete_storage,
             }),