]>
Commit | Line | Data |
---|---|---|
1dc01b9f DM |
1 | package PVE::Storage::DirPlugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use File::Path; | |
6 | use PVE::Storage::Plugin; | |
7 | use PVE::JSONSchema qw(get_standard_option); | |
8 | ||
9 | use base qw(PVE::Storage::Plugin); | |
10 | ||
11 | # Configuration | |
12 | ||
13 | sub type { | |
14 | return 'dir'; | |
15 | } | |
16 | ||
17 | sub plugindata { | |
18 | return { | |
19 | content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, none => 1 }, | |
20 | { images => 1, rootdir => 1 }], | |
35533c68 | 21 | format => [ { raw => 1, qcow2 => 1, vmdk => 1, subvol => 1 } , 'raw' ], |
1dc01b9f DM |
22 | }; |
23 | } | |
24 | ||
25 | sub properties { | |
26 | return { | |
27 | path => { | |
28 | description => "File system path.", | |
29 | type => 'string', format => 'pve-storage-path', | |
30 | }, | |
b521247b WB |
31 | mkdir => { |
32 | description => "Create the directory if it doesn't exist.", | |
33 | type => 'boolean', | |
34 | default => 'yes', | |
35 | }, | |
1dc01b9f DM |
36 | }; |
37 | } | |
38 | ||
39 | sub options { | |
40 | return { | |
41 | path => { fixed => 1 }, | |
42 | nodes => { optional => 1 }, | |
43 | shared => { optional => 1 }, | |
44 | disable => { optional => 1 }, | |
45 | maxfiles => { optional => 1 }, | |
46 | content => { optional => 1 }, | |
47 | format => { optional => 1 }, | |
b521247b | 48 | mkdir => { optional => 1 }, |
1dc01b9f DM |
49 | }; |
50 | } | |
51 | ||
52 | # Storage implementation | |
53 | ||
54 | sub activate_storage { | |
55 | my ($class, $storeid, $scfg, $cache) = @_; | |
56 | ||
b521247b WB |
57 | if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) { |
58 | my $path = $scfg->{path}; | |
59 | mkpath $path; | |
60 | } | |
1dc01b9f DM |
61 | |
62 | $class->SUPER::activate_storage($storeid, $scfg, $cache); | |
63 | } | |
64 | ||
5c95e484 WB |
65 | sub check_config { |
66 | my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_; | |
67 | my $opts = PVE::SectionConfig::check_config($self, $sectionId, $config, $create, $skipSchemaCheck); | |
68 | return $opts if !$create; | |
69 | if ($opts->{path} !~ m@^/[-/a-zA-Z0-9_.]+$@) { | |
70 | die "illegal path for directory storage: $opts->{path}\n"; | |
71 | } | |
72 | return $opts; | |
73 | } | |
1dc01b9f DM |
74 | |
75 | 1; |