use PVE::RPCEnvironment;
use PVE::QemuServer;
use PVE::API2::Qemu;
+use JSON;
use PVE::JSONSchema qw(get_standard_option);
use Term::ReadLine;
my $nodename = PVE::INotify::nodename();
+sub setup_environment {
+ PVE::RPCEnvironment->setup_default_cli_env();
+}
+
sub run_vnc_proxy {
my ($path) = @_;
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',
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}, 1);
my $stat = $vmstatus->{$param->{vmid}};
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->{qmpstatus} || 'unknown';
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::write_config($vmid, $conf);
+ PVE::QemuConfig->write_config($vmid, $conf);
});
return undef;
}});
+__PACKAGE__->register_method ({
+ name => 'nbdstop',
+ path => 'nbdstop',
+ method => 'PUT',
+ description => "Stop embedded nbd server.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+ },
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ my $vmid = $param->{vmid};
+
+ PVE::QemuServer::nbd_stop($vmid);
+
+ return undef;
+ }});
+
__PACKAGE__->register_method ({
name => 'mtunnel',
path => 'mtunnel',
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";
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};
return undef;
}});
+
+my $print_agent_result = sub {
+ my ($data) = @_;
+
+ my $result = $data->{result};
+ return if !defined($result);
+
+ my $class = ref($result);
+
+ if (!$class) {
+ chomp $result;
+ return if $result =~ m/^\s*$/;
+ print "$result\n";
+ return;
+ }
+
+ if (($class eq 'HASH') && !scalar(keys %$result)) { # empty hash
+ return;
+ }
+
+ print to_json($result, { pretty => 1, canonical => 1});
+};
+
our $cmddef = {
list => [ "PVE::API2::Qemu", 'vmlist', [],
{ node => $nodename }, sub {
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 }],
monitor => [ __PACKAGE__, 'monitor', ['vmid']],
+ agent => [ "PVE::API2::Qemu", 'agent', ['vmid', 'command'],
+ { node => $nodename }, $print_agent_result ],
+
mtunnel => [ __PACKAGE__, 'mtunnel', []],
+ nbdstop => [ __PACKAGE__, 'nbdstop', ['vmid']],
+
terminal => [ __PACKAGE__, 'terminal', ['vmid']],
};
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