Merge pull request #360 from ylei-tsubame/server-vm-screenshot

Move server screenshot fetching to `scan-server`
main
Fabio M. Di Nitto 1 year ago committed by GitHub
commit 12635e0a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Anvil/Tools.pm
  2. 87
      Anvil/Tools/Server.pm
  3. 15
      anvil.spec.in
  4. 124
      scancore-agents/scan-server/scan-server
  5. 2
      striker-ui-api/out/index.js
  6. 30
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts
  7. 8
      tools/anvil-access-module
  8. 88
      tools/anvil-daemon
  9. 217
      tools/anvil-get-server-screenshot

@ -1230,6 +1230,7 @@ sub _set_paths
modifyrepo_c => "/usr/bin/modifyrepo_c",
modprobe => "/usr/sbin/modprobe",
mv => "/usr/bin/mv",
nc => "/usr/bin/nc",
nmap => "/usr/bin/nmap",
nmcli => "/bin/nmcli",
ocf_alteeve => "/usr/lib/ocf/resource.d/alteeve/server",

@ -16,6 +16,7 @@ my $THIS_FILE = "Server.pm";
# boot_virsh
# count_servers
# find
# find_processes
# get_definition
# get_runtime
# get_status
@ -484,6 +485,92 @@ sub find
}
=head2 find_processes
Find a list of qemu-kvm processes and extracts server information from the process arguments.
Parameters;
=head3 base_vnc_port (optional)
This value is added to the port offset extracted from -vnc optional to qemu-kvm. Defaults to 5900.
=cut
sub find_processes
{
my $self = shift;
my $parameters = shift;
my $anvil = $self->parent;
my $base_vnc_port = $parameters->{base_vnc_port} // 5900;
my $debug = $parameters->{debug} // 3;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters });
$base_vnc_port = "$base_vnc_port";
return (1) if (not $base_vnc_port =~ /^\d+$/);
$base_vnc_port = int($base_vnc_port);
# Servers only exist on non-striker
return (1) if ($anvil->data->{sys}{host_type} eq "striker");
my $grep = $anvil->data->{path}{exe}{'grep'};
my $nc = $anvil->data->{path}{exe}{'nc'};
my $ps = $anvil->data->{path}{exe}{'ps'};
my $sed = $anvil->data->{path}{exe}{'sed'};
my $ps_call = "$ps -ef | $grep '[q]emu-kvm' | $sed -E 's/^.*guest=([^,]+).*-uuid[[:space:]]+([^[:space:]]+)(.*-vnc[[:space:]]+([[:digit:].:]+))?.*\$/\\2,\\1,\\4/'";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { ps_call => $ps_call }});
my ($call_output, $call_rcode) = $anvil->System->call({ shell_call => $ps_call });
return (1) if ($call_rcode != 0);
my $result = { names => {}, uuids => {} };
foreach my $line (split(/\n/, $call_output))
{
my ($uuid, $name, $vnc) = split(/,/, $line);
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server_name => $name,
server_uuid => $uuid,
server_vnc => $vnc,
}});
$result->{uuids}{$uuid} = { name => $name };
# Record name to UUID mapping
$result->{names}{$name} = $uuid;
next if (not $vnc);
my ($hostname, $port_offset) = split(/:/, $vnc);
my $vnc_port = $base_vnc_port + int($port_offset);
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server_vnc_hostname => $hostname,
server_vnc_port_offset => $port_offset,
server_vnc_port => $vnc_port,
}});
$result->{uuids}{$uuid}{vnc_port} = $vnc_port;
my $nc_call = "$nc -z $hostname $vnc_port";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { nc_call => $nc_call }});
my ($nc_output, $nc_rcode) = $anvil->System->call({ shell_call => $nc_call });
$result->{uuids}{$uuid}{vnc_alive} = int($nc_rcode) > 0 ? 0 : 1;
}
return (0, $result);
}
=head2 get_definition
This returns the server definition XML for a server.

@ -135,6 +135,7 @@ Requires: firefox
Requires: gcc
Requires: gdm
Requires: gnome-terminal
Requires: netpbm-progs
Requires: nmap
Requires: nodejs
Requires: openssh-askpass
@ -156,7 +157,7 @@ NOTE: This installs and enables Gnome desktop.
%package node
Summary: Alteeve's Anvil! node package
Requires: anvil-core == %{version}-%{release}
Requires: anvil-core == %{version}-%{release}
Requires: drbd90-utils
Requires: kmod-drbd
Requires: libvirt
@ -164,7 +165,7 @@ Requires: libvirt-daemon
Requires: libvirt-daemon-driver-qemu
Requires: libvirt-daemon-kvm
Requires: libvirt-docs
Requires: netpbm-progs
Requires: nmap-ncat
Requires: pacemaker
Requires: pcs
Requires: python3-websockify
@ -176,6 +177,7 @@ Requires: virt-top
# allowed to host a database or be a DR host.
Conflicts: anvil-striker
Conflicts: anvil-dr
Conflicts: netcat
%description node
@ -188,7 +190,7 @@ NOTE: LINBIT customers must have access to the LINBIT repositories configured.
%package dr
Summary: Alteeve's Anvil! DR host package
Requires: anvil-core == %{version}-%{release}
Requires: anvil-core == %{version}-%{release}
Requires: drbd90-utils
Requires: kmod-drbd
Requires: libvirt
@ -196,15 +198,16 @@ Requires: libvirt-daemon
Requires: libvirt-daemon-driver-qemu
Requires: libvirt-daemon-kvm
Requires: libvirt-docs
Requires: netpbm-progs
Requires: nmap-ncat
Requires: python3-websockify
Requires: qemu-kvm
Requires: qemu-kvm-core
Requires: virt-install
Requires: virt-top
# A DR host is not allowed to be a live-migration target or host a database.
Conflicts: anvil-striker
Conflicts: anvil-node
Conflicts: anvil-striker
Conflicts: anvil-node
Conflicts: netcat
%description dr

@ -88,12 +88,12 @@ collect_data($anvil);
# Look for migration times written out by ocf:alteeve:server.
record_migration_times($anvil);
# Check if we need to update the websocket stuff.
check_vnc($anvil);
# Check that there's a DRBD fence rule for each server.
check_drbd_fence_rules($anvil);
# Get screenshot from every server that is alive.
get_screenshots($anvil);
# Shut down.
$anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
@ -169,72 +169,66 @@ sub check_drbd_fence_rules
return(0);
}
#
sub check_vnc
# Gets a screenshot for each server that is alive.
sub get_screenshots
{
my ($anvil) = @_;
### NOTE: In the interest of time, this table is not yet in the core schema. Later, when it is, this
### check can be removed.
# See if the 'vnc_pipes' table exists.
my $query = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'vnc_pipes' AND table_schema = 'public';";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
my $anvil = shift;
my $parameters = shift;
my $debug = $parameters->{debug} // 3;
my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if ($count)
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid();
my $local_host_uuid = $anvil->Get->host_uuid();
my $query = "SELECT host_name FROM hosts WHERE host_type = 'striker';";
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ });
my $count = @{$results};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query, count => $count } });
return (1) if ($count == 0);
# Start the CSV with the first element, then append.
my $striker_name_csv = $results->[0]->[0];
foreach my $row ( @{$results}[1 .. $#{$results}] )
{
# For each server running here, get the VNC port and record it.
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid;
foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
{
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_name => $server_name,
server_uuid => $server_uuid,
server_state => $server_state,
}});
next if $server_state eq "paused";
next if $server_state eq "shut off";
next if $server_state eq "crashed";
# Get the VNC port. Ignore the IP and the port number is +5900.
my $shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." vncdisplay --domain ".$server_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
foreach my $line (split/\n/, $output)
{
if ($line =~ /\d.*?:(\d+)$/)
{
my $port = 5900 + $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { port => $port }});
my ($variable_uuid) = $anvil->Database->insert_or_update_variables({
file => $THIS_FILE,
line => __LINE__,
variable_name => "server::vnc_port",
variable_value => $port,
variable_default => "",
variable_description => "message_0255",
variable_section => "servers",
variable_source_uuid => $server_uuid,
variable_source_table => "servers",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }});
}
}
}
my $host_name = $row->[0];
$striker_name_csv = "$striker_name_csv,$host_name";
}
return(0);
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { striker_name_csv => $striker_name_csv } });
foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
{
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server_host_uuid => $server_host_uuid,
server_name => $server_name,
server_state => $server_state,
server_uuid => $server_uuid,
} });
next if ( ($server_host_uuid ne $local_host_uuid) || (not $server_state eq "running") );
my ($syscall_output, $syscall_rcode) = $anvil->System->call({
debug => $debug,
line => __LINE__,
shell_call => $anvil->data->{path}{exe}{'anvil-get-server-screenshot'}." --server-uuid '$server_uuid' --request-host-name '$striker_name_csv' &",
source => $THIS_FILE,
});
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
syscall_output => $syscall_output,
syscall_rcode => $syscall_rcode,
}});
}
return (0);
}
# Look for migration times written out by ocf:alteeve:server.

File diff suppressed because one or more lines are too long

@ -1,12 +1,11 @@
import assert from 'assert';
import { RequestHandler } from 'express';
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { REP_UUID, SERVER_PATHS } from '../../consts';
import { sanitize } from '../../sanitize';
import { stderr, stdout, stdoutVar } from '../../shell';
import { stderr, stdout } from '../../shell';
import { execSync } from 'child_process';
export const getServerDetail: RequestHandler<
ServerDetailParamsDictionary,
@ -37,26 +36,17 @@ export const getServerDetail: RequestHandler<
}
if (isScreenshot) {
const imageFileName = `${serverUuid}_screenshot`;
const imageFilePath = path.join(SERVER_PATHS.tmp.self, imageFileName);
stdoutVar(
{ imageFileName, imageFilePath },
`Server ${serverUuid} image file: `,
);
const rsbody = { screenshot: '' };
if (existsSync(imageFilePath)) {
try {
rsbody.screenshot = readFileSync(imageFilePath, { encoding: 'utf-8' });
} catch (error) {
stderr(
`Failed to read image file at ${imageFilePath}; CAUSE: ${error}`,
);
try {
rsbody.screenshot = execSync(
`${SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self} --convert --resize 500x500 --server-uuid '${serverUuid}'`,
{ encoding: 'utf-8' },
);
} catch (error) {
stderr(`Failed to server ${serverUuid} screenshot; CAUSE: ${error}`);
return response.status(500).send();
}
return response.status(500).send();
}
return response.send(rsbody);

@ -524,10 +524,12 @@ else
my $script_file_handle;
eval {
if ($script_file =~ /^#!SET!#|-$/)
{
$script_file = "-";
# TODO: make this script read piped input
$script_file = "-" if ($script_file =~ /^#!SET!#$/);
if ($script_file =~ /^-$/)
{
open($script_file_handle, $script_file);
}
else

@ -554,9 +554,6 @@ sub handle_periodic_tasks
# Check if anything is needed to be done in /mnt/shared.
check_incoming($anvil);
# TODO: resolve the possible libvirt deadlock and re-enable screenshot fetching.
# do_non_striker_tasks($anvil);
# Check for stale db_in_use states.
check_db_in_use_states($anvil);
}
@ -1818,88 +1815,3 @@ sub update_state_file
return(0);
}
sub get_server_screenshot
{
my $anvil = shift;
my $parameters = shift;
my $debug = $parameters->{debug} // 3;
my $query = "SELECT host_uuid FROM hosts WHERE host_type = 'striker';";
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ });
my $count = @{$results};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query, count => $count } });
return (1) if ($count == 0);
my $striker_uuid_csv = $results->[0]->[0];
foreach my $row ( @{$results}[1 .. $#{$results}] )
{
my $host_uuid = $row->[0];
$striker_uuid_csv = "$striker_uuid_csv,$host_uuid";
}
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { striker_uuid_csv => $striker_uuid_csv } });
my $server_list_on_local = $anvil->data->{server}{location};
my $server_name_csv = join(", ", map { $anvil->Database->quote($_) } keys %{$server_list_on_local});
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_name_csv => $server_name_csv } });
return (1) if ( length($server_name_csv) == 0 );
$query = "SELECT server_uuid FROM servers WHERE server_name IN (".$server_name_csv.") ORDER BY server_name;";
$results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ });
$count = @{$results};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query, count => $count } });
return (1) if ($count == 0);
foreach my $row ( @{$results} )
{
my $server_uuid = $row->[0];
my ($syscall_output, $syscall_rcode) = $anvil->System->call({
debug => $debug,
line => __LINE__,
shell_call => $anvil->data->{path}{exe}{'anvil-get-server-screenshot'}." --server-uuid '$server_uuid' --request-host-uuid '$striker_uuid_csv'",
source => $THIS_FILE,
});
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
syscall_output => $syscall_output,
syscall_rcode => $syscall_rcode,
}});
}
return (0);
}
sub do_non_striker_tasks
{
my $anvil = shift;
my $parameters = shift;
my $debug = $parameters->{debug} // 3;
my $host_type = $anvil->data->{sys}{host_type};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_type => $host_type } });
return (1) if ($host_type eq "striker");
# Get the servers running on this host (except striker).
my ($rcode) = $anvil->Server->find();
if ($rcode == 0)
{
# Get a screenshot from every server (cluster resource)
# running on localhost and punt them to all strikers.
get_server_screenshot($anvil, { debug => $debug });
}
return (0);
}

@ -18,95 +18,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new();
sub remote_call
{
my $parameters = shift;
my $debug = $parameters->{debug};
my @call_result = $anvil->Remote->call($parameters);
my ($output, $error, $return_code) = @call_result;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
%$parameters,
output => $output,
error => $error,
return_code => $return_code,
} });
return @call_result;
}
sub system_call
{
my $parameters = shift;
my $debug = $parameters->{debug};
my @call_result = $anvil->System->call($parameters);
my ($output, $return_code) = @call_result;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
%$parameters,
output => $output,
return_code => $return_code,
} });
return @call_result;
}
sub get_remote_call_requirements
{
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
my $debug = $parameters->{debug};
my $query = "
SELECT ip_address_address
FROM ip_addresses
WHERE ip_address_gateway <> ''
AND ip_address_note <> 'DELETED'
AND ip_address_host_uuid = ".$anvil->Database->quote($host_uuid)."
;";
my $host_ip_address = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__, debug => $debug })->[0]->[0];
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_uuid => $host_uuid,
host_ip_address => $host_ip_address,
} });
return $host_ip_address;
}
sub get_server_screenshot
{
my $parameters = shift;
my $server_uuid = $parameters->{server_uuid};
my $debug = $parameters->{debug};
my $resize_args = defined $parameters->{resize_args} ? $parameters->{resize_args} : '';
my $sh_domstate = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." domstate --domain ".$server_uuid;
my ($sh_domstate_output, $sh_domstate_return_code) = system_call({ debug => $debug, shell_call => $sh_domstate });
if ( ($sh_domstate_return_code != 0) || ($sh_domstate_output ne "running") )
{
return "";
}
my $shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." --quiet screenshot --domain ".$server_uuid." --file ".$anvil->data->{path}{devices}{stdout};
if ($resize_args =~ /^\d+x\d+$/)
{
my ($resize_x, $resize_y) = split(/x/ , $resize_args);
$shell_call .= " | ".$anvil->data->{path}{exe}{pamscale}." -quiet -xyfit ".$resize_x." ".$resize_y;
}
$shell_call .= " | ".$anvil->data->{path}{exe}{pamtopng}." -quiet | ".$anvil->data->{path}{exe}{base64}." --wrap 0";
my ($output, $return_code) = system_call({ debug => $debug, shell_call => $shell_call });
return $return_code == 0 ? $output : "";
}
$anvil->Get->switches;
my $debug = $anvil->data->{switches}{debug};
$anvil->Database->connect;
@ -163,56 +76,72 @@ if ($anvil->data->{switches}{'job-uuid'})
}
}
my $server_uuid = $anvil->data->{switches}{'server-uuid'};
my $resize_args = $anvil->data->{switches}{resize};
my $request_host_uuid = $anvil->data->{switches}{'request-host-uuid'};
my $is_convert = $anvil->data->{switches}{'convert'};
my $job_uuid = $anvil->data->{switches}{'job-uuid'};
my $out_file_id = $anvil->data->{switches}{'out-file-id'};
my $resize_args = $anvil->data->{switches}{'resize'};
my $request_host_name = $anvil->data->{switches}{'request-host-name'};
my $server_uuid = $anvil->data->{switches}{'server-uuid'};
$out_file_id = ( (defined $out_file_id) && ($out_file_id ne "#!SET!#") ) ? "_".$out_file_id : "";
$out_file_id = ( (defined $out_file_id) && ($out_file_id ne "#!SET!#") ) ? "_${out_file_id}" : "";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
debug => $debug,
job_uuid => $job_uuid,
request_host_uuid => $request_host_uuid,
request_host_name => $request_host_name,
resize_args => $resize_args,
server_uuid => $server_uuid,
} });
if ($server_uuid)
{
my $encoded_image = get_server_screenshot({ debug => $debug, server_uuid => $server_uuid, resize_args => $resize_args });
my $out_file_path = $anvil->data->{path}{directories}{tmp}."/${server_uuid}_screenshot${out_file_id}";
if ($is_convert)
{
my ($rcode, $encoded_image) = convert_server_screenshot({
debug => $debug,
resize_args => $resize_args,
source_file => $out_file_path,
});
print($encoded_image) if ($rcode == 0);
$anvil->nice_exit({ exit_code => $rcode });
}
my ($rcode) = get_server_screenshot({
debug => $debug,
output_file => $out_file_path,
server_uuid => $server_uuid,
});
if ($encoded_image eq "")
if ($rcode > 0)
{
$anvil->Job->update_progress({ progress => 100, message => "message_0265" });
$anvil->nice_exit({ exit_code => 1 });
}
if ($request_host_uuid)
if ($request_host_name)
{
chomp $request_host_uuid;
chomp $request_host_name;
my $rsync = $anvil->data->{path}{exe}{rsync};
foreach my $host_uuid ( split(/[,]/, $request_host_uuid) )
foreach my $host_name ( split(/,/, $request_host_name) )
{
my $request_host_ip_address = get_remote_call_requirements({ debug => $debug, host_uuid => $host_uuid });
my $out_file_path = $anvil->data->{path}{directories}{tmp}."/".$server_uuid."_screenshot".$out_file_id;
my $remote_shell_call = $anvil->data->{path}{exe}{echo}." '".$encoded_image."' 1<>'".$out_file_path."' >'".$out_file_path."'";
my $shell_call = "$rsync -e \"ssh -o BatchMode=yes\" -ac '$out_file_path' '$host_name':'$out_file_path'";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
out_file_path => $out_file_path,
remote_shell_call => $remote_shell_call,
request_host_ip_address => $request_host_ip_address,
host_name => $host_name,
out_file_path => $out_file_path,
shell_call => $shell_call,
} });
remote_call({ debug => $debug, shell_call => $remote_shell_call, target => $request_host_ip_address });
system_call({ debug => $debug, shell_call => $shell_call });
}
}
else
{
print($encoded_image);
}
$anvil->Job->update_progress({ progress => 100, message => "message_0264" });
}
@ -224,3 +153,73 @@ else
}
$anvil->nice_exit({ exit_code => 0 });
#
# Functions
#
sub convert_server_screenshot
{
my $parameters = shift;
my $resize_args = $parameters->{resize_args};
my $source_file = $parameters->{source_file};
my $debug = $parameters->{debug};
my $host_type = $anvil->Get->host_type();
return (1) if ( ($host_type ne "striker") || (not -e $source_file) );
my $base64 = $anvil->data->{path}{exe}{base64};
my $pamscale = $anvil->data->{path}{exe}{pamscale};
my $pamtopng = $anvil->data->{path}{exe}{pamtopng};
my $shell_call = "cat $source_file";
if ( (defined $resize_args) && ($resize_args =~ /^\d+x\d+$/) )
{
my ($resize_x, $resize_y) = split(/x/ , $resize_args);
$shell_call .= " | $pamscale -quiet -xyfit $resize_x $resize_y";
}
$shell_call .= " | $pamtopng -quiet | $base64 --wrap 0";
my ($output, $return_code) = system_call({ debug => $debug, shell_call => $shell_call });
return ($return_code, $output);
}
sub get_server_screenshot
{
my $parameters = shift;
my $output_file = $parameters->{output_file};
my $server_uuid = $parameters->{server_uuid};
my $debug = $parameters->{debug};
return (1) if ( (not $server_uuid) || (not $output_file) );
my $setsid = $anvil->data->{path}{exe}{setsid};
my $virsh = $anvil->data->{path}{exe}{virsh};
my $shell_call = "$setsid --wait $virsh --quiet screenshot --domain $server_uuid --file $output_file";
my ($output, $return_code) = system_call({ debug => $debug, shell_call => $shell_call });
return ($return_code, $output);
}
sub system_call
{
my $parameters = shift;
my $debug = $parameters->{debug};
my @call_result = $anvil->System->call($parameters);
my ($output, $return_code) = @call_result;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
%$parameters,
output => $output,
return_code => $return_code,
} });
return @call_result;
}

Loading…
Cancel
Save