default => 'metadata',
optional => 1,
},
+ dirs => {
+ description => "Overrides for default directories",
+ type => "string", format => "pve-dir-override-list",
+ optional => 1,
+ },
},
};
return $def->{content}->[0];
}
+sub dirs_hash_to_string {
+ my $hash = shift;
+
+ return join(',', map { "$_:$hash->{$_}" } sort keys %$hash);
+}
+
sub default_format {
my ($scfg) = @_;
die "unable to parse volume ID '$volid'\n";
}
+PVE::JSONSchema::register_format('pve-dir-override', \&verify_dir_override);
+sub verify_dir_override {
+ my ($value, $noerr) = @_;
+
+ if($value =~ m/^([a-z]+):(.+)$/ &&
+ verify_content($1, $noerr) && verify_path($2, $noerr)) {
+ return $value;
+ }
+
+ return undef if $noerr;
+ die "invalid override '$value'\n";
+}
sub private {
return $defaultData;
# die "storage '$storeid' does not allow node restrictions\n";
#}
+ return $res;
+ } elsif ($key eq 'dirs') {
+ my $valid_content = $def->{content}->[0];
+ my $res = {};
+
+ foreach my $dir (PVE::Tools::split_list($value)) {
+ my ($content, $path) = split(/:/, $dir, 2);
+
+ if (!$valid_content->{$content}) {
+ warn "storage does not support content type '$content'\n";
+ next;
+ }
+
+ $res->{$content} = $path;
+ }
+
return $res;
}
} elsif ($key eq 'content') {
my $res = content_hash_to_string($value) || 'none';
return $res;
+ } elsif ($key eq 'dirs') {
+ my $res = dirs_hash_to_string($value);
+ return $res;
}
return $value;
my $path = $scfg->{path};
die "storage definition has no path\n" if !$path;
+ die "unknown vtype '$vtype'\n" if !exists($vtype_subdirs->{$vtype});
- my $subdir = $vtype_subdirs->{$vtype};
-
- die "unknown vtype '$vtype'\n" if !defined($subdir);
+ my $subdir = $scfg->{dirs}->{$vtype} // "/".$vtype_subdirs->{$vtype};
- return "$path/$subdir";
+ return $path.$subdir;
}
sub filesystem_path {
push @$tests, [ $scfg_with_path, $type, $path ];
}
+# creates additional tests for overrides
+foreach my $type (keys %$vtype_subdirs) {
+ my $override = "/${type}_override";
+ my $scfg_with_override = { path => '/some/path', dirs => { $type => $override } };
+ push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}$scfg_with_override->{dirs}->{$type}" ];
+}
+
plan tests => scalar @$tests;
foreach my $tt (@$tests) {