]>
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);
13 use base
qw(PVE::RESTHandler);
17 __PACKAGE__-
>register_method ({
22 permissions
=> { user
=> 'all' },
23 description
=> "Node index.",
25 additionalProperties
=> 0,
27 node
=> get_standard_option
('pve-node'),
36 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
43 { name
=> 'initgpt' },
50 __PACKAGE__-
>register_method ({
54 description
=> "List local disks.",
58 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
61 additionalProperties
=> 0,
63 node
=> get_standard_option
('pve-node'),
73 description
=> 'The device path',
75 used
=> { type
=> 'string', optional
=> 1 },
76 gpt
=> { type
=> 'boolean' },
77 size
=> { type
=> 'integer'},
78 osdid
=> { type
=> 'integer'},
79 vendor
=> { type
=> 'string', optional
=> 1 },
80 model
=> { type
=> 'string', optional
=> 1 },
81 serial
=> { type
=> 'string', optional
=> 1 },
82 wwn
=> { type
=> 'string', optional
=> 1},
83 health
=> { type
=> 'string', optional
=> 1},
90 my $disks = PVE
::Diskmanage
::get_disks
();
94 foreach my $disk (sort keys %$disks) {
95 my $entry = $disks->{$disk};
96 push @$result, $entry;
101 __PACKAGE__-
>register_method ({
105 description
=> "Get SMART Health of a disk.",
109 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
112 additionalProperties
=> 0,
114 node
=> get_standard_option
('pve-node'),
117 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
118 description
=> "Block device name",
122 description
=> "If true returns only the health status",
127 returns
=> { type
=> 'object' },
131 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
135 if ($param->{healthonly
}) {
136 $result = { health
=> PVE
::Diskmanage
::get_smart_health
($disk) };
138 $result = PVE
::Diskmanage
::get_smart_data
($disk);
141 $result->{health
} = 'UNKOWN' if !defined $result->{health
};
146 __PACKAGE__-
>register_method ({
150 description
=> "Initialize Disk with GPT",
154 check
=> ['perm', '/', ['Sys.Modify']],
157 additionalProperties
=> 0,
159 node
=> get_standard_option
('pve-node'),
162 description
=> "Block device name",
163 pattern
=> '^/dev/[a-zA-Z0-9\/]+$',
167 description
=> 'UUID for the GPT table',
168 pattern
=> '[a-fA-F0-9\-]+',
174 returns
=> { type
=> 'string' },
178 my $disk = PVE
::Diskmanage
::verify_blockdev_path
($param->{disk
});
180 my $rpcenv = PVE
::RPCEnvironment
::get
();
182 my $authuser = $rpcenv->get_user();
184 die "disk $disk already in use\n" if PVE
::Diskmanage
::disk_is_used
($disk);
186 PVE
::Diskmanage
::init_disk
($disk, $param->{uuid
});
190 $diskid =~ s
|^.*/||; # remove all up to the last slash
191 return $rpcenv->fork_worker('diskinit', $diskid, $authuser, $worker);