PVE::API2::ReplicationConfig - extract guest ID from job ID

This commit is contained in:
Dietmar Maurer 2017-06-06 12:43:13 +02:00
parent 9b24b5d4ed
commit a9da300ded
2 changed files with 16 additions and 15 deletions

View File

@ -109,6 +109,9 @@ __PACKAGE__->register_method ({
my $plugin = PVE::ReplicationConfig->lookup($type); my $plugin = PVE::ReplicationConfig->lookup($type);
my $id = extract_param($param, 'id'); 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 $code = sub {
my $cfg = PVE::ReplicationConfig->new(); my $cfg = PVE::ReplicationConfig->new();
@ -117,6 +120,8 @@ __PACKAGE__->register_method ({
my $opts = $plugin->check_config($id, $param, 1, 1); my $opts = $plugin->check_config($id, $param, 1, 1);
$opts->{guest} = $guest;
$cfg->{ids}->{$id} = $opts; $cfg->{ids}->{$id} = $opts;
$cfg->write(); $cfg->write();

View File

@ -34,7 +34,6 @@ __PACKAGE__->register_method ({
additionalProperties => 0, additionalProperties => 0,
properties => { properties => {
id => get_standard_option('pve-replication-id'), 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', { 'extra-args' => get_standard_option('extra-args', {
description => "The list of volume IDs to consider." }), description => "The list of volume IDs to consider." }),
force => { force => {
@ -55,8 +54,7 @@ __PACKAGE__->register_method ({
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
my $jobid = $param->{id}; my ($vmid, undef, $jobid) = PVE::ReplicationConfig::parse_replication_job_id($param->{id});
my $vmid = $param->{vmid};
my $last_sync = $param->{last_sync} // 0; my $last_sync = $param->{last_sync} // 0;
my $local_node = PVE::INotify::nodename(); my $local_node = PVE::INotify::nodename();
@ -133,7 +131,6 @@ __PACKAGE__->register_method ({
additionalProperties => 0, additionalProperties => 0,
properties => { properties => {
id => get_standard_option('pve-replication-id'), 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', { 'extra-args' => get_standard_option('extra-args', {
description => "The list of volume IDs to consider." }), description => "The list of volume IDs to consider." }),
last_sync => { last_sync => {
@ -148,8 +145,7 @@ __PACKAGE__->register_method ({
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
my $jobid = $param->{id}; my ($vmid, undef, $jobid) = PVE::ReplicationConfig::parse_replication_job_id($param->{id});
my $vmid = $param->{vmid};
my $last_sync = $param->{last_sync} // 0; my $last_sync = $param->{last_sync} // 0;
my $local_node = PVE::INotify::nodename(); my $local_node = PVE::INotify::nodename();
@ -277,15 +273,15 @@ __PACKAGE__->register_method ({
my $print_job_list = sub { my $print_job_list = sub {
my ($list) = @_; 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) { foreach my $job (sort { $a->{guest} <=> $b->{guest} } @$list) {
my $plugin = PVE::ReplicationConfig->lookup($job->{type}); my $plugin = PVE::ReplicationConfig->lookup($job->{type});
my $tid = $plugin->get_unique_target_id($job); 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->{schedule}) ? $job->{schedule} : '*/15',
defined($job->{rate}) ? $job->{rate} : '-', defined($job->{rate}) ? $job->{rate} : '-',
$job->{disable} ? 'no' : 'yes' $job->{disable} ? 'no' : 'yes'
@ -296,9 +292,9 @@ my $print_job_list = sub {
my $print_job_status = sub { my $print_job_status = sub {
my ($list) = @_; 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) { foreach my $job (sort { $a->{guest} <=> $b->{guest} } @$list) {
my $plugin = PVE::ReplicationConfig->lookup($job->{type}); my $plugin = PVE::ReplicationConfig->lookup($job->{type});
@ -321,7 +317,7 @@ my $print_job_status = sub {
my $state = $job->{pid} ? "SYNCING" : $job->{error} // 'OK'; my $state = $job->{pid} ? "SYNCING" : $job->{error} // 'OK';
printf($format, $job->{id}, $job->{guest}, $tid, printf($format, $job->{id}, $tid,
$timestr, $nextstr, $job->{duration} // '-', $timestr, $nextstr, $job->{duration} // '-',
$job->{fail_count}, $state); $job->{fail_count}, $state);
} }
@ -335,14 +331,14 @@ our $cmddef = {
sub { my $res = shift; print to_json($res, { utf8 => 1, pretty => 1, canonical => 1}); }], sub { my $res = shift; print to_json($res, { utf8 => 1, pretty => 1, canonical => 1}); }],
update => [ 'PVE::API2::ReplicationConfig', 'update' , ['id'], {} ], update => [ 'PVE::API2::ReplicationConfig', 'update' , ['id'], {} ],
delete => [ 'PVE::API2::ReplicationConfig', 'delete' , ['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' } ], { type => 'local' } ],
enable => [ __PACKAGE__, 'enable', ['id'], {}], enable => [ __PACKAGE__, 'enable', ['id'], {}],
disable => [ __PACKAGE__, 'disable', ['id'], {}], disable => [ __PACKAGE__, 'disable', ['id'], {}],
'prepare-local-job' => [ __PACKAGE__, 'prepare_local_job', ['id', 'vmid', 'extra-args'], {} ], 'prepare-local-job' => [ __PACKAGE__, 'prepare_local_job', ['id', 'extra-args'], {} ],
'finalize-local-job' => [ __PACKAGE__, 'finalize_local_job', ['id', 'vmid', 'extra-args'], {} ], 'finalize-local-job' => [ __PACKAGE__, 'finalize_local_job', ['id', 'extra-args'], {} ],
run => [ __PACKAGE__ , 'run'], run => [ __PACKAGE__ , 'run'],
}; };