]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Disks.pm
1 package PVE
::API2
::Disks
;
6 use HTTP
::Status
qw(:constants);
9 use PVE
::JSONSchema
qw(get_standard_option);
12 use PVE
::API2
::Disks
::Directory
;
13 use PVE
::API2
::Disks
::LVM
;
14 use PVE
::API2
::Disks
::LVMThin
;
15 use PVE
::API2
::Disks
::ZFS
;
18 use base
qw(PVE::RESTHandler);
20 __PACKAGE__-
>register_method ({
21 subclass
=> "PVE::API2::Disks::LVM",
25 __PACKAGE__-
>register_method ({
26 subclass
=> "PVE::API2::Disks::LVMThin",
30 __PACKAGE__-
>register_method ({
31 subclass
=> "PVE::API2::Disks::Directory",
35 __PACKAGE__-
>register_method ({
36 subclass
=> "PVE::API2::Disks::ZFS",
40 __PACKAGE__-
>register_method ({
45 permissions
=> { user
=> 'all' },
46 description
=> "Node index.",
48 additionalProperties
=> 0,
50 node
=> get_standard_option
('pve-node'),
59 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
66 { name
=> 'initgpt' },
69 { name
=> 'lvmthin' },
70 { name
=> 'directory' },
77 __PACKAGE__-
>register_method ({
81 description
=> "List local disks.",
86 ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
87 ['perm', '/nodes/{node}', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
91 additionalProperties
=> 0,
93 node
=> get_standard_option
('pve-node'),
94 'include-partitions' => {
95 description
=> "Also include partitions.",
101 description
=> "Skip smart checks.",
107 description
=> "Only list specific types of disks.",
109 enum
=> ['unused', 'journal_disks'],
121 description
=> 'The device path',
123 used
=> { type
=> 'string', optional
=> 1 },
124 gpt
=> { type
=> 'boolean' },
125 size
=> { type
=> 'integer'},
126 osdid
=> { type
=> 'integer'},
127 vendor
=> { type
=> 'string', optional
=> 1 },
128 model
=> { type
=> 'string', optional
=> 1 },
129 serial
=> { type
=> 'string', optional
=> 1 },
130 wwn
=> { type
=> 'string', optional
=> 1},
131 health
=> { type
=> 'string', optional
=> 1},
134 description
=> 'For partitions only. The device path of ' .
135 'the disk the partition resides on.',
144 my $skipsmart = $param->{skipsmart
} // 0;
145 my $include_partitions = $param->{'include-partitions'} // 0;
147 my $disks = PVE
::Diskmanage
::get_disks
(
153 my $type = $param->{type
} // '';
156 foreach my $disk (sort keys %$disks) {
157 my $entry = $disks->{$disk};
158 if ($type eq 'journal_disks') {
159 next if $entry->{osdid
} >= 0;
160 if (my $usage = $entry->{used
}) {
161 next if !($usage eq 'partitions' && $entry->{gpt
}
164 } elsif ($type eq 'unused') {
165 next if $entry->{used
};
166 } elsif ($type ne '') {
167 die "internal error"; # should not happen
169 push @$result, $entry;
174 __PACKAGE__-
>register_method ({
178 description
=> "Get SMART Health of a disk.",
182 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
185 additionalProperties
=> 0,
187 node
=> get_standard_option
('pve-node'),
190 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
191 description
=> "Block device name",
195 description
=> "If true returns only the health status",
203 health
=> { type
=> 'string' },
204 type
=> { type
=> 'string', optional
=> 1 },
205 attributes
=> { type
=> 'array', optional
=> 1},
206 text
=> { type
=> 'string', optional
=> 1 },
212 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
214 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
216 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
217 $result = { health
=> $result->{health
} } if $param->{healthonly
};
222 __PACKAGE__-
>register_method ({
226 description
=> "Initialize Disk with GPT",
230 check
=> ['perm', '/', ['Sys.Modify']],
233 additionalProperties
=> 0,
235 node
=> get_standard_option
('pve-node'),
238 description
=> "Block device name",
239 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
243 description
=> 'UUID for the GPT table',
244 pattern
=> '[a-fA-F0-9\-]+',
250 returns
=> { type
=> 'string' },
254 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
256 my $rpcenv = PVE
::RPCEnvironment
::get
();
258 my $authuser = $rpcenv->get_user();
260 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
262 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
266 $diskid =~ s
|^.*/||; # remove all up to the last slash
267 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);