[pve-devel] [PATCH container 16/20] add helper to get the lxc version

w.bumiller at proxmox.com w.bumiller at proxmox.com
Fri Apr 3 16:37:36 CEST 2020


From: Wolfgang Bumiller <w.bumiller at proxmox.com>

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/LXC.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 9033322..de4389d 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2346,4 +2346,20 @@ sub copy_volume {
     return $new_volid;
 }
 
+sub get_lxc_version() {
+    my $version;
+    PVE::Tools::run_command([qw(lxc-start --version)], outfunc => sub {
+	my ($line) = @_;
+	# We only parse out major & minor version numbers.
+	if ($line =~ /^(\d+)\.(\d+)(?:\D.*)?$/) {
+	    $version = [$1, $2];
+	}
+    });
+
+    die "failed to get lxc version\n" if !defined($version);
+
+    # return as a list:
+    return $version->@*;
+}
+
 1;
-- 
2.20.1





More information about the pve-devel mailing list