|
|
@ -27,15 +27,6 @@ sub set_anvil_power |
|
|
|
my $anvil_uuid = $parameters->{anvil_uuid}; |
|
|
|
my $anvil_uuid = $parameters->{anvil_uuid}; |
|
|
|
my $on = $parameters->{on}; |
|
|
|
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. |
|
|
|
# Get all mandatory hosts inside the anvil identified by the given UUID. |
|
|
|
my @host_uuids = ( |
|
|
|
my @host_uuids = ( |
|
|
|
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}, |
|
|
|
$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. |
|
|
|
# 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})) |
|
|
|
if (length($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid})) |
|
|
|
{ |
|
|
|
{ |
|
|
|
push( |
|
|
|
push(@host_uuids, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}); |
|
|
|
@host_uuids, |
|
|
|
|
|
|
|
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (@host_uuids) |
|
|
|
foreach (@host_uuids) |
|
|
|
{ |
|
|
|
{ |
|
|
|
set_host_power({ |
|
|
|
set_host_power({ host_uuid => $_, on => $on }); |
|
|
|
host_uuid => $_, |
|
|
|
|
|
|
|
on => $on |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -116,9 +101,7 @@ sub set_host_power |
|
|
|
$anvil->Get->switches; |
|
|
|
$anvil->Get->switches; |
|
|
|
|
|
|
|
|
|
|
|
# Temporary; for debugging |
|
|
|
# Temporary; for debugging |
|
|
|
$anvil->Log->level({ |
|
|
|
$anvil->Log->level({ set => 2 }); |
|
|
|
set => 2 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$anvil->Database->connect; |
|
|
|
$anvil->Database->connect; |
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
|
|
@ -139,23 +122,13 @@ print $anvil->Template->get({file => "shared.html", name => "json_headers", show |
|
|
|
|
|
|
|
|
|
|
|
my $response_body = {}; |
|
|
|
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; |
|
|
|
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 { |
|
|
|
my $is_decode_json_success = eval { |
|
|
|
$request_body = decode_json( |
|
|
|
$request_body = decode_json($anvil->data->{cgi}{PUTDATA}{value}); |
|
|
|
$anvil->data->{cgi}{PUTDATA}{value} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (not $is_decode_json_success) |
|
|
|
if (not $is_decode_json_success) |
|
|
@ -167,14 +140,9 @@ if (not $is_decode_json_success) |
|
|
|
'print' => 1, |
|
|
|
'print' => 1, |
|
|
|
priority => "err", |
|
|
|
priority => "err", |
|
|
|
key => "error_0304", |
|
|
|
key => "error_0304", |
|
|
|
variables => { |
|
|
|
variables => { request_body_string => $anvil->data->{cgi}{PUTDATA}{value}, json_decode_error => $_ } |
|
|
|
request_body_string => $anvil->data->{cgi}{PUTDATA}{value}, |
|
|
|
|
|
|
|
json_decode_error => $_ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
$anvil->nice_exit({ |
|
|
|
|
|
|
|
exit_code => 1 |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
$anvil->nice_exit({ exit_code => 1 }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
my $anvil_uuid = exists $request_body->{anvil_uuid} ? $request_body->{anvil_uuid} : ""; |
|
|
|
my $anvil_uuid = exists $request_body->{anvil_uuid} ? $request_body->{anvil_uuid} : ""; |
|
|
@ -196,10 +164,7 @@ if ($anvil_uuid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}) |
|
|
|
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
set_anvil_power({ |
|
|
|
set_anvil_power({ anvil_uuid => $anvil_uuid, on => $is_on }); |
|
|
|
anvil_uuid => $anvil_uuid, |
|
|
|
|
|
|
|
on => $is_on |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -219,10 +184,7 @@ elsif ($host_uuid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (exists $anvil->data->{hosts}{host_uuid}{$anvil_uuid}) |
|
|
|
if (exists $anvil->data->{hosts}{host_uuid}{$anvil_uuid}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
set_host_power({ |
|
|
|
set_host_power({ host_uuid => $host_uuid, on => $is_on }); |
|
|
|
host_uuid => $host_uuid, |
|
|
|
|
|
|
|
on => $is_on |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|