]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Disks.pm
1 package PVE
::API2
::Disks
;
8 use HTTP
::Status
qw(:constants);
9 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::API2
::Disks
::LVM
;
12 use PVE
::API2
::Disks
::LVMThin
;
13 use PVE
::API2
::Disks
::Directory
;
14 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'),
92 description
=> "Skip smart checks.",
98 description
=> "Only list specific types of disks.",
100 enum
=> ['unused', 'journal_disks'],
112 description
=> 'The device path',
114 used
=> { type
=> 'string', optional
=> 1 },
115 gpt
=> { type
=> 'boolean' },
116 size
=> { type
=> 'integer'},
117 osdid
=> { type
=> 'integer'},
118 vendor
=> { type
=> 'string', optional
=> 1 },
119 model
=> { type
=> 'string', optional
=> 1 },
120 serial
=> { type
=> 'string', optional
=> 1 },
121 wwn
=> { type
=> 'string', optional
=> 1},
122 health
=> { type
=> 'string', optional
=> 1},
129 my $skipsmart = $param->{skipsmart
} // 0;
131 my $disks = PVE
::Diskmanage
::get_disks
(undef, $skipsmart);
133 my $type = $param->{type
} // '';
136 foreach my $disk (sort keys %$disks) {
137 my $entry = $disks->{$disk};
138 if ($type eq 'journal_disks') {
139 next if $entry->{osdid
} >= 0;
140 next if !($entry->{gpt
} || !$entry->{used
} || $entry->{used
} eq 'LVM');
141 } elsif ($type eq 'unused') {
142 next if $entry->{used
};
143 } elsif ($type ne '') {
144 die "internal error"; # should not happen
146 push @$result, $entry;
151 __PACKAGE__-
>register_method ({
155 description
=> "Get SMART Health of a disk.",
159 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
162 additionalProperties
=> 0,
164 node
=> get_standard_option
('pve-node'),
167 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
168 description
=> "Block device name",
172 description
=> "If true returns only the health status",
180 health
=> { type
=> 'string' },
181 type
=> { type
=> 'string', optional
=> 1 },
182 attributes
=> { type
=> 'array', optional
=> 1},
183 text
=> { type
=> 'string', optional
=> 1 },
189 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
191 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
193 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
194 $result = { health
=> $result->{health
} } if $param->{healthonly
};
199 __PACKAGE__-
>register_method ({
203 description
=> "Initialize Disk with GPT",
207 check
=> ['perm', '/', ['Sys.Modify']],
210 additionalProperties
=> 0,
212 node
=> get_standard_option
('pve-node'),
215 description
=> "Block device name",
216 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
220 description
=> 'UUID for the GPT table',
221 pattern
=> '[a-fA-F0-9\-]+',
227 returns
=> { type
=> 'string' },
231 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
233 my $rpcenv = PVE
::RPCEnvironment
::get
();
235 my $authuser = $rpcenv->get_user();
237 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
239 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
243 $diskid =~ s
|^.*/||; # remove all up to the last slash
244 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);