[pve-devel] [PATCH pve-container 2/2] add -ignore-unpack-errors

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Nov 20 11:54:51 CET 2015


In some cases the user may genuinly want to ignore unpacking
errors. (Like permission denied errors on mknod commands in
some templates where the user might choose to work around
the problem manually in the running container.)
---
 src/PVE/API2/LXC.pm   | 9 ++++++++-
 src/PVE/LXC/Create.pm | 9 +++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 165e327..0a80dfc 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -142,6 +142,11 @@ __PACKAGE__->register_method({
 		type => 'string', format => 'pve-poolid',
 		description => "Add the VM to the specified pool.",
 	    },
+	    'ignore-unpack-errors' => {
+		optional => 1,
+		type => 'boolean',
+		description => "Ignore errors when extracting the template.",
+	    },
 	}),
     },
     returns => {
@@ -158,6 +163,8 @@ __PACKAGE__->register_method({
 
 	my $vmid = extract_param($param, 'vmid');
 
+	my $ignore_unpack_errors = extract_param($param, 'ignore-unpack-errors');
+
 	my $basecfg_fn = PVE::LXC::config_file($vmid);
 
 	my $same_container_exists = -f $basecfg_fn;
@@ -298,7 +305,7 @@ __PACKAGE__->register_method({
 
 		$vollist = PVE::LXC::create_disks($storage_cfg, $vmid, $param, $conf);
 
-		PVE::LXC::Create::create_rootfs($storage_cfg, $vmid, $conf, $archive, $password, $restore);
+		PVE::LXC::Create::create_rootfs($storage_cfg, $vmid, $conf, $archive, $password, $restore, $ignore_unpack_errors);
 		# set some defaults
 		$conf->{hostname} ||= "CT$vmid";
 		$conf->{memory} ||= 512;
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 7051fcc..07ecf73 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -132,9 +132,10 @@ sub recover_config {
 }
 
 sub restore_and_configure {
-    my ($vmid, $archive, $rootdir, $conf, $password, $restore) = @_;
+    my ($vmid, $archive, $rootdir, $conf, $password, $restore, $no_unpack_error) = @_;
 
-    restore_archive($archive, $rootdir, $conf);
+    eval { restore_archive($archive, $rootdir, $conf) };
+    die $@ if $@ && !$no_unpack_error;
 
     if (!$restore) {
 	my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); # detect OS
@@ -180,7 +181,7 @@ sub restore_and_configure {
 }
 
 sub create_rootfs {
-    my ($storage_cfg, $vmid, $conf, $archive, $password, $restore) = @_;
+    my ($storage_cfg, $vmid, $conf, $archive, $password, $restore, $no_unpack_error) = @_;
 
     my $config_fn = PVE::LXC::config_file($vmid);
     if (-f $config_fn) {
@@ -210,7 +211,7 @@ sub create_rootfs {
 
     eval {
 	my $rootdir = PVE::LXC::mount_all($vmid, $storage_cfg, $conf);
-        restore_and_configure($vmid, $archive, $rootdir, $conf, $password, $restore);
+        restore_and_configure($vmid, $archive, $rootdir, $conf, $password, $restore, $no_unpack_error);
     };
     if (my $err = $@) {
 	die $err;
-- 
2.1.4





More information about the pve-devel mailing list