]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/CLI/qm.pm
add qm listsnapshot call
[qemu-server.git] / PVE / CLI / qm.pm
index dc544a80bb914c7db2798c53b11ed96f7e40f04e..a0e0ba564d5bf0bc3bfb6e841687096d0541ac64 100755 (executable)
@@ -75,6 +75,32 @@ sub run_vnc_proxy {
     exit(0);
 }
 
+sub print_recursive_hash {
+    my ($prefix, $hash, $key) = @_;
+
+    if (ref($hash) eq 'HASH') {
+       if (defined($key)) {
+           print "$prefix$key:\n";
+       }
+       foreach my $itemkey (keys %$hash) {
+           print_recursive_hash("\t$prefix", $hash->{$itemkey}, $itemkey);
+       }
+    } elsif (ref($hash) eq 'ARRAY') {
+       if (defined($key)) {
+           print "$prefix$key:\n";
+       }
+       foreach my $item (@$hash) {
+           print_recursive_hash("\t$prefix", $item);
+       }
+    } elsif (!ref($hash) && defined($hash)) {
+       if (defined($key)) {
+           print "$prefix$key: $hash\n";
+       } else {
+           print "$prefix$hash\n";
+       }
+    }
+}
+
 __PACKAGE__->register_method ({
     name => 'showcmd',
     path => 'showcmd',
@@ -83,7 +109,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
        },
     },
     returns => { type => 'null'},
@@ -104,7 +130,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
            verbose => {
                description => "Verbose output format",
                type => 'boolean',
@@ -117,19 +143,18 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        # test if VM exists
-       my $conf = PVE::QemuServer::load_config ($param->{vmid});
+       my $conf = PVE::QemuConfig->load_config ($param->{vmid});
 
-       my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
+       my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid}, 1);
        my $stat = $vmstatus->{$param->{vmid}};
        if ($param->{verbose}) {
            foreach my $k (sort (keys %$stat)) {
                next if $k eq 'cpu' || $k eq 'relcpu'; # always 0
                my $v = $stat->{$k};
-               next if !defined($v);
-               print "$k: $v\n";
+               print_recursive_hash("", $v, $k);
            }
        } else {
-           my $status = $stat->{status} || 'unknown';
+           my $status = $stat->{qmpstatus} || 'unknown';
            print "status: $status\n";
        }
 
@@ -144,7 +169,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
        },
     },
     returns => { type => 'null'},
@@ -175,7 +200,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
        },
     },
     returns => { type => 'null'},
@@ -184,11 +209,11 @@ __PACKAGE__->register_method ({
 
        my $vmid = $param->{vmid};
 
-       PVE::QemuServer::lock_config ($vmid, sub {
-           my $conf = PVE::QemuServer::load_config($vmid);
+       PVE::QemuConfig->lock_config ($vmid, sub {
+           my $conf = PVE::QemuConfig->load_config($vmid);
            delete $conf->{lock};
            delete $conf->{pending}->{lock} if $conf->{pending}; # just to be sure
-           PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
+           PVE::QemuConfig->write_config($vmid, $conf);
        });
 
        return undef;
@@ -231,7 +256,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
            timeout => {
                description => "Timeout in seconds. Default is to wait forever.",
                type => 'integer',
@@ -271,7 +296,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
        },
     },
     returns => { type => 'null'},
@@ -280,7 +305,7 @@ __PACKAGE__->register_method ({
 
        my $vmid = $param->{vmid};
 
-       my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
+       my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
 
        print "Entering Qemu Monitor for VM $vmid - type 'help' for help\n";
 
@@ -312,7 +337,10 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid', {optional => 1}),
+           vmid => get_standard_option('pve-vmid', {
+               optional => 1,
+               completion => \&PVE::QemuServer::complete_vmid,
+           }),
        },
     },
     returns => { type => 'null'},
@@ -332,7 +360,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid'),
+           vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
            iface => {
                description => "Select the serial device. By default we simply use the first suitable device.",
                type => 'string',
@@ -347,7 +375,7 @@ __PACKAGE__->register_method ({
 
        my $vmid = $param->{vmid};
 
-       my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
+       my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
 
        my $iface = $param->{iface};
 
@@ -389,7 +417,7 @@ our $cmddef = {
 
                 foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
                     printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name},
-                    $rec->{status},
+                    $rec->{qmpstatus} || $rec->{status},
                     ($rec->{maxmem} || 0)/(1024*1024),
                     ($rec->{maxdisk} || 0)/(1024*1024*1024),
                     $rec->{pid}||0;
@@ -462,6 +490,17 @@ our $cmddef = {
 
     delsnapshot => [ "PVE::API2::Qemu", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
 
+    listsnapshot => [ "PVE::API2::Qemu", 'snapshot_list', ['vmid'], { node => $nodename },
+                   sub {
+                       my $res = shift;
+                       foreach my $e (@$res) {
+                           my $headline = $e->{description} || 'no-description';
+                           $headline =~ s/\n.*//sg;
+                           my $parent = $e->{parent} // 'no-parent';
+                           printf("%-20s %-20s %s\n", $e->{name}, $parent, $headline);
+                       }
+                   }],
+
     rollback => [ "PVE::API2::Qemu", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
 
     template => [ "PVE::API2::Qemu", 'template', ['vmid'], { node => $nodename }],
@@ -496,59 +535,3 @@ our $cmddef = {
 };
 
 1;
-
-__END__
-
-=head1 NAME
-
-qm - qemu/kvm virtual machine manager
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-qm is a script to manage virtual machines with qemu/kvm. You can
-create and destroy virtual machines, and control execution
-(start/stop/suspend/resume). Besides that, you can use qm to set
-parameters in the associated config file. It is also possible to
-create and delete virtual disks.
-
-=head1 CONFIGURATION
-
-All configuration files consists of lines in the form
-
-       PARAMETER: value
-
-See L<vm.conf|vm.conf> for a complete list of options.
-
-Configuration files are stored inside the Proxmox configuration file system, and can be access at F</etc/pve/qemu-server/C<VMID>.conf>.
-
-The default for option 'keyboard' is read from
-F</etc/pve/datacenter.conf>.
-
-=head1 Locks
-
-Online migration and backups (vzdump) set a lock to prevent
-unintentional action on such VMs. Sometimes you need remove such lock
-manually (power failure).
-
- qm unlock <vmid>
-
-=head1 EXAMPLES
-
- # create a new VM with 4 GB ide disk
- qm create 300 -ide0 4 -net0 e1000 -cdrom proxmox-mailgateway_2.1.iso
-
- # start the new VM
- qm start 300
-
- # send shutdown, then wait until VM is stopped
- qm shutdown 300 && qm wait 300
-
- # same as above, but only wait for 40 seconds
- qm shutdown 300 && qm wait 300 -timeout 40
-
-
-=include pve_copyright