style(cgi-bin): format set_power to keep consistency

main
Tsu-ba-me 4 years ago
parent fae1c72986
commit f966ed12fb
  1. 136
      cgi-bin/set_power

@ -27,15 +27,6 @@ sub set_anvil_power
my $anvil_uuid = $parameters->{anvil_uuid};
my $on = $parameters->{on};
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
anvil_data => Dumper($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})
}
});
# Get all mandatory hosts inside the anvil identified by the given UUID.
my @host_uuids = (
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid},
@ -45,18 +36,12 @@ sub set_anvil_power
# Check for DR host outside of the loop to avoid duplicating checks.
if (length($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}))
{
push(
@host_uuids,
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}
);
push(@host_uuids, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid});
}
foreach (@host_uuids)
{
set_host_power({
host_uuid => $_,
on => $on
});
set_host_power({ host_uuid => $_, on => $on });
}
}
@ -72,12 +57,12 @@ sub set_host_power
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
host_uuid => $host_uuid,
line => __LINE__,
level => 2,
list => {
host_uuid => $host_uuid,
is_host_on => $is_host_on,
on => $on
on => $on
}
});
@ -89,11 +74,11 @@ sub set_host_power
# TODO: Uncomment when testing against real hosts.
#
#$anvil->Database->insert_or_update_jobs({
# job_command => $anvil->data->{path}{exe}{'anvil-safe-stop'}." --power-off",
# job_command => $anvil->data->{path}{exe}{'anvil-safe-stop'}." --power-off",
# job_description => "job_0333",
# job_name => "cgi-bin::set_power::off",
# job_progress => 0,
# job_title => "job_0332"
# job_name => "cgi-bin::set_power::off",
# job_progress => 0,
# job_title => "job_0332"
#});
}
# When host is OFF and request is to power ON.
@ -104,11 +89,11 @@ sub set_host_power
# TODO: Uncomment when testing against real hosts.
#
#$anvil->Database->insert_or_update_jobs({
# job_command => $anvil->data->{path}{directories}{tools}."/striker-boot-machine --host-uuid ".$host_uuid,
# job_command => $anvil->data->{path}{directories}{tools}."/striker-boot-machine --host-uuid ".$host_uuid,
# job_description => "job_0335",
# job_name => "cgi-bin::set_power::on",
# job_progress => 0,
# job_title => "job_0334"
# job_name => "cgi-bin::set_power::on",
# job_progress => 0,
# job_title => "job_0334"
#});
}
}
@ -116,9 +101,7 @@ sub set_host_power
$anvil->Get->switches;
# Temporary; for debugging
$anvil->Log->level({
set => 2
});
$anvil->Log->level({ set => 2 });
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
@ -139,42 +122,27 @@ print $anvil->Template->get({file => "shared.html", name => "json_headers", show
my $response_body = {};
# Decode request body (JSON string) to a hash
# Decode request body (JSON string) to a hash.
#
# Note: requests made with the PUT method won't have query params.
my $request_body;
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
# Requests made with the PUT method won't have query params
CGI => Dumper($anvil->data->{cgi})
}
});
my $is_decode_json_success = eval {
$request_body = decode_json(
$anvil->data->{cgi}{PUTDATA}{value}
);
$request_body = decode_json($anvil->data->{cgi}{PUTDATA}{value});
};
if (not $is_decode_json_success)
{
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0304",
variables => {
request_body_string => $anvil->data->{cgi}{PUTDATA}{value},
json_decode_error => $_
}
});
$anvil->nice_exit({
exit_code => 1
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0304",
variables => { request_body_string => $anvil->data->{cgi}{PUTDATA}{value}, json_decode_error => $_ }
});
$anvil->nice_exit({ exit_code => 1 });
}
my $anvil_uuid = exists $request_body->{anvil_uuid} ? $request_body->{anvil_uuid} : "";
@ -183,12 +151,12 @@ my $is_on = exists $request_body->{is_on} ? $request_body->{is_on}
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
line => __LINE__,
level => 2,
list => {
anvil_uuid => $anvil_uuid,
host_uuid => $host_uuid,
is_on => $is_on
host_uuid => $host_uuid,
is_on => $is_on
}
});
@ -196,21 +164,18 @@ if ($anvil_uuid)
{
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})
{
set_anvil_power({
anvil_uuid => $anvil_uuid,
on => $is_on
});
set_anvil_power({ anvil_uuid => $anvil_uuid, on => $is_on });
}
else
{
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => "anvil UUID", uuid => $anvil_uuid }
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => "anvil UUID", uuid => $anvil_uuid }
});
$anvil->nice_exit({ exit_code => 1 });
}
@ -219,21 +184,18 @@ elsif ($host_uuid)
{
if (exists $anvil->data->{hosts}{host_uuid}{$anvil_uuid})
{
set_host_power({
host_uuid => $host_uuid,
on => $is_on
});
set_host_power({ host_uuid => $host_uuid, on => $is_on });
}
else
{
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => "host UUID", uuid => $host_uuid }
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => "host UUID", uuid => $host_uuid }
});
$anvil->nice_exit({ exit_code => 1 });
}

Loading…
Cancel
Save