]>
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
;
17 use base
qw(PVE::RESTHandler);
19 __PACKAGE__-
>register_method ({
20 subclass
=> "PVE::API2::Disks::LVM",
24 __PACKAGE__-
>register_method ({
25 subclass
=> "PVE::API2::Disks::LVMThin",
29 __PACKAGE__-
>register_method ({
30 subclass
=> "PVE::API2::Disks::Directory",
34 __PACKAGE__-
>register_method ({
39 permissions
=> { user
=> 'all' },
40 description
=> "Node index.",
42 additionalProperties
=> 0,
44 node
=> get_standard_option
('pve-node'),
53 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
60 { name
=> 'initgpt' },
63 { name
=> 'lvmthin' },
64 { name
=> 'directory' },
70 __PACKAGE__-
>register_method ({
74 description
=> "List local disks.",
78 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
81 additionalProperties
=> 0,
83 node
=> get_standard_option
('pve-node'),
85 description
=> "Skip smart checks.",
91 description
=> "Only list specific types of disks.",
93 enum
=> ['unused', 'journal_disks'],
105 description
=> 'The device path',
107 used
=> { type
=> 'string', optional
=> 1 },
108 gpt
=> { type
=> 'boolean' },
109 size
=> { type
=> 'integer'},
110 osdid
=> { type
=> 'integer'},
111 vendor
=> { type
=> 'string', optional
=> 1 },
112 model
=> { type
=> 'string', optional
=> 1 },
113 serial
=> { type
=> 'string', optional
=> 1 },
114 wwn
=> { type
=> 'string', optional
=> 1},
115 health
=> { type
=> 'string', optional
=> 1},
122 my $skipsmart = $param->{skipsmart
} // 0;
124 my $disks = PVE
::Diskmanage
::get_disks
(undef, $skipsmart);
126 my $type = $param->{type
} // '';
129 foreach my $disk (sort keys %$disks) {
130 my $entry = $disks->{$disk};
131 if ($type eq 'journal_disks') {
132 next if $entry->{osdid
} >= 0;
133 next if !$entry->{gpt
};
134 } elsif ($type eq 'unused') {
135 next if $entry->{used
};
136 } elsif ($type ne '') {
137 die "internal error"; # should not happen
139 push @$result, $entry;
144 __PACKAGE__-
>register_method ({
148 description
=> "Get SMART Health of a disk.",
152 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
155 additionalProperties
=> 0,
157 node
=> get_standard_option
('pve-node'),
160 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
161 description
=> "Block device name",
165 description
=> "If true returns only the health status",
173 health
=> { type
=> 'string' },
174 type
=> { type
=> 'string', optional
=> 1 },
175 attributes
=> { type
=> 'array', optional
=> 1},
176 text
=> { type
=> 'string', optional
=> 1 },
182 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
184 my $result = PVE
::Diskmanage
::get_smart_data
($disk, $param->{healthonly
});
186 $result->{health
} = 'UNKNOWN' if !defined $result->{health
};
187 $result = { health
=> $result->{health
} } if $param->{healthonly
};
192 __PACKAGE__-
>register_method ({
196 description
=> "Initialize Disk with GPT",
200 check
=> ['perm', '/', ['Sys.Modify']],
203 additionalProperties
=> 0,
205 node
=> get_standard_option
('pve-node'),
208 description
=> "Block device name",
209 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
213 description
=> 'UUID for the GPT table',
214 pattern
=> '[a-fA-F0-9\-]+',
220 returns
=> { type
=> 'string' },
224 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
226 my $rpcenv = PVE
::RPCEnvironment
::get
();
228 my $authuser = $rpcenv->get_user();
230 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
232 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
236 $diskid =~ s
|^.*/||; # remove all up to the last slash
237 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);