[pve-devel] [PATCH v2 pve-manager 22/22] PVE::API2::ReplicationConfig - implement proxyto_callback for delete

Dietmar Maurer dietmar at proxmox.com
Mon May 29 11:30:06 CEST 2017


We want to execute delete on the node where the guest resides.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/API2/ReplicationConfig.pm | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/ReplicationConfig.pm b/PVE/API2/ReplicationConfig.pm
index 6f4de385..a4279b44 100644
--- a/PVE/API2/ReplicationConfig.pm
+++ b/PVE/API2/ReplicationConfig.pm
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 
 use PVE::Tools qw(extract_param);
-use PVE::Exception qw(raise_perm_exc);
+use PVE::Exception qw(raise_perm_exc raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
 use PVE::ReplicationConfig;
@@ -112,7 +112,6 @@ __PACKAGE__->register_method ({
 	my $code = sub {
 	    my $cfg = PVE::ReplicationConfig->new();
 
-	    #die "replication job for guest '$param->{guest}' to target '$param->{target}' already exists\n"
 	    die "replication job '$id' already exists\n"
 		if $cfg->{ids}->{$id};
 
@@ -175,6 +174,31 @@ __PACKAGE__->register_method ({
     permissions => {
 	check => ['perm', '/storage', ['Datastore.Allocate']],
     },
+    proxyto_callback => sub {
+	my ($rpcenv, $proxyto, $param) = @_;
+
+	return 'localhost' if $param->{keep}; # do not care it this case
+
+	# proxy to the node where the guest resides
+
+	my $id = $param->{id};
+
+	raise_param_exc({ id =>  "missing replication job id"}) if !$id;
+
+	my $cfg = PVE::ReplicationConfig->new();
+	my $data = $cfg->{ids}->{$id};
+	raise_param_exc({ id =>  "no such job '$id'"}) if !$data;
+
+	return 'localhost' if $data->{type} ne 'local';
+
+        my $vmid = $data->{guest};
+
+	my $vms = PVE::Cluster::get_vmlist();
+
+	return 'localhost' if !$vms->{ids}->{$vmid};
+
+	return $vms->{ids}->{$vmid}->{node};
+    },
     parameters => {
     	additionalProperties => 0,
 	properties => {
@@ -193,6 +217,11 @@ __PACKAGE__->register_method ({
 
 	my $id = extract_param($param, 'id');
 
+	if (!$param->{keep}) {
+	    # try to remove data on target
+
+	}
+
 	my $code = sub {
 	    my $cfg = PVE::ReplicationConfig->new();
 
-- 
2.11.0




More information about the pve-devel mailing list