]> git.proxmox.com Git - qemu-server.git/blame - PVE/CLI/qmrestore.pm
add setup_environment hook to CLIHandler classes
[qemu-server.git] / PVE / CLI / qmrestore.pm
CommitLineData
cc7b93ec
DM
1package PVE::CLI::qmrestore;
2
3use strict;
4use warnings;
5use PVE::SafeSyslog;
6use PVE::Tools qw(extract_param);
7use PVE::INotify;
8use PVE::RPCEnvironment;
9use PVE::CLIHandler;
10use PVE::JSONSchema qw(get_standard_option);
11use PVE::Cluster;
12use PVE::QemuServer;
13use PVE::API2::Qemu;
14
15use base qw(PVE::CLIHandler);
16
5e4035c7
DM
17sub setup_environment {
18 PVE::RPCEnvironment->setup_default_cli_env();
19}
20
cc7b93ec
DM
21__PACKAGE__->register_method({
22 name => 'qmrestore',
23 path => 'qmrestore',
24 method => 'POST',
25 description => "Restore QemuServer vzdump backups.",
26 parameters => {
27 additionalProperties => 0,
28 properties => {
29 vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
30 archive => {
31 description => "The backup file. You can pass '-' to read from standard input.",
32 type => 'string',
33 maxLength => 255,
34 completion => \&PVE::QemuServer::complete_backup_archives,
35 },
36 storage => get_standard_option('pve-storage-id', {
37 description => "Default storage.",
38 optional => 1,
39 completion => \&PVE::QemuServer::complete_storage,
40 }),
41 force => {
42 optional => 1,
43 type => 'boolean',
44 description => "Allow to overwrite existing VM.",
45 },
46 unique => {
47 optional => 1,
48 type => 'boolean',
49 description => "Assign a unique random ethernet address.",
50 },
51 pool => {
52 optional => 1,
53 type => 'string', format => 'pve-poolid',
54 description => "Add the VM to the specified pool.",
55 },
56 },
57 },
58 returns => {
59 type => 'string',
60 },
61 code => sub {
62 my ($param) = @_;
63
64 $param->{node} = PVE::INotify::nodename();
65
66 return PVE::API2::Qemu->create_vm($param);
67 }});
68
69our $cmddef = [ __PACKAGE__, 'qmrestore', ['archive', 'vmid'], undef,
70 sub {
71 my $upid = shift;
72 my $status = PVE::Tools::upid_read_status($upid);
73 exit($status eq 'OK' ? 0 : -1);
74 }];
75
761;