]>
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'),
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 if (my $usage = $entry->{used
}) {
141 next if !($usage eq 'partitions' && $entry->{gpt
}
144 } elsif ($type eq 'unused') {
145 next if $entry->{used
};
146 } elsif ($type ne '') {
147 die "internal error"; # should not happen
149 push @$result, $entry;
154 __PACKAGE__-
>register_method ({
158 description
=> "Get SMART Health of a disk.",
162 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
165 additionalProperties
=> 0,
167 node
=> get_standard_option
('pve-node'),
170 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
171 description
=> "Block device name",
175 description
=> "If true returns only the health status",
183 health
=> { type
=> 'string' },
184 type
=> { type
=> 'string', optional
=> 1 },
185 attributes
=> { type
=> 'array', optional
=> 1},
186 text
=> { type
=> 'string', optional
=> 1 },
192 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
194 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
196 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
197 $result = { health
=> $result->{health
} } if $param->{healthonly
};
202 __PACKAGE__-
>register_method ({
206 description
=> "Initialize Disk with GPT",
210 check
=> ['perm', '/', ['Sys.Modify']],
213 additionalProperties
=> 0,
215 node
=> get_standard_option
('pve-node'),
218 description
=> "Block device name",
219 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
223 description
=> 'UUID for the GPT table',
224 pattern
=> '[a-fA-F0-9\-]+',
230 returns
=> { type
=> 'string' },
234 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
236 my $rpcenv = PVE
::RPCEnvironment
::get
();
238 my $authuser = $rpcenv->get_user();
240 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
242 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
246 $diskid =~ s
|^.*/||; # remove all up to the last slash
247 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);