]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/API2/Disks.pm
code cleanup
[pve-storage.git] / PVE / API2 / Disks.pm
index d7030f88b991f3cf587d674822245eecf661af16..807e9b2dc73292331780caeab46d9f3d41dd844f 100644 (file)
@@ -3,16 +3,39 @@ package PVE::API2::Disks;
 use strict;
 use warnings;
 
-use PVE::SafeSyslog;
-use PVE::Diskmanage;
 use HTTP::Status qw(:constants);
+
+use PVE::Diskmanage;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::SafeSyslog;
 
-use PVE::RESTHandler;
+use PVE::API2::Disks::Directory;
+use PVE::API2::Disks::LVM;
+use PVE::API2::Disks::LVMThin;
+use PVE::API2::Disks::ZFS;
 
+use PVE::RESTHandler;
 use base qw(PVE::RESTHandler);
 
-use Data::Dumper;
+__PACKAGE__->register_method ({
+   subclass => "PVE::API2::Disks::LVM",
+   path => 'lvm',
+});
+
+__PACKAGE__->register_method ({
+   subclass => "PVE::API2::Disks::LVMThin",
+   path => 'lvmthin',
+});
+
+__PACKAGE__->register_method ({
+   subclass => "PVE::API2::Disks::Directory",
+   path => 'directory',
+});
+
+__PACKAGE__->register_method ({
+   subclass => "PVE::API2::Disks::ZFS",
+   path => 'zfs',
+});
 
 __PACKAGE__->register_method ({
     name => 'index',
@@ -42,7 +65,11 @@ __PACKAGE__->register_method ({
            { name => 'list' },
            { name => 'initgpt' },
            { name => 'smart' },
-           ];
+           { name => 'lvm' },
+           { name => 'lvmthin' },
+           { name => 'directory' },
+           { name => 'zfs' },
+       ];
 
        return $result;
     }});
@@ -61,6 +88,18 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            node => get_standard_option('pve-node'),
+           skipsmart => {
+               description => "Skip smart checks.",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
+           },
+           type => {
+               description => "Only list specific types of disks.",
+               type => 'string',
+               enum => ['unused', 'journal_disks'],
+               optional => 1,
+           },
        },
     },
     returns => {
@@ -87,12 +126,23 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $disks = PVE::Diskmanage::get_disks();
+       my $skipsmart = $param->{skipsmart} // 0;
+
+       my $disks = PVE::Diskmanage::get_disks(undef, $skipsmart);
 
+       my $type = $param->{type} // '';
        my $result = [];
 
        foreach my $disk (sort keys %$disks) {
            my $entry = $disks->{$disk};
+           if ($type eq 'journal_disks') {
+               next if $entry->{osdid} >= 0;
+               next if !($entry->{gpt} || !$entry->{used} || $entry->{used} eq 'LVM');
+           } elsif ($type eq 'unused') {
+               next if $entry->{used};
+           } elsif ($type ne '') {
+               die "internal error"; # should not happen
+           }
            push @$result, $entry;
        }
        return $result;
@@ -124,21 +174,24 @@ __PACKAGE__->register_method ({
            },
        },
     },
-    returns => { type => 'object' },
+    returns => {
+       type => 'object',
+       properties => {
+           health => { type => 'string' },
+           type => { type => 'string', optional => 1 },
+           attributes => { type => 'array', optional => 1},
+           text => { type => 'string', optional => 1 },
+       },
+    },
     code => sub {
        my ($param) = @_;
 
        my $disk = PVE::Diskmanage::verify_blockdev_path($param->{disk});
 
-       my $result = {};
-
-       if ($param->{healthonly}) {
-           $result = { health => PVE::Diskmanage::get_smart_health($disk) };
-       } else {
-           $result = PVE::Diskmanage::get_smart_data($disk);
-       }
+       my $result = PVE::Diskmanage::get_smart_data($disk, $param->{healthonly});
 
-       $result->{health} = 'UNKOWN' if !defined $result->{health};
+       $result->{health} = 'UNKNOWN' if !defined $result->{health};
+       $result = { health => $result->{health} } if $param->{healthonly};
 
        return $result;
     }});