refactor pveam to use it with our CLI Handler.

This commit is contained in:
Wolfgang Link 2016-02-24 12:11:05 +01:00 committed by Dietmar Maurer
parent c8969ecb19
commit 108b722948
4 changed files with 95 additions and 23 deletions

View File

@ -1,6 +1,6 @@
include ../../defines.mk
SOURCES=vzdump.pm pvesubscription.pm pveceph.pm
SOURCES=vzdump.pm pvesubscription.pm pveceph.pm pveam.pm
all:

88
PVE/CLI/pveam.pm Normal file
View File

@ -0,0 +1,88 @@
package PVE::CLI::pveam;
use strict;
use warnings;
use PVE::Cluster;
use PVE::APLInfo;
use Data::Dumper;
use PVE::SafeSyslog;
use PVE::Tools qw(extract_param);
use PVE::Cluster;
use PVE::INotify;
use PVE::RPCEnvironment;
use PVE::JSONSchema qw(get_standard_option);
use PVE::CLIHandler;
use base qw(PVE::CLIHandler);
my $nodename = PVE::INotify::nodename();
my $upid_exit = sub {
my $upid = shift;
my $status = PVE::Tools::upid_read_status($upid);
exit($status eq 'OK' ? 0 : -1);
};
__PACKAGE__->register_method ({
name => 'update',
path => 'update',
method => 'PUT',
description => "Update Container Template Database.",
parameters => {
additionalProperties => 0,
},
returns => { type => 'null'},
code => sub {
my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
print Data::Dumper::Dumper $dccfg;
print STDERR "update failed - see /var/log/pveam.log for details\n"
if !PVE::APLInfo::update($dccfg->{http_proxy});
return undef;
}});
our $cmddef = {
update => [ __PACKAGE__, 'update', []],
};
1;
__END__
=head1 NAME
pveam Tool to manage Linux Container templates on Proxmox VE
=head1 SYNOPSIS
=include synopsis
=head1 DESCRIPTION
pveam can manage Container templates like updating the Database,
destroying, downloading and showing templates.
This tool support bash completion
=head1 EXAMPLES
Updating the DB
pveam update
downloading a template in background
pveam download debian-8.0-standard --storage local --bg 1
removing a template
pveam destroy debian-8.0-standard --storage local
showing all templates what are available
pveam show
=head1 FILES
Log-files
/var/log/pveam.log
=include pve_copyright

View File

@ -3,13 +3,12 @@ include ../defines.mk
SUBDIRS = init.d ocf test
SERVICES = pvestatd pveproxy pvedaemon spiceproxy
CLITOOLS = vzdump pvesubscription pveceph
CLITOOLS = vzdump pvesubscription pveceph pveam
SCRIPTS = \
${SERVICES} \
${CLITOOLS} \
pvesh \
pveam \
pvebanner \
pveversion \
pvemailforward.pl \
@ -25,9 +24,9 @@ CLI_MANS = \
$(addsuffix .1, ${CLITOOLS}) \
pveversion.1 \
pveupgrade.1 \
pveperf.1 \
pveperf.1 \
pvesh.1 \
pvereport.1
pvereport.1 \
CLI_PODS = $(addsuffix .pod, ${CLI_MANS})

View File

@ -1,23 +1,8 @@
#!/usr/bin/perl
#!/usr/bin/perl -T
use strict;
use warnings;
use PVE::Cluster;
use PVE::APLInfo;
if (scalar (@ARGV) != 1) {
print STDERR "usage: $0 CMD\n";
exit (-1);
}
use PVE::CLI::pveam;
my $cmd = shift;
if ($cmd eq 'update') {
my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
exit (0) if PVE::APLInfo::update($dccfg->{http_proxy});
print STDERR "update failed - see /var/log/pveam.log for details\n";
exit (-1);
} else {
print STDERR "unknown CMD '$cmd'\n";
exit (-1);
}
PVE::CLI::pveam->run_cli();