[pve-devel] [PATCH pve-manager 3/3] PVE::API2::ReplicationConfig - extract guest ID from job ID

Dietmar Maurer dietmar at proxmox.com
Tue Jun 6 13:02:35 CEST 2017


Ther is no need to pass an additional guest parameter.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/API2/ReplicationConfig.pm |  9 ++++++++-
 PVE/CLI/pvesr.pm              | 26 +++++++++++---------------
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/PVE/API2/ReplicationConfig.pm b/PVE/API2/ReplicationConfig.pm
index 69d56aed..6dd3e15b 100644
--- a/PVE/API2/ReplicationConfig.pm
+++ b/PVE/API2/ReplicationConfig.pm
@@ -91,6 +91,9 @@ __PACKAGE__->register_method ({
 	return $data;
     }});
 
+my $create_schema = PVE::ReplicationConfig->createSchema();
+delete $create_schema->{properties}->{guest};
+
 __PACKAGE__->register_method ({
     name => 'create',
     path => '',
@@ -100,7 +103,7 @@ __PACKAGE__->register_method ({
     permissions => {
 	check => ['perm', '/storage', ['Datastore.Allocate']],
     },
-    parameters => PVE::ReplicationConfig->createSchema(),
+    parameters => $create_schema,
     returns => { type => 'null' },
     code => sub {
 	my ($param) = @_;
@@ -109,6 +112,10 @@ __PACKAGE__->register_method ({
 	my $plugin = PVE::ReplicationConfig->lookup($type);
 	my $id = extract_param($param, 'id');
 
+	# extract guest ID from job ID
+	my ($guest) = PVE::ReplicationConfig::parse_replication_job_id($id);
+	$param->{guest} = $guest;
+
 	my $code = sub {
 	    my $cfg = PVE::ReplicationConfig->new();
 
diff --git a/PVE/CLI/pvesr.pm b/PVE/CLI/pvesr.pm
index cd107f0e..dc367638 100644
--- a/PVE/CLI/pvesr.pm
+++ b/PVE/CLI/pvesr.pm
@@ -34,7 +34,6 @@ __PACKAGE__->register_method ({
 	additionalProperties => 0,
 	properties => {
 	    id => get_standard_option('pve-replication-id'),
-	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_vmid }),
 	    'extra-args' => get_standard_option('extra-args', {
 		description => "The list of volume IDs to consider." }),
 	    force => {
@@ -55,8 +54,7 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
-	my $jobid = $param->{id};
-	my $vmid = $param->{vmid};
+	my ($vmid, undef, $jobid) = PVE::ReplicationConfig::parse_replication_job_id($param->{id});
 	my $last_sync = $param->{last_sync} // 0;
 
 	my $local_node = PVE::INotify::nodename();
@@ -133,7 +131,6 @@ __PACKAGE__->register_method ({
 	additionalProperties => 0,
 	properties => {
 	    id => get_standard_option('pve-replication-id'),
-	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_vmid }),
 	    'extra-args' => get_standard_option('extra-args', {
 		description => "The list of volume IDs to consider." }),
 	    last_sync => {
@@ -148,8 +145,7 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
-	my $jobid = $param->{id};
-	my $vmid = $param->{vmid};
+	my ($vmid, undef, $jobid) = PVE::ReplicationConfig::parse_replication_job_id($param->{id});
 	my $last_sync = $param->{last_sync} // 0;
 
 	my $local_node = PVE::INotify::nodename();
@@ -277,15 +273,15 @@ __PACKAGE__->register_method ({
 my $print_job_list = sub {
     my ($list) = @_;
 
-    my $format = "%-20s %10s %-20s %10s %5s %8s\n";
+    my $format = "%-20s %-20s %10s %5s %8s\n";
 
-    printf($format, "JobID", "GuestID", "Target", "Schedule", "Rate", "Enabled");
+    printf($format, "JobID", "Target", "Schedule", "Rate", "Enabled");
 
     foreach my $job (sort { $a->{guest} <=> $b->{guest} } @$list) {
 	my $plugin = PVE::ReplicationConfig->lookup($job->{type});
 	my $tid = $plugin->get_unique_target_id($job);
 
-	printf($format, $job->{id}, $job->{guest}, $tid,
+	printf($format, $job->{id}, $tid,
 	       defined($job->{schedule}) ? $job->{schedule} : '*/15',
 	       defined($job->{rate}) ? $job->{rate} : '-',
 	       $job->{disable} ? 'no' : 'yes'
@@ -296,9 +292,9 @@ my $print_job_list = sub {
 my $print_job_status = sub {
     my ($list) = @_;
 
-    my $format = "%-20s %10s %-20s %20s %20s %10s %10s %s\n";
+    my $format = "%-20s %-20s %20s %20s %10s %10s %s\n";
 
-    printf($format, "JobID", "GuestID", "Target", "LastSync", "NextSync", "Duration", "FailCount", "State");
+    printf($format, "JobID", "Target", "LastSync", "NextSync", "Duration", "FailCount", "State");
 
     foreach my $job (sort { $a->{guest} <=> $b->{guest} } @$list) {
 	my $plugin = PVE::ReplicationConfig->lookup($job->{type});
@@ -321,7 +317,7 @@ my $print_job_status = sub {
 
 	my $state = $job->{pid} ? "SYNCING" : $job->{error} // 'OK';
 
-	printf($format, $job->{id}, $job->{guest}, $tid,
+	printf($format, $job->{id}, $tid,
 	       $timestr, $nextstr, $job->{duration} // '-',
 	       $job->{fail_count}, $state);
     }
@@ -335,14 +331,14 @@ our $cmddef = {
 	     sub { my $res = shift; print to_json($res, { utf8 => 1, pretty => 1, canonical => 1}); }],
     update => [ 'PVE::API2::ReplicationConfig', 'update' , ['id'], {} ],
     delete => [ 'PVE::API2::ReplicationConfig', 'delete' , ['id'], {} ],
-    'create-local-job' => [ 'PVE::API2::ReplicationConfig', 'create' , ['id', 'guest', 'target'],
+    'create-local-job' => [ 'PVE::API2::ReplicationConfig', 'create' , ['id', 'target'],
 			    { type => 'local' } ],
 
     enable => [ __PACKAGE__, 'enable', ['id'], {}],
     disable => [ __PACKAGE__, 'disable', ['id'], {}],
 
-    'prepare-local-job' => [ __PACKAGE__, 'prepare_local_job', ['id', 'vmid', 'extra-args'], {} ],
-    'finalize-local-job' => [ __PACKAGE__, 'finalize_local_job', ['id', 'vmid', 'extra-args'], {} ],
+    'prepare-local-job' => [ __PACKAGE__, 'prepare_local_job', ['id', 'extra-args'], {} ],
+    'finalize-local-job' => [ __PACKAGE__, 'finalize_local_job', ['id', 'extra-args'], {} ],
 
     run => [ __PACKAGE__ , 'run'],
 };
-- 
2.11.0




More information about the pve-devel mailing list