X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=PVE%2FAPIClient%2FCommands%2FGuestStatus.pm;h=57784e58b17400ab66a434cb900c6f1c9d0b4c75;hp=7903a2b7d59d7eddc99b63c137bb1c9a89175ad1;hb=c9138c03bcb92d01e8c7d9f195ac2f9b4d5458b3;hpb=89335fb1777461e08e9af18c6c4c8a7e162588c5 diff --git a/PVE/APIClient/Commands/GuestStatus.pm b/PVE/APIClient/Commands/GuestStatus.pm index 7903a2b..57784e5 100644 --- a/PVE/APIClient/Commands/GuestStatus.pm +++ b/PVE/APIClient/Commands/GuestStatus.pm @@ -6,11 +6,13 @@ use warnings; use PVE::APIClient::Helpers; use PVE::APIClient::Config; -use PVE::JSONSchema qw(get_standard_option); +use PVE::APIClient::JSONSchema qw(get_standard_option); -use PVE::CLIHandler; +use File::Temp qw(tempfile); -use base qw(PVE::CLIHandler); +use PVE::APIClient::CLIHandler; + +use base qw(PVE::APIClient::CLIHandler); my $guest_status_command = sub { my ($remote, $vmid, $cmd, $param) = @_, @@ -41,8 +43,8 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - my $remote = PVE::Tools::extract_param($param, 'remote'); - my $vmid = PVE::Tools::extract_param($param, 'vmid'); + my $remote = PVE::APIClient::Tools::extract_param($param, 'remote'); + my $vmid = PVE::APIClient::Tools::extract_param($param, 'vmid'); $guest_status_command->($remote, $vmid, 'start', $param); @@ -65,10 +67,52 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; + my $remote = PVE::APIClient::Tools::extract_param($param, 'remote'); + my $vmid = PVE::APIClient::Tools::extract_param($param, 'vmid'); + + $guest_status_command->($remote, $vmid, 'stop', $param); + + return undef; + }}); + +__PACKAGE__->register_method ({ + name => 'spice', + path => 'spice', + method => 'POST', + description => "Run the spice client for a guest (VM/Container)", + parameters => { + additionalProperties => 0, + properties => { + remote => get_standard_option('pveclient-remote-name'), + vmid => get_standard_option('pve-vmid'), + }, + }, + returns => { type => 'null'}, + code => sub { + my ($param) = @_; + my $remote = PVE::Tools::extract_param($param, 'remote'); my $vmid = PVE::Tools::extract_param($param, 'vmid'); - $guest_status_command->($remote, $vmid, 'stop', $param); + my $config = PVE::APIClient::Config->load(); + my $conn = PVE::APIClient::Config->remote_conn($config, $remote); + + my $resource = PVE::APIClient::Helpers::get_vmid_resource($conn, $vmid); + + my $res = $conn->post("api2/json/nodes/$resource->{node}/$resource->{type}/$resource->{vmid}/spiceproxy", {}); + + my $vvsetup = "[virt-viewer]\n"; + foreach my $k (keys %$res) { + $vvsetup .= "$k=$res->{$k}\n"; + } + + my ($fh, $filename) = tempfile( "tempXXXXX", SUFFIX => '.vv', TMPDIR => 1); + syswrite($fh, $vvsetup); + + system("nohup remote-viewer $filename 1>/dev/null 2>&1 &"); + if ($? != 0) { + print "failed to execute remote-viewer: $!\n"; + } return undef; }});