]> git.proxmox.com Git - pve-container.git/commitdiff
Implement volume-related helpers and use new foreach_volume
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 26 Mar 2020 08:09:39 +0000 (09:09 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 27 Mar 2020 13:14:21 +0000 (14:14 +0100)
Renames mountpoint_names to avoid the need to create a wrapper.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/CLI/pct.pm
src/PVE/LXC/Config.pm

index e0289634c5588863472864a1eb069884e640c603..f4c1a49fa795417ae18f34d8188c6699d5dda4d2 100644 (file)
@@ -1570,7 +1570,7 @@ __PACKAGE__->register_method({
            disk => {
                type => 'string',
                description => "The disk you want to resize.",
-               enum => [PVE::LXC::Config->mountpoint_names()],
+               enum => [PVE::LXC::Config->valid_volume_keys()],
            },
            size => {
                type => 'string',
@@ -1732,7 +1732,7 @@ __PACKAGE__->register_method({
            vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
            volume => {
                type => 'string',
-               enum => [ PVE::LXC::Config->mountpoint_names() ],
+               enum => [ PVE::LXC::Config->valid_volume_keys() ],
                description => "Volume which will be moved.",
            },
            storage => get_standard_option('pve-storage-id', {
index 5c3666956b108812a6ccbf4ddd97482d3c68f818..934d9aa3e482add4d9bcfb269c091261d802c692 100755 (executable)
@@ -210,7 +210,7 @@ __PACKAGE__->register_method ({
                optional => 1,
                type => 'string',
                description => "A volume on which to run the filesystem check",
-               enum => [PVE::LXC::Config->mountpoint_names()],
+               enum => [PVE::LXC::Config->valid_volume_keys()],
            },
        },
     },
index 1434dc8ec4425a5c1bb5e1da875a10c4c6f44a2e..6cc4e4a76a7d73308c8edd31b9f3e82f393b9762 100644 (file)
@@ -186,7 +186,7 @@ sub __snapshot_rollback_get_unused {
 
     my $unused = [];
 
-    $class->__snapshot_foreach_volume($conf, sub {
+    $class->foreach_volume($conf, sub {
        my ($vs, $volume) = @_;
 
        return if $volume->{type} ne 'volume';
@@ -194,7 +194,7 @@ sub __snapshot_rollback_get_unused {
        my $found = 0;
        my $volid = $volume->{volume};
 
-       $class->__snapshot_foreach_volume($snap, sub {
+       $class->foreach_volume($snap, sub {
            my ($ms, $mountpoint) = @_;
 
            return if $found;
@@ -210,12 +210,6 @@ sub __snapshot_rollback_get_unused {
     return $unused;
 }
 
-sub __snapshot_foreach_volume {
-    my ($class, $conf, $func) = @_;
-
-    $class->foreach_mountpoint($conf, $func);
-}
-
 # END implemented abstract methods from PVE::AbstractConfig
 
 # BEGIN JSON config code
@@ -1088,6 +1082,30 @@ sub print_ct_mountpoint {
     return PVE::JSONSchema::print_property_string($info, $mp_desc, $skip);
 }
 
+sub parse_volume {
+    my ($class, $key, $volume_string, $noerr) = @_;
+
+    if ($key eq 'rootfs') {
+       return $class->parse_ct_rootfs($volume_string, $noerr);
+    } elsif ($key =~ m/^mp\d+$/ || $key =~ m/^unused\d+$/) {
+       return $class->parse_ct_mountpoint($volume_string, $noerr);
+    }
+
+    die "parse_volume - unknown type: $key\n";
+}
+
+sub print_volume {
+    my ($class, $key, $volume) = @_;
+
+    return $class->print_ct_mountpoint($volume, $key eq 'rootfs');
+}
+
+sub volid_key {
+    my ($class) = @_;
+
+    return 'volume';
+}
+
 sub print_lxc_network {
     my ($class, $net) = @_;
     return PVE::JSONSchema::print_property_string($net, $netconf_desc);
@@ -1455,7 +1473,7 @@ sub get_cmode {
     return $conf->{cmode} // $confdesc->{cmode}->{default};
 }
 
-sub mountpoint_names {
+sub valid_volume_keys {
     my ($class, $reverse) = @_;
 
     my @names = ('rootfs');
@@ -1470,7 +1488,7 @@ sub mountpoint_names {
 sub foreach_mountpoint_full {
     my ($class, $conf, $reverse, $func, @param) = @_;
 
-    my $mps = [ grep { defined($conf->{$_}) } $class->mountpoint_names($reverse) ];
+    my $mps = [ grep { defined($conf->{$_}) } $class->valid_volume_keys($reverse) ];
     foreach my $key (@$mps) {
        my $value = $conf->{$key};
        my $mountpoint = $key eq 'rootfs' ? $class->parse_ct_rootfs($value, 1) : $class->parse_ct_mountpoint($value, 1);