]>
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
;
16 use base
qw(PVE::RESTHandler);
18 __PACKAGE__-
>register_method ({
19 subclass
=> "PVE::API2::Disks::LVM",
23 __PACKAGE__-
>register_method ({
24 subclass
=> "PVE::API2::Disks::LVMThin",
28 __PACKAGE__-
>register_method ({
33 permissions
=> { user
=> 'all' },
34 description
=> "Node index.",
36 additionalProperties
=> 0,
38 node
=> get_standard_option
('pve-node'),
47 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
54 { name
=> 'initgpt' },
57 { name
=> 'lvmthin' },
63 __PACKAGE__-
>register_method ({
67 description
=> "List local disks.",
71 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
74 additionalProperties
=> 0,
76 node
=> get_standard_option
('pve-node'),
78 description
=> "Skip smart checks.",
84 description
=> "Only list specific types of disks.",
86 enum
=> ['unused', 'journal_disks'],
98 description
=> 'The device path',
100 used
=> { type
=> 'string', optional
=> 1 },
101 gpt
=> { type
=> 'boolean' },
102 size
=> { type
=> 'integer'},
103 osdid
=> { type
=> 'integer'},
104 vendor
=> { type
=> 'string', optional
=> 1 },
105 model
=> { type
=> 'string', optional
=> 1 },
106 serial
=> { type
=> 'string', optional
=> 1 },
107 wwn
=> { type
=> 'string', optional
=> 1},
108 health
=> { type
=> 'string', optional
=> 1},
115 my $skipsmart = $param->{skipsmart
} // 0;
117 my $disks = PVE
::Diskmanage
::get_disks
(undef, $skipsmart);
119 my $type = $param->{type
} // '';
122 foreach my $disk (sort keys %$disks) {
123 my $entry = $disks->{$disk};
124 if ($type eq 'journal_disks') {
125 next if $entry->{osdid
} >= 0;
126 next if !$entry->{gpt
};
127 } elsif ($type eq 'unused') {
128 next if $entry->{used
};
129 } elsif ($type ne '') {
130 die "internal error"; # should not happen
132 push @$result, $entry;
137 __PACKAGE__-
>register_method ({
141 description
=> "Get SMART Health of a disk.",
145 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
148 additionalProperties
=> 0,
150 node
=> get_standard_option
('pve-node'),
153 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
154 description
=> "Block device name",
158 description
=> "If true returns only the health status",
166 health
=> { type
=> 'string' },
167 type
=> { type
=> 'string', optional
=> 1 },
168 attributes
=> { type
=> 'array', optional
=> 1},
169 text
=> { type
=> 'string', optional
=> 1 },
175 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
177 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
179 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
180 $result = { health
=> $result->{health
} } if $param->{healthonly
};
185 __PACKAGE__-
>register_method ({
189 description
=> "Initialize Disk with GPT",
193 check
=> ['perm', '/', ['Sys.Modify']],
196 additionalProperties
=> 0,
198 node
=> get_standard_option
('pve-node'),
201 description
=> "Block device name",
202 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
206 description
=> 'UUID for the GPT table',
207 pattern
=> '[a-fA-F0-9\-]+',
213 returns
=> { type
=> 'string' },
217 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
219 my $rpcenv = PVE
::RPCEnvironment
::get
();
221 my $authuser = $rpcenv->get_user();
223 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
225 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
229 $diskid =~ s
|^.*/||; # remove all up to the last slash
230 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);