From c07e72bab9b293aba6b16959a2281bd59c3284b6 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 22 Jun 2021 18:49:02 -0400 Subject: [PATCH] fix(cgi-bin): add logic to power on/off server VM --- cgi-bin/set_power | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/cgi-bin/set_power b/cgi-bin/set_power index 767e84a8..b48999bf 100755 --- a/cgi-bin/set_power +++ b/cgi-bin/set_power @@ -116,6 +116,56 @@ sub set_host_power } } +sub set_server_power +{ + my $parameters = shift; + my $server_uuid = $parameters->{server_uuid}; + my $on = $parameters->{on}; + + my $query = " +SELECT + server_anvil_uuid +FROM + servers +WHERE + server_uuid = ".$anvil->Database->quote($server_uuid)." +;"; + my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ }); + my $count = @{$results}; + + if ($count == 1) + { + my $row = $results->[0]; + my $anvil_uuid = $row->[0]; + my $host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; + + $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid, host_uuid => $host_uuid, server_uuid => $server_uuid } }); + + # if ($on) + # { + # $anvil->Database->insert_or_update_jobs({ + # job_command => $anvil->data->{path}{exe}{'anvil-boot-server'}." --server-uuid ".$server_uuid, + # job_host_uuid => $host_uuid, + # job_description => "", + # job_name => "cgi-bin::set_power::server::on", + # job_progress => 0, + # job_title => "" + # }); + # } + # else + # { + # $anvil->Database->insert_or_update_jobs({ + # job_command => $anvil->data->{path}{exe}{'anvil-shutdown-server'}." --server-uuid ".$server_uuid, + # job_host_uuid => $host_uuid, + # job_description => "", + # job_name => "cgi-bin::set_power::server::off", + # job_progress => 0, + # job_title => "" + # }); + # } + } +} + $anvil->Get->switches; $anvil->Database->connect; @@ -217,6 +267,8 @@ elsif ($server_uuid_list) my $server_uuid = $_; $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { server_uuid => $server_uuid } }); + + set_server_power({ server_uuid => $server_uuid, on => $is_on }); } }