]>
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.",
85 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
88 additionalProperties
=> 0,
90 node
=> get_standard_option
('pve-node'),
91 'include-partitions' => {
92 description
=> "Also include partitions.",
98 description
=> "Skip smart checks.",
104 description
=> "Only list specific types of disks.",
106 enum
=> ['unused', 'journal_disks'],
118 description
=> 'The device path',
120 used
=> { type
=> 'string', optional
=> 1 },
121 gpt
=> { type
=> 'boolean' },
122 size
=> { type
=> 'integer'},
123 osdid
=> { type
=> 'integer'},
124 vendor
=> { type
=> 'string', optional
=> 1 },
125 model
=> { type
=> 'string', optional
=> 1 },
126 serial
=> { type
=> 'string', optional
=> 1 },
127 wwn
=> { type
=> 'string', optional
=> 1},
128 health
=> { type
=> 'string', optional
=> 1},
131 description
=> 'For partitions only. The device path of ' .
132 'the disk the partition resides on.',
141 my $skipsmart = $param->{skipsmart
} // 0;
142 my $include_partitions = $param->{'include-partitions'} // 0;
144 my $disks = PVE
::Diskmanage
::get_disks
(
150 my $type = $param->{type
} // '';
153 foreach my $disk (sort keys %$disks) {
154 my $entry = $disks->{$disk};
155 if ($type eq 'journal_disks') {
156 next if $entry->{osdid
} >= 0;
157 if (my $usage = $entry->{used
}) {
158 next if !($usage eq 'partitions' && $entry->{gpt
}
161 } elsif ($type eq 'unused') {
162 next if $entry->{used
};
163 } elsif ($type ne '') {
164 die "internal error"; # should not happen
166 push @$result, $entry;
171 __PACKAGE__-
>register_method ({
175 description
=> "Get SMART Health of a disk.",
179 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
182 additionalProperties
=> 0,
184 node
=> get_standard_option
('pve-node'),
187 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
188 description
=> "Block device name",
192 description
=> "If true returns only the health status",
200 health
=> { type
=> 'string' },
201 type
=> { type
=> 'string', optional
=> 1 },
202 attributes
=> { type
=> 'array', optional
=> 1},
203 text
=> { type
=> 'string', optional
=> 1 },
209 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
211 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
213 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
214 $result = { health
=> $result->{health
} } if $param->{healthonly
};
219 __PACKAGE__-
>register_method ({
223 description
=> "Initialize Disk with GPT",
227 check
=> ['perm', '/', ['Sys.Modify']],
230 additionalProperties
=> 0,
232 node
=> get_standard_option
('pve-node'),
235 description
=> "Block device name",
236 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
240 description
=> 'UUID for the GPT table',
241 pattern
=> '[a-fA-F0-9\-]+',
247 returns
=> { type
=> 'string' },
251 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
253 my $rpcenv = PVE
::RPCEnvironment
::get
();
255 my $authuser = $rpcenv->get_user();
257 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
259 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
263 $diskid =~ s
|^.*/||; # remove all up to the last slash
264 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);