[pve-devel] [PATCH v3 container 07/23] Implement volume-related helpers and use new foreach_volume
Fabian Ebner
f.ebner at proxmox.com
Thu Mar 12 13:15:51 CET 2020
Forgot to change the 23 in the subject here and for patch #8
Should be 22; sorry for the noise.
On 3/12/20 1:08 PM, Fabian Ebner wrote:
> Renames mountpoint_names to avoid the need to create a wrapper.
>
> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
> ---
> src/PVE/API2/LXC.pm | 4 ++--
> src/PVE/CLI/pct.pm | 2 +-
> src/PVE/LXC/Config.pm | 38 ++++++++++++++++++++++++++++----------
> 3 files changed, 31 insertions(+), 13 deletions(-)
>
> diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
> index a48cf95..ddd067c 100644
> --- a/src/PVE/API2/LXC.pm
> +++ b/src/PVE/API2/LXC.pm
> @@ -1587,7 +1587,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',
> @@ -1749,7 +1749,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', {
> diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
> index 5c36669..934d9aa 100755
> --- a/src/PVE/CLI/pct.pm
> +++ b/src/PVE/CLI/pct.pm
> @@ -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()],
> },
> },
> },
> diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
> index e88ba0b..ee74984 100644
> --- a/src/PVE/LXC/Config.pm
> +++ b/src/PVE/LXC/Config.pm
> @@ -181,7 +181,7 @@ sub __snapshot_rollback_get_unused {
>
> my $unused = [];
>
> - $class->__snapshot_foreach_volume($conf, sub {
> + $class->foreach_volume($conf, undef, sub {
> my ($vs, $volume) = @_;
>
> return if $volume->{type} ne 'volume';
> @@ -189,7 +189,7 @@ sub __snapshot_rollback_get_unused {
> my $found = 0;
> my $volid = $volume->{volume};
>
> - $class->__snapshot_foreach_volume($snap, sub {
> + $class->foreach_volume($snap, undef, sub {
> my ($ms, $mountpoint) = @_;
>
> return if $found;
> @@ -205,12 +205,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
> @@ -1076,6 +1070,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);
> @@ -1443,7 +1461,7 @@ sub get_cmode {
> return $conf->{cmode} // $confdesc->{cmode}->{default};
> }
>
> -sub mountpoint_names {
> +sub valid_volume_keys {
> my ($class, $reverse) = @_;
>
> my @names = ('rootfs');
> @@ -1458,7 +1476,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);
>
More information about the pve-devel
mailing list