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',
parameters => {
additionalProperties => 0,
properties => {
- vmid => get_standard_option('pve-vmid'),
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
},
},
returns => { type => 'null'},
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',
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";
}
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'},
parameters => {
additionalProperties => 0,
properties => {
- vmid => get_standard_option('pve-vmid'),
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
},
},
returns => { type => 'null'},
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;
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',
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'},
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";
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'},
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',
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};
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;
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 }],
};
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