[pve-devel] [PATCH 1/4] refactor pveam to use it with our CLI Handler.
Wolfgang Link
w.link at proxmox.com
Wed Feb 24 12:11:05 CET 2016
---
PVE/CLI/Makefile | 2 +-
PVE/CLI/pveam.pm | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/Makefile | 7 ++---
bin/pveam | 21 ++------------
4 files changed, 95 insertions(+), 23 deletions(-)
create mode 100644 PVE/CLI/pveam.pm
diff --git a/PVE/CLI/Makefile b/PVE/CLI/Makefile
index 6ec4dd1..b005a8f 100644
--- a/PVE/CLI/Makefile
+++ b/PVE/CLI/Makefile
@@ -1,6 +1,6 @@
include ../../defines.mk
-SOURCES=vzdump.pm pvesubscription.pm pveceph.pm
+SOURCES=vzdump.pm pvesubscription.pm pveceph.pm pveam.pm
all:
diff --git a/PVE/CLI/pveam.pm b/PVE/CLI/pveam.pm
new file mode 100644
index 0000000..407d629
--- /dev/null
+++ b/PVE/CLI/pveam.pm
@@ -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
diff --git a/bin/Makefile b/bin/Makefile
index 827e30d..6826c7c 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -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})
diff --git a/bin/pveam b/bin/pveam
index adf1de6..8b55adf 100755
--- a/bin/pveam
+++ b/bin/pveam
@@ -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();
--
2.1.4
More information about the pve-devel
mailing list