};
__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,
},
}});
__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'),
},
return &$api_storage_config($cfg, $param->{storage});
}});
+my sub extract_sensitive_params :prototype($$) {
+ my ($param, $delete_list) = @_;
+
+ my $sensitive;
+
+ my %delete = map { $_ => 1 } ($delete_list || [])->@*;
+
+ # always extract pw and keys, so they don't get written to the www-data readable scfg
+ for my $opt (qw(password encryption-key)) {
+ # First handle deletions as explicitly setting `undef`, afterwards new values may override
+ # it.
+ if (exists($delete{$opt})) {
+ $sensitive->{$opt} = undef;
+ }
+
+ if (defined(my $value = extract_param($param, $opt))) {
+ $sensitive->{$opt} = $value;
+ }
+ }
+
+ return $sensitive;
+}
+
__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(),
- returns => { type => 'null' },
+ returns => {
+ type => 'object',
+ properties => {
+ storage => {
+ description => "The ID of the created storage.",
+ type => 'string',
+ },
+ type => {
+ description => "The type of the created storage.",
+ type => 'string',
+ enum => $storage_type_enum,
+ },
+ config => {
+ description => "Partial, possible server generated, configuration properties.",
+ type => 'object',
+ optional => 1,
+ additionalProperties => 1,
+ properties => {
+ 'encryption-key' => {
+ description => "The, possible auto-generated, encryption-key.",
+ optional => 1,
+ type => 'string',
+ },
+ },
+ },
+ },
+ },
code => sub {
my ($param) = @_;
# fix me in section config create never need an empty entity.
delete $param->{nodes} if !$param->{nodes};
- 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}) {
- $password = $tmp_pw;
- } else {
- warn "ignore password parameter\n";
- }
- }
-
- if ($param->{portal}) {
- $param->{portal} = PVE::Storage::resolv_portal($param->{portal});
- }
+ my $sensitive = extract_sensitive_params($param, []);
my $plugin = PVE::Storage::Plugin->lookup($type);
my $opts = $plugin->check_config($storeid, $param, 1, 1);
- PVE::Storage::lock_storage_config(
- sub {
-
- my $cfg = PVE::Storage::config();
-
- if (my $scfg = PVE::Storage::storage_config($cfg, $storeid, 1)) {
- die "storage ID '$storeid' already defined\n";
- }
-
- $cfg->{ids}->{$storeid} = $opts;
-
- $plugin->on_add_hook($storeid, $opts, password => $password);
-
- my $cred_file = undef;
-
- if ($type eq 'lvm' && $opts->{base}) {
-
- my ($baseid, $volname) = PVE::Storage::parse_volume_id($opts->{base});
-
- my $basecfg = PVE::Storage::storage_config ($cfg, $baseid, 1);
- die "base storage ID '$baseid' does not exist\n" if !$basecfg;
-
- # we only support iscsi for now
- if (!($basecfg->{type} eq 'iscsi')) {
- die "unsupported base type '$basecfg->{type}'";
- }
-
- my $path = PVE::Storage::path($cfg, $opts->{base});
+ my $returned_config;
+ PVE::Storage::lock_storage_config(sub {
+ my $cfg = PVE::Storage::config();
- PVE::Storage::activate_storage($cfg, $baseid);
+ if (my $scfg = PVE::Storage::storage_config($cfg, $storeid, 1)) {
+ die "storage ID '$storeid' already defined\n";
+ }
- PVE::Storage::LVMPlugin::lvm_create_volume_group($path, $opts->{vgname}, $opts->{shared});
- } elsif ($type eq 'rbd' && !defined($opts->{monhost})) {
- my $ceph_admin_keyring = '/etc/pve/priv/ceph.client.admin.keyring';
- my $ceph_storage_keyring = "/etc/pve/priv/ceph/${storeid}.keyring";
+ $cfg->{ids}->{$storeid} = $opts;
- die "ceph authx keyring file for storage '$storeid' already exists!\n"
- if -e $ceph_storage_keyring;
+ $returned_config = $plugin->on_add_hook($storeid, $opts, %$sensitive);
- eval {
- mkdir '/etc/pve/priv/ceph';
- PVE::Tools::file_copy($ceph_admin_keyring, $ceph_storage_keyring);
- };
- if (my $err = $@) {
- unlink $ceph_storage_keyring;
- die "failed to copy ceph authx keyring for storage '$storeid': $err\n";
- }
+ eval {
+ # try to activate if enabled on local node,
+ # we only do this to detect errors/problems sooner
+ if (PVE::Storage::storage_check_enabled($cfg, $storeid, undef, 1)) {
+ PVE::Storage::activate_storage($cfg, $storeid);
}
+ };
+ if (my $err = $@) {
+ eval { $plugin->on_delete_hook($storeid, $opts) };
+ warn "$@\n" if $@;
+ die $err;
+ }
- eval {
- # try to activate if enabled on local node,
- # we only do this to detect errors/problems sooner
- if (PVE::Storage::storage_check_enabled($cfg, $storeid, undef, 1)) {
- PVE::Storage::activate_storage($cfg, $storeid);
- }
- };
- 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);
- PVE::Storage::write_config($cfg);
-
- }, "create storage failed");
+ }, "create storage failed");
- return undef;
+ my $res = {
+ storage => $storeid,
+ type => $type,
+ };
+ $res->{config} = $returned_config if $returned_config;
+ return $res;
}});
__PACKAGE__->register_method ({
path => '{storage}',
method => 'PUT',
description => "Update storage configuration.",
- permissions => {
+ permissions => {
check => ['perm', '/storage', ['Datastore.Allocate']],
},
parameters => PVE::Storage::Plugin->updateSchema(),
- returns => { type => 'null' },
+ returns => {
+ type => 'object',
+ properties => {
+ storage => {
+ description => "The ID of the created storage.",
+ type => 'string',
+ },
+ type => {
+ description => "The type of the created storage.",
+ type => 'string',
+ enum => $storage_type_enum,
+ },
+ config => {
+ description => "Partial, possible server generated, configuration properties.",
+ type => 'object',
+ optional => 1,
+ additionalProperties => 1,
+ properties => {
+ 'encryption-key' => {
+ description => "The, possible auto-generated, encryption-key.",
+ optional => 1,
+ type => 'string',
+ },
+ },
+ },
+ },
+ },
code => sub {
my ($param) = @_;
my $storeid = extract_param($param, 'storage');
my $digest = extract_param($param, 'digest');
+ my $delete = extract_param($param, 'delete');
+ my $type;
- PVE::Storage::lock_storage_config(
- sub {
+ if ($delete) {
+ $delete = [ PVE::Tools::split_list($delete) ];
+ }
+ my $returned_config;
+ 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);
+ $type = $scfg->{type};
- my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+ my $sensitive = extract_sensitive_params($param, $delete);
+
+ my $plugin = PVE::Storage::Plugin->lookup($type);
my $opts = $plugin->check_config($storeid, $param, 0, 1);
- foreach my $k (%$opts) {
+ if ($delete) {
+ my $options = $plugin->private()->{options}->{$type};
+ foreach my $k (@$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};
+ }
+ }
+
+ $returned_config = $plugin->on_update_hook($storeid, $opts, %$sensitive);
+
+ for my $k (keys %$opts) {
$scfg->{$k} = $opts->{$k};
}
PVE::Storage::write_config($cfg);
- }, "update storage failed");
+ }, "update storage failed");
- return undef;
+ my $res = {
+ storage => $storeid,
+ type => $type,
+ };
+ $res->{config} = $returned_config if $returned_config;
+ return $res;
}});
__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,
- }),
+ completion => \&PVE::Storage::complete_storage,
+ }),
},
},
returns => { type => 'null' },
my $storeid = extract_param($param, 'storage');
- PVE::Storage::lock_storage_config(
- sub {
-
- my $cfg = PVE::Storage::config();
-
- my $scfg = PVE::Storage::storage_config($cfg, $storeid);
+ PVE::Storage::lock_storage_config(sub {
+ my $cfg = PVE::Storage::config();
- die "can't remove storage - storage is used as base of another storage\n"
- if PVE::Storage::storage_is_used($cfg, $storeid);
+ my $scfg = PVE::Storage::storage_config($cfg, $storeid);
- my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+ die "can't remove storage - storage is used as base of another storage\n"
+ if PVE::Storage::storage_is_used($cfg, $storeid);
- $plugin->on_delete_hook($storeid, $scfg);
+ my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
- if ($scfg->{type} eq 'rbd' && !defined($scfg->{monhost})) {
- my $ceph_storage_keyring = "/etc/pve/priv/ceph/${storeid}.keyring";
- if (-f $ceph_storage_keyring) {
- unlink($ceph_storage_keyring) or warn "removing keyring of storage failed: $!\n";
- }
- }
+ $plugin->on_delete_hook($storeid, $scfg);
- delete $cfg->{ids}->{$storeid};
+ delete $cfg->{ids}->{$storeid};
- PVE::Storage::write_config($cfg);
+ PVE::Storage::write_config($cfg);
- }, "delete storage failed");
+ }, "delete storage failed");
PVE::AccessControl::remove_storage_access($storeid);