X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FAPI2%2FQemu.pm;h=c566c4d8d2a153c3371d1031ea89e3f6480dfad4;hb=dd32a4664f3f13fc5bf2490b796e8b27f98e0156;hp=80bc141b5817bcc0339bb9f60dfc5633231559a5;hpb=6d449202baab081ea334d0b18fd47d3ba9cd95ec;p=qemu-server.git diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 80bc141..c566c4d 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -24,7 +24,6 @@ use PVE::INotify; use PVE::Network; use PVE::Firewall; use PVE::API2::Firewall::VM; -use PVE::ReplicationTools; BEGIN { if (!$ENV{PVE_GENERATING_DOCS}) { @@ -120,7 +119,8 @@ my $create_disks = sub { my $vollist = []; my $res = {}; - PVE::QemuServer::foreach_drive($settings, sub { + + my $code = sub { my ($ds, $disk) = @_; my $volid = $disk->{file}; @@ -128,7 +128,7 @@ my $create_disks = sub { if (!$volid || $volid eq 'none' || $volid eq 'cdrom') { delete $disk->{size}; $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk); - } elsif ($volid =~ m/^(([^:\s]+):)?(\d+(\.\d+)?)$/) { + } elsif ($volid =~ m!^(([^/:\s]+):)?(\d+(\.\d+)?)$!) { my ($storeid, $size) = ($2 || $default_storage, $3); die "no storage ID specified (and no default storage)\n" if !$storeid; my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid); @@ -191,7 +191,9 @@ my $create_disks = sub { $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk); } - }); + }; + + eval { PVE::QemuServer::foreach_drive($settings, $code); }; # free allocated images on error if (my $err = $@) { @@ -1029,16 +1031,6 @@ my $update_vm_api = sub { if defined($conf->{pending}->{$opt}); PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force); PVE::QemuConfig->write_config($vmid, $conf); - } elsif ($opt eq "replica" || $opt eq "replica_target") { - delete $conf->{$opt}; - delete $conf->{replica} if $opt eq "replica_target"; - - PVE::ReplicationTools::job_remove($vmid); - PVE::QemuConfig->write_config($vmid, $conf); - } elsif ($opt eq "replica_interval" || $opt eq "replica_rate_limit") { - delete $conf->{$opt}; - PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt}); - PVE::QemuConfig->write_config($vmid, $conf); } else { PVE::QemuServer::vmconfig_delete_pending_option($conf, $opt, $force); PVE::QemuConfig->write_config($vmid, $conf); @@ -1061,26 +1053,11 @@ my $update_vm_api = sub { if defined($conf->{pending}->{$opt}); &$create_disks($rpcenv, $authuser, $conf->{pending}, $storecfg, $vmid, undef, {$opt => $param->{$opt}}); - } elsif ($opt eq "replica") { - die "Not all volumes are syncable, please check your config\n" - if !PVE::ReplicationTools::check_guest_volumes_syncable($conf, 'qemu'); - die "replica_target is required\n" - if !$conf->{replica_target} && !$param->{replica_target}; - my $value = $param->{$opt}; - if ($value) { - PVE::ReplicationTools::job_enable($vmid); - } else { - PVE::ReplicationTools::job_disable($vmid); - } - $conf->{$opt} = $param->{$opt}; - } elsif ($opt eq "replica_interval" || $opt eq "replica_rate_limit") { - $conf->{$opt} = $param->{$opt}; - PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt}); - } elsif ($opt eq "replica_target" ) { - die "Node: $param->{$opt} does not exists in Cluster.\n" - if !PVE::Cluster::check_node_exists($param->{$opt}); - PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt}) - if defined($conf->{$opt}); + } elsif ($opt eq "replicate") { + # check if all volumes have replicate feature + PVE::QemuConfig->get_replicatable_volumes($storecfg, $conf); + my $repl = PVE::JSONSchema::check_format('pve-replicate', $param->{opt}); + PVE::Cluster::check_node_exists($repl->{target}); $conf->{$opt} = $param->{$opt}; } else { $conf->{pending}->{$opt} = $param->{$opt}; @@ -1317,9 +1294,6 @@ __PACKAGE__->register_method({ syslog('info', "destroy VM $vmid: $upid\n"); - # return without error if vm has no replica job - PVE::ReplicationTools::destroy_replica($vmid); - PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock); PVE::AccessControl::remove_vm_access($vmid); @@ -1459,6 +1433,7 @@ __PACKAGE__->register_method({ $cmd = [@$remcmd, "/usr/sbin/qm", 'vncproxy', $vmid]; my $sock = IO::Socket::IP->new( + ReuseAddr => 1, Listen => 1, LocalPort => $port, Proto => 'tcp', @@ -1484,7 +1459,7 @@ __PACKAGE__->register_method({ return; }; - my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $authuser, $realcmd); + my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $authuser, $realcmd, 1); PVE::Tools::wait_for_vnc_port($port);