]> git.proxmox.com Git - pve-guest-common.git/commitdiff
add create_and_lock_config
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 1 Jun 2018 14:37:38 +0000 (16:37 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 12 Jun 2018 07:45:40 +0000 (09:45 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/AbstractConfig.pm

index 347398854e1cbb0e585d8aaa5eff2ba056e81e7c..11180df80df1c3bde2a515f6f9784e7256da8910 100644 (file)
@@ -82,6 +82,19 @@ sub lock_config_full {
     return $res;
 }
 
+sub create_and_lock_config {
+    my ($class, $vmid, $allow_existing) = @_;
+
+    $class->lock_config_full($vmid, 5, sub {
+       PVE::Cluster::check_vmid_unused($vmid, $allow_existing);
+
+       my $conf = eval { $class->load_config($vmid) } || {};
+       $class->check_lock($conf);
+       $conf->{lock} = 'create';
+       $class->write_config($vmid, $conf);
+    });
+}
+
 # Lock config file using flock, run $code with @param, unlock config file.
 # $timeout is the maximum time to aquire the flock
 # $shared eq 1 creates a non-exclusive ("read") flock