From a9da300ded4a9aec4b4e37c7dcdb9d179c92dbb5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 6 Jun 2017 12:43:13 +0200 Subject: [PATCH] PVE::API2::ReplicationConfig - extract guest ID from job ID --- PVE/API2/ReplicationConfig.pm | 5 +++++ PVE/CLI/pvesr.pm | 26 +++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/PVE/API2/ReplicationConfig.pm b/PVE/API2/ReplicationConfig.pm index 69d56aed..21c70a8f 100644 --- a/PVE/API2/ReplicationConfig.pm +++ b/PVE/API2/ReplicationConfig.pm @@ -109,6 +109,9 @@ __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); + my $code = sub { my $cfg = PVE::ReplicationConfig->new(); @@ -117,6 +120,8 @@ __PACKAGE__->register_method ({ my $opts = $plugin->check_config($id, $param, 1, 1); + $opts->{guest} = $guest; + $cfg->{ids}->{$id} = $opts; $cfg->write(); 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'], };