]> git.proxmox.com Git - qemu-server.git/commitdiff
convert qmrestore into a PVE::CLI class
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 5 Oct 2015 11:10:24 +0000 (13:10 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 5 Oct 2015 11:10:24 +0000 (13:10 +0200)
and install bash completion helpers.

Makefile
PVE/CLI/Makefile
PVE/CLI/qmrestore.pm [new file with mode: 0755]
qm
qmrestore

index 9c47a196584ede7e4c3838a837cd0df7f0fa3b82..7384ce428a2f99b61234bd89de8cfbe92126ebf0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ sparsecp: sparsecp.c utils.c
 %.1.pod: %
        podselect $*>$@
 
-qm.1.pod: qm PVE/QemuServer.pm
+qm.1.pod: PVE/CLI/qm.pm PVE/QemuServer.pm
        perl -I. -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_pod_manpage();" >$@.tmp
        mv $@.tmp $@
 
@@ -63,13 +63,18 @@ qm.bash-completion:
        perl -I. -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_bash_completions();" >$@.tmp
        mv $@.tmp $@
 
-qmrestore.1.pod: qmrestore
-       perl -I. ./qmrestore printmanpod >$@
+qmrestore.1.pod: PVE/CLI/qmrestore.pm
+       perl -I. -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_pod_manpage();" >$@.tmp
+       mv $@.tmp $@
+
+qmrestore.bash-completion:
+       perl -I. -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_bash_completions();" >$@.tmp
+       mv $@.tmp $@
 
 vm.conf.5.pod: gen-vmconf-pod.pl PVE/QemuServer.pm 
        perl -I. ./gen-vmconf-pod.pl >$@
 
-PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar control vm.conf.5.pod vm.conf.5.gz qm.bash-completion
+PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar control vm.conf.5.pod vm.conf.5.gz qm.bash-completion qmrestore.bash-completion
 
 .PHONY: install
 install: ${PKGSOURCES}
@@ -84,6 +89,7 @@ install: ${PKGSOURCES}
        install -m 0644 pve-usb.cfg ${DESTDIR}/usr/share/${PACKAGE}
        install -m 0644 pve-q35.cfg ${DESTDIR}/usr/share/${PACKAGE}
        install -m 0644 -D qm.bash-completion ${DESTDIR}/${BASHCOMPLDIR}/qm
+       install -m 0644 -D qmrestore.bash-completion ${DESTDIR}/${BASHCOMPLDIR}/qmrestore
        make -C PVE install
        install -m 0755 qm ${DESTDIR}${SBINDIR}
        install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
index ac16e738f8b0faea0253bffe49356842d557b669..2fec8e5e812ba9ccebd9f8b6f725f138801cb961 100644 (file)
@@ -1,4 +1,4 @@
-SOURCES=qm.pm
+SOURCES=qm.pm qmrestore.pm
 
 .PHONY: install
 install: ${SOURCES}
diff --git a/PVE/CLI/qmrestore.pm b/PVE/CLI/qmrestore.pm
new file mode 100755 (executable)
index 0000000..b5abfb9
--- /dev/null
@@ -0,0 +1,94 @@
+package PVE::CLI::qmrestore;
+
+use strict;
+use warnings;
+use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
+use PVE::INotify;
+use PVE::RPCEnvironment;
+use PVE::CLIHandler;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Cluster;
+use PVE::QemuServer;
+use PVE::API2::Qemu;
+
+use base qw(PVE::CLIHandler);
+
+__PACKAGE__->register_method({
+    name => 'qmrestore', 
+    path => 'qmrestore', 
+    method => 'POST',
+    description => "Restore QemuServer vzdump backups.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
+           archive => {
+               description => "The backup file. You can pass '-' to read from standard input.",
+               type => 'string', 
+               maxLength => 255,
+               completion => \&PVE::QemuServer::complete_backup_archives,
+           },
+           storage => get_standard_option('pve-storage-id', {
+               description => "Default storage.",
+               optional => 1,
+               completion => \&PVE::QemuServer::complete_storage,
+           }),
+           force => {
+               optional => 1, 
+               type => 'boolean',
+               description => "Allow to overwrite existing VM.",
+           },
+           unique => {
+               optional => 1, 
+               type => 'boolean',
+               description => "Assign a unique random ethernet address.",
+           },
+           pool => { 
+               optional => 1,
+               type => 'string', format => 'pve-poolid',
+               description => "Add the VM to the specified pool.",
+           },
+       },
+    },
+    returns => { 
+       type => 'string',
+    },
+    code => sub {
+       my ($param) = @_;
+
+       $param->{node} = PVE::INotify::nodename();
+
+       return PVE::API2::Qemu->create_vm($param);
+    }});    
+
+our $cmddef = [ __PACKAGE__, 'qmrestore', ['archive', 'vmid'], undef, 
+               sub {
+                   my $upid = shift;
+                   my $status = PVE::Tools::upid_read_status($upid);
+                   exit($status eq 'OK' ? 0 : -1);
+               }];
+
+1;
+
+__END__
+
+=head1 NAME
+
+qmrestore - restore QemuServer vzdump backups
+
+=head1 SYNOPSIS
+
+=include synopsis
+
+=head1 DESCRIPTION
+
+Restore the QemuServer vzdump backup C<archive> to virtual machine
+C<vmid>. Volumes are allocated on the original storage if there is no
+C<storage> specified.
+
+=head1 SEE ALSO
+
+vzdump(1) vzrestore(1)
+
+=include pve_copyright
diff --git a/qm b/qm
index 663e440d32cbd1a8975c438b6d063a23799d19c2..d0e9bc196aa1a33156c1e9cce80cdd56403fbfbb 100755 (executable)
--- a/qm
+++ b/qm
@@ -5,4 +5,4 @@ use warnings;
 
 use PVE::CLI::qm;
 
-PVE::CLI::qm->run_cli();
+PVE::CLI::qm->run_cli_handler();
index 59a47b6e3a5c543b4c22241840003045128df3d6..506f2bdcebd0da3a7df17858bb47c9c35f83f8bc 100755 (executable)
--- a/qmrestore
+++ b/qmrestore
@@ -2,109 +2,7 @@
 
 use strict;
 use warnings;
-use PVE::SafeSyslog;
-use PVE::Tools qw(extract_param);
-use PVE::INotify;
-use PVE::RPCEnvironment;
-use PVE::CLIHandler;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::API2::Qemu;
 
-use Data::Dumper; # fixme: remove
+use PVE::CLI::qmrestore;
 
-use base qw(PVE::CLIHandler);
-
-$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
-
-initlog('qmrestore');
-
-die "please run as root\n" if $> != 0;
-
-PVE::INotify::inotify_init();
-
-my $rpcenv = PVE::RPCEnvironment->init('cli');
-
-$rpcenv->init_request();
-$rpcenv->set_language($ENV{LANG});
-$rpcenv->set_user('root@pam'); 
-
-__PACKAGE__->register_method({
-    name => 'qmrestore', 
-    path => 'qmrestore', 
-    method => 'POST',
-    description => "Restore QemuServer vzdump backups.",
-    parameters => {
-       additionalProperties => 0,
-       properties => {
-           vmid => get_standard_option('pve-vmid'),
-           archive => {
-               description => "The backup file. You can pass '-' to read from standard input.",
-               type => 'string', 
-               maxLength => 255,
-           },
-           storage => get_standard_option('pve-storage-id', {
-               description => "Default storage.",
-               optional => 1,
-           }),
-           force => {
-               optional => 1, 
-               type => 'boolean',
-               description => "Allow to overwrite existing VM.",
-           },
-           unique => {
-               optional => 1, 
-               type => 'boolean',
-               description => "Assign a unique random ethernet address.",
-           },
-           pool => { 
-               optional => 1,
-               type => 'string', format => 'pve-poolid',
-               description => "Add the VM to the specified pool.",
-           },
-       },
-    },
-    returns => { 
-       type => 'string',
-    },
-    code => sub {
-       my ($param) = @_;
-
-       $param->{node} = PVE::INotify::nodename();
-
-       return PVE::API2::Qemu->create_vm($param);
-    }});    
-
-my $cmddef = [ __PACKAGE__, 'qmrestore', ['archive', 'vmid'], undef, 
-              sub {
-                  my $upid = shift;
-                  my $status = PVE::Tools::upid_read_status($upid);
-                  exit($status eq 'OK' ? 0 : -1);
-              }];
-
-push @ARGV, 'help' if !scalar(@ARGV);
-
-PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
-
-exit 0;
-
-__END__
-
-=head1 NAME
-
-qmrestore - restore QemuServer vzdump backups
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-Restore the QemuServer vzdump backup C<archive> to virtual machine
-C<vmid>. Volumes are allocated on the original storage if there is no
-C<storage> specified.
-
-=head1 SEE ALSO
-
-vzdump(1) vzrestore(1)
-
-=include pve_copyright
+PVE::CLI::qmrestore->run_cli_handler();