* Removed Network->is_remote, standardized on Network->is_local, and flipped calls to it to be more sensible (is_local -> local call -> else remote call). Also fixed a deep recursion issue with ->is_local where, given that it logs (which calls Storage methods which have local/remote invocations), would loop.

* Fixed a bug where '$target' being preset to 'local' was causing bad calls to 'Remote->call'.
* Updated Storage->change_mode and -> change_owner to work locally and on remote hosts.
* Barely started work on striker->process_anvil_menu().

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent a7f93c59ea
commit 32bcdbe6d3
  1. 124
      Anvil/Tools/DRBD.pm
  2. 4
      Anvil/Tools/Database.pm
  3. 30
      Anvil/Tools/Get.pm
  4. 244
      Anvil/Tools/Network.pm
  5. 7
      Anvil/Tools/Remote.pm
  6. 119
      Anvil/Tools/Server.pm
  7. 749
      Anvil/Tools/Storage.pm
  8. 80
      Anvil/Tools/System.pm
  9. 21
      cgi-bin/striker
  10. 2
      tools/anvil-daemon

@ -119,7 +119,7 @@ sub allow_two_primaries
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $resource = defined $parameter->{resource} ? $parameter->{resource} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $target_node_id = defined $parameter->{target_node_id} ? $parameter->{target_node_id} : "";
my $return_code = 255;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -186,7 +186,19 @@ sub allow_two_primaries
my $shell_call = $anvil->data->{path}{exe}{drbdsetup}." net-options ".$resource." ".$target_node_id." --allow-two-primaries=yes";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($output, $return_code) = $anvil->System->call({
debug => $debug,
shell_call => $shell_call,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call.
($output, my $error, $return_code) = $anvil->Remote->call({
@ -203,18 +215,6 @@ sub allow_two_primaries
return_code => $return_code,
}});
}
else
{
# Local.
($output, $return_code) = $anvil->System->call({
debug => $debug,
shell_call => $shell_call,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
if ($return_code)
{
@ -261,7 +261,7 @@ sub get_devices
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -273,7 +273,16 @@ sub get_devices
my $host = $anvil->_short_host_name;
my $shell_call = $anvil->data->{path}{exe}{drbdadm}." dump-xml";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($output, $anvil->data->{drbd}{'drbdadm-xml'}{return_code}) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
"drbd::drbdadm-xml::return_code" => $anvil->data->{drbd}{'drbdadm-xml'}{return_code},
}});
}
else
{
# Remote call.
($output, my $error, $anvil->data->{drbd}{'drbdadm-xml'}{return_code}) = $anvil->Remote->call({
@ -292,15 +301,6 @@ sub get_devices
"drbd::drbdadm-xml::return_code" => $anvil->data->{drbd}{'drbdadm-xml'}{return_code},
}});
}
else
{
# Local.
($output, $anvil->data->{drbd}{'drbdadm-xml'}{return_code}) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
"drbd::drbdadm-xml::return_code" => $anvil->data->{drbd}{'drbdadm-xml'}{return_code},
}});
}
# Clear the hash where we'll store the data.
if (exists $anvil->data->{drbd}{config}{$host})
@ -532,7 +532,7 @@ sub get_status
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -544,26 +544,17 @@ sub get_status
my $shell_call = $anvil->data->{path}{exe}{drbdsetup}." status --json";
my $output = "";
my $host = $anvil->_short_host_name();
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Clear the hash where we'll store the data.
$host = $target;
if (exists $anvil->data->{drbd}{status}{$host})
{
delete $anvil->data->{drbd}{status}{$host};
}
# Remote call.
($output, my $error, $anvil->data->{drbd}{status}{$host}{return_code}) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
# Local.
($output, $anvil->data->{drbd}{status}{return_code}) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
"drbd::status::${host}::return_code" => $anvil->data->{drbd}{status}{return_code},
}});
@ -571,14 +562,23 @@ sub get_status
else
{
# Clear the hash where we'll store the data.
$host = $target;
if (exists $anvil->data->{drbd}{status}{$host})
{
delete $anvil->data->{drbd}{status}{$host};
}
# Local.
($output, $anvil->data->{drbd}{status}{return_code}) = $anvil->System->call({shell_call => $shell_call});
# Remote call.
($output, my $error, $anvil->data->{drbd}{status}{$host}{return_code}) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
"drbd::status::${host}::return_code" => $anvil->data->{drbd}{status}{return_code},
}});
@ -791,7 +791,7 @@ sub manage_resource
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $resource = defined $parameter->{resource} ? $parameter->{resource} : "";
my $task = defined $parameter->{task} ? $parameter->{task} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -817,7 +817,16 @@ sub manage_resource
my $shell_call = $anvil->data->{path}{exe}{drbdadm}." ".$task." ".$resource;
my $output = "";
my $return_code = 255;
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call.
($output, my $error, $return_code) = $anvil->Remote->call({
@ -834,15 +843,6 @@ sub manage_resource
return_code => $return_code,
}});
}
else
{
# Local.
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
return($return_code);
}
@ -887,7 +887,7 @@ sub reload_defaults
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $resource = defined $parameter->{resource} ? $parameter->{resource} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $return_code = 255;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
@ -906,7 +906,16 @@ sub reload_defaults
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 0, level => 2, key => "log_0355"});
my $shell_call = $anvil->data->{path}{exe}{drbdadm}." adjust ".$resource;
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call.
($output, my $error, $return_code) = $anvil->Remote->call({
@ -923,15 +932,6 @@ sub reload_defaults
return_code => $return_code,
}});
}
else
{
# Local.
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
if ($return_code)
{

@ -6376,7 +6376,7 @@ sub manage_anvil_conf
my $port = defined $parameter->{port} ? $parameter->{port} : 22;
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $remove = defined $parameter->{remove} ? $parameter->{remove} : 0;
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
db_password => $anvil->Log->is_secure($db_password),
db_ping => $db_ping,
@ -6730,7 +6730,7 @@ sub manage_anvil_conf
# If this is a local update, disconnect (if no connections exist, will still clear out known
# databases), the re-read the new config.
if (not $anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
$anvil->Database->disconnect;

@ -124,7 +124,7 @@ sub anvil_version
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $version = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
@ -134,7 +134,20 @@ sub anvil_version
}});
# Is this a local call or a remote call?
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
$version = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'anvil.version'}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { version => $version }});
# Did we actually read a version?
if ($version eq "!!error!!")
{
$version = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { version => $version }});
}
}
else
{
# Remote call. If we're running as the apache user, we need to read the cached version for
# the peer. otherwise, after we read the version, will write the cached version.
@ -219,19 +232,6 @@ fi;
}
}
}
else
{
# Local.
$version = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'anvil.version'}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { version => $version }});
# Did we actually read a version?
if ($version eq "!!error!!")
{
$version = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { version => $version }});
}
}
# Clear off any newline.
$version =~ s/\n//gs;

@ -19,7 +19,6 @@ my $THIS_FILE = "Network.pm";
# get_ips
# get_network
# is_local
# is_remote
# load_ips
# ping
@ -115,7 +114,7 @@ If C<< target >> is set, this is the TCP port number used to connect to the remo
If C<< target >> is set, this is the user account that will be used when connecting to the remote system.
=head3 target (optional, default 'local')
=head3 target (optional, default '')
If set, the bridge data will be read from the target machine. This needs to be the IP address or (resolvable) host name of the target.
@ -131,7 +130,7 @@ sub bridge_info
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : 22;
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -141,7 +140,16 @@ sub bridge_info
my $shell_call = $anvil->data->{path}{exe}{bridge}." -json -pretty link show";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
else
{
# Remote call
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -158,15 +166,6 @@ sub bridge_info
's3:return_code' => $return_code,
}});
}
else
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
# Did I get usable data?
if ($output !~ /^\[/)
@ -182,24 +181,26 @@ sub bridge_info
{
my $bridge = $hash_ref->{master};
my $interface = $hash_ref->{ifname};
my $host = $target ? $target : "local";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:bridge' => $bridge,
's2:interface' => $interface,
's3:host' => $host,
}});
if ((not exists $anvil->data->{bridge}{$target}{$bridge}) or (ref($anvil->data->{bridge}{$target}{$bridge}{interfaces}) ne "ARRAY"))
if ((not exists $anvil->data->{bridge}{$host}{$bridge}) or (ref($anvil->data->{bridge}{$host}{$bridge}{interfaces}) ne "ARRAY"))
{
$anvil->data->{bridge}{$target}{$bridge}{interfaces} = [];
$anvil->data->{bridge}{$host}{$bridge}{interfaces} = [];
}
push @{$anvil->data->{bridge}{$target}{$bridge}{interfaces}}, $interface;
push @{$anvil->data->{bridge}{$host}{$bridge}{interfaces}}, $interface;
# Now store the rest of the data.
foreach my $key (sort {$a cmp $b} keys %{$hash_ref})
{
next if $key eq "master";
next if $key eq "ifname";
$anvil->data->{bridge}{$target}{$bridge}{$interface}{$key} = $hash_ref->{$key};
$anvil->data->{bridge}{$host}{$bridge}{$interface}{$key} = $hash_ref->{$key};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"bridge::${target}::${bridge}::${interface}::${key}" => $anvil->data->{bridge}{$target}{$bridge}{$interface}{$key},
"bridge::${host}::${bridge}::${interface}::${key}" => $anvil->data->{bridge}{$host}{$bridge}{$interface}{$key},
}});
}
}
@ -253,7 +254,7 @@ sub check_internet
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : 22;
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $tries = defined $parameter->{tries} ? $parameter->{tries} : 3;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
domains => $domains,
@ -947,7 +948,7 @@ sub get_ips
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : 22;
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -955,11 +956,24 @@ sub get_ips
target => $target,
}});
# This is used in the hash reference when storing the data.
my $host = $target ? $target : "local";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
# Reading locally or remote?
my $in_iface = "";
my $shell_call = $anvil->data->{path}{exe}{ip}." addr list";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
else
{
# Remote call
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -976,15 +990,6 @@ sub get_ips
's3:return_code' => $return_code,
}});
}
else
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
@ -993,18 +998,18 @@ sub get_ips
$in_iface = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_iface => $in_iface }});
$anvil->data->{network}{$target}{interface}{$in_iface}{ip} = "" if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{ip};
$anvil->data->{network}{$target}{interface}{$in_iface}{subnet} = "" if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{subnet};
$anvil->data->{network}{$target}{interface}{$in_iface}{mac} = "" if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{mac};
$anvil->data->{network}{$target}{interface}{$in_iface}{default_gateway} = 0 if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{default_gateway};
$anvil->data->{network}{$target}{interface}{$in_iface}{gateway} = "" if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{gateway};
$anvil->data->{network}{$target}{interface}{$in_iface}{dns} = "" if not defined $anvil->data->{network}{$target}{interface}{$in_iface}{dns};
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{ip};
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{subnet};
$anvil->data->{network}{$host}{interface}{$in_iface}{mac} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{mac};
$anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway};
$anvil->data->{network}{$host}{interface}{$in_iface}{gateway} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{gateway};
$anvil->data->{network}{$host}{interface}{$in_iface}{dns} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{dns};
}
next if not $in_iface;
if ($in_iface eq "lo")
{
# We don't care about 'lo'.
delete $anvil->data->{network}{$target}{interface}{$in_iface};
delete $anvil->data->{network}{$host}{interface}{$in_iface};
next;
}
if ($line =~ /inet (.*?)\/(.*?) /)
@ -1021,19 +1026,19 @@ sub get_ips
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { subnet => $subnet }});
}
$anvil->data->{network}{$target}{interface}{$in_iface}{ip} = $ip;
$anvil->data->{network}{$target}{interface}{$in_iface}{subnet} = $subnet;
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = $ip;
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet} = $subnet;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"s1:network::${target}::interface::${in_iface}::ip" => $anvil->data->{network}{$target}{interface}{$in_iface}{ip},
"s2:network::${target}::interface::${in_iface}::subnet" => $anvil->data->{network}{$target}{interface}{$in_iface}{subnet},
"s1:network::${host}::interface::${in_iface}::ip" => $anvil->data->{network}{$host}{interface}{$in_iface}{ip},
"s2:network::${host}::interface::${in_iface}::subnet" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet},
}});
}
if ($line =~ /ether ([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}) /i)
{
my $mac = $1;
$anvil->data->{network}{$target}{interface}{$in_iface}{mac} = $mac;
$anvil->data->{network}{$host}{interface}{$in_iface}{mac} = $mac;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${target}::interface::${in_iface}::mac" => $anvil->data->{network}{$target}{interface}{$in_iface}{mac},
"network::${host}::interface::${in_iface}::mac" => $anvil->data->{network}{$host}{interface}{$in_iface}{mac},
}});
# We only record the mac in 'network::mac' if this isn't a bond.
@ -1053,7 +1058,16 @@ sub get_ips
# we'll read them all in.
$shell_call = $anvil->data->{path}{exe}{ls}." ".$anvil->data->{path}{directories}{ifcfg};
$output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
else
{
# Remote call
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -1070,19 +1084,11 @@ sub get_ips
's3:return_code' => $return_code,
}});
}
else
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
next if $line !~ /^ifcfg-/;
my $full_path = $anvil->data->{path}{directories}{ifcfg}."/".$line;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { full_path => $full_path }});
@ -1108,30 +1114,34 @@ sub get_ips
next if $line =~ /^#/;
if ($line =~ /(.*?)=(.*)/)
{
my $variable = $1;
my $value = $2;
$value =~ s/^"(.*)"$/$1/;
$temp->{$variable} = $value;
my $variable = $1;
my $value = $2;
$value =~ s/^"(.*)"$/$1/;
$temp->{$variable} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "temp->{$variable}" => $temp->{$variable} }});
if (uc($variable) eq "DEVICE")
{
# If this isn't a device we saw in 'ip addr', skip it by just not setting the interface variable
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { value => $value }});
last if not exists $anvil->data->{network}{$host}{interface}{$value};
$interface = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "interface" => $interface }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }});
}
}
if ($interface)
{
$anvil->data->{network}{$target}{interface}{$interface}{file} = $full_path;
$anvil->data->{network}{$host}{interface}{$interface}{file} = $full_path;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${target}::interface::${interface}::file" => $anvil->data->{network}{$target}{interface}{$interface}{file},
"network::${host}::interface::${interface}::file" => $anvil->data->{network}{$host}{interface}{$interface}{file},
}});
foreach my $variable (sort {$a cmp $b} keys %{$temp})
{
$anvil->data->{network}{$target}{interface}{$interface}{variable}{$variable} = $temp->{$variable};
$anvil->data->{network}{$host}{interface}{$interface}{variable}{$variable} = $temp->{$variable};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${target}::interface::${interface}::file::variable::${variable}" => $anvil->data->{network}{$target}{interface}{$interface}{variable}{$variable},
"network::${host}::interface::${interface}::file::variable::${variable}" => $anvil->data->{network}{$host}{interface}{$interface}{variable}{$variable},
}});
}
}
@ -1144,7 +1154,16 @@ sub get_ips
my $route_ip = "";
$shell_call = $anvil->data->{path}{exe}{ip}." route show";
$output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
else
{
# Remote call
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -1161,15 +1180,6 @@ sub get_ips
's3:return_code' => $return_code,
}});
}
else
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
@ -1212,7 +1222,16 @@ sub get_ips
my $dns_hash = {};
my $shell_call = $anvil->data->{path}{exe}{nmcli}." dev show";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
else
{
# Remote call
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -1229,15 +1248,6 @@ sub get_ips
's3:return_code' => $return_code,
}});
}
else
{
# Local call.
($output, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:output' => $output,
's2:return_code' => $return_code,
}});
}
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
@ -1275,13 +1285,13 @@ sub get_ips
$dns_list =~ s/, $//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { dns_list => $dns_list }});
$anvil->data->{network}{$target}{interface}{$route_interface}{default_gateway} = 1;
$anvil->data->{network}{$target}{interface}{$route_interface}{gateway} = $route_ip;
$anvil->data->{network}{$target}{interface}{$route_interface}{dns} = $dns_list;
$anvil->data->{network}{$host}{interface}{$route_interface}{default_gateway} = 1;
$anvil->data->{network}{$host}{interface}{$route_interface}{gateway} = $route_ip;
$anvil->data->{network}{$host}{interface}{$route_interface}{dns} = $dns_list;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${target}::interface::${route_interface}::default_gateway" => $anvil->data->{network}{$target}{interface}{$route_interface}{default_gateway},
"network::${target}::interface::${route_interface}::gateway" => $anvil->data->{network}{$target}{interface}{$route_interface}{gateway},
"network::${target}::interface::${route_interface}::dns" => $anvil->data->{network}{$target}{interface}{$route_interface}{dns},
"network::${host}::interface::${route_interface}::default_gateway" => $anvil->data->{network}{$host}{interface}{$route_interface}{default_gateway},
"network::${host}::interface::${route_interface}::gateway" => $anvil->data->{network}{$host}{interface}{$route_interface}{gateway},
"network::${host}::interface::${route_interface}::dns" => $anvil->data->{network}{$host}{interface}{$route_interface}{dns},
}});
}
@ -1348,7 +1358,6 @@ sub get_network
return($network);
}
### TODO: Merge the logic with ->is_remote and then make one of them simply invert the output of the other.
=head2 is_local
This method takes a host name or IP address and looks to see if it matches the local system. If it does, it returns C<< 1 >>. Otherwise it returns C<< 0 >>.
@ -1366,7 +1375,11 @@ sub is_local
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->_is_local()" }});
# To avoid deep recurssion, we set this on the first call so that anything below that re-calls us just gets a quick '1' and returns
$anvil->data->{env}{checking_local} = 0 if not defined $anvil->data->{env}{checking_local};
return(1) if $anvil->data->{env}{checking_local};
$anvil->data->{env}{checking_local} = 1;
my $host = $parameter->{host} ? $parameter->{host} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
@ -1383,8 +1396,10 @@ sub is_local
}
else
{
### NOTE: We use the undocumented 'is_local' parameter to avoid ->get_ips() calling us,
### causing a recursive loop.
# Get the list of current IPs and see if they match.
$anvil->Network->get_ips;
$anvil->Network->get_ips({debug => 3});
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "network::local::interface::${interface}::ip" => $anvil->data->{network}{'local'}{interface}{$interface}{ip} }});
@ -1398,41 +1413,10 @@ sub is_local
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }});
delete $anvil->data->{env}{checking_local};
return($is_local);
}
=head2 is_remote
This looks at the C<< target >> and determines if it relates to the local system or not. If the C<< target >> is remote, C<< 1 >> is returned. Otherwise, C<< 0 >> is returned.
if ($anvil->Network->is_remote($target))
{
# Do something remotely
}
else
{
# Do something locally
}
B<< NOTE >>: Unlike most methods, this one does not take a hash reference for the parameters. It takes the string directly.
=cut
sub is_remote
{
my $self = shift;
my $target = shift;
my $anvil = $self->parent;
my $remote = 0;
if (($target) && ($target ne "local") && ($target ne $anvil->_host_name) && ($target ne $anvil->_short_host_name))
{
# It's a remote system
$remote = 1;
}
return($remote);
}
# =head3
#
# Private Functions;
@ -1594,7 +1578,13 @@ sub ping
my $error = "";
# If the 'target' is set, we'll call over SSH unless 'target' is 'local' or our host name.
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
### Local calls
($output, my $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
}
else
{
### Remote calls
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0166", variables => { shell_call => $shell_call, target => $target, remote_user => $remote_user }});
@ -1612,12 +1602,6 @@ sub ping
return_code => $return_code,
}});
}
else
{
### Local calls
($output, my $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
}
foreach my $line (split/\n/, $output)
{

@ -309,6 +309,13 @@ sub call
target => $target,
}});
# In case 'target' is 'local', change it to ''.
if ($target eq "local")
{
$target = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { target => $target }});
}
if (not $shell_call)
{
# No shell call

@ -211,7 +211,7 @@ sub find
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $refresh = defined $parameter->{refresh} ? $parameter->{refresh} : 1;
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -230,7 +230,16 @@ sub find
my $host = $anvil->_host_name;
my $virsh_output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call
($virsh_output, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." list --all"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
virsh_output => $virsh_output,
return_code => $return_code,
}});
}
else
{
# Remote call.
($host, my $error, my $host_return_code) = $anvil->Remote->call({
@ -258,14 +267,6 @@ sub find
return_code => $return_code,
}});
}
else
{
($virsh_output, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." list --all"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
virsh_output => $virsh_output,
return_code => $return_code,
}});
}
foreach my $line (split/\n/, $virsh_output)
{
@ -327,7 +328,7 @@ sub get_status
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -335,16 +336,20 @@ sub get_status
target => $target,
}});
# This is used in the hash reference when storing the data.
my $host = $target ? $target : "local";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
if (not $server)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Server->get_status()", parameter => "server" }});
return(1);
}
if (exists $anvil->data->{server}{$target}{$server})
if (exists $anvil->data->{server}{$host}{$server})
{
delete $anvil->data->{server}{$target}{$server};
delete $anvil->data->{server}{$host}{$server};
}
$anvil->data->{server}{$target}{$server}{from_memory}{host} = "";
$anvil->data->{server}{$host}{$server}{from_memory}{host} = "";
# We're going to map DRBD devices to resources, so we need to collect that data now.
$anvil->DRBD->get_devices({
@ -357,12 +362,21 @@ sub get_status
# Is this a local call or a remote call?
my $shell_call = $anvil->data->{path}{exe}{virsh}." dumpxml ".$server;
my $host = $anvil->_short_host_name;
if ($anvil->Network->is_remote($target))
my $this_host = $anvil->_short_host_name;
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($anvil->data->{server}{$host}{$server}{from_memory}{xml}, $anvil->data->{server}{$host}{$server}{from_memory}{return_code}) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"server::${host}::${server}::from_memory::xml" => $anvil->data->{server}{$host}{$server}{from_memory}{xml},
"server::${host}::${server}::from_memory::return_code" => $anvil->data->{server}{$host}{$server}{from_memory}{return_code},
}});
}
else
{
# Remote call.
$host = $target;
($anvil->data->{server}{$target}{$server}{from_memory}{xml}, my $error, $anvil->data->{server}{$target}{$server}{from_memory}{return_code}) = $anvil->Remote->call({
$this_host = $target;
($anvil->data->{server}{$host}{$server}{from_memory}{xml}, my $error, $anvil->data->{server}{$host}{$server}{from_memory}{return_code}) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
@ -372,39 +386,30 @@ sub get_status
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
"server::${target}::${server}::from_memory::xml" => $anvil->data->{server}{$target}{$server}{from_memory}{xml},
"server::${target}::${server}::from_memory::return_code" => $anvil->data->{server}{$target}{$server}{from_memory}{return_code},
}});
}
else
{
# Local.
($anvil->data->{server}{$target}{$server}{from_memory}{xml}, $anvil->data->{server}{$target}{$server}{from_memory}{return_code}) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"server::${target}::${server}::from_memory::xml" => $anvil->data->{server}{$target}{$server}{from_memory}{xml},
"server::${target}::${server}::from_memory::return_code" => $anvil->data->{server}{$target}{$server}{from_memory}{return_code},
"server::${host}::${server}::from_memory::xml" => $anvil->data->{server}{$host}{$server}{from_memory}{xml},
"server::${host}::${server}::from_memory::return_code" => $anvil->data->{server}{$host}{$server}{from_memory}{return_code},
}});
}
# If the return code was non-zero, we can't parse the XML.
if ($anvil->data->{server}{$target}{$server}{from_memory}{return_code})
if ($anvil->data->{server}{$host}{$server}{from_memory}{return_code})
{
$anvil->data->{server}{$target}{$server}{from_memory}{xml} = "";
$anvil->data->{server}{$host}{$server}{from_memory}{xml} = "";
}
else
{
$anvil->data->{server}{$target}{$server}{from_memory}{host} = $host;
$anvil->data->{server}{$host}{$server}{from_memory}{host} = $this_host;
$anvil->Server->_parse_definition({
debug => $debug,
host => $host,
host => $this_host,
server => $server,
source => "from_memory",
definition => $anvil->data->{server}{$target}{$server}{from_memory}{xml},
definition => $anvil->data->{server}{$host}{$server}{from_memory}{xml},
});
}
# Now get the on-disk XML.
($anvil->data->{server}{$target}{$server}{from_disk}{xml}) = $anvil->Storage->read_file({
($anvil->data->{server}{$host}{$server}{from_disk}{xml}) = $anvil->Storage->read_file({
debug => $debug,
password => $password,
port => $port,
@ -414,21 +419,21 @@ sub get_status
file => $anvil->data->{path}{directories}{shared}{definitions}."/".$server.".xml",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"server::${target}::${server}::from_disk::xml" => $anvil->data->{server}{$target}{$server}{from_disk}{xml},
"server::${host}::${server}::from_disk::xml" => $anvil->data->{server}{$host}{$server}{from_disk}{xml},
}});
if (($anvil->data->{server}{$target}{$server}{from_disk}{xml} eq "!!errer!!") or (not $anvil->data->{server}{$target}{$server}{from_disk}{xml}))
if (($anvil->data->{server}{$host}{$server}{from_disk}{xml} eq "!!errer!!") or (not $anvil->data->{server}{$host}{$server}{from_disk}{xml}))
{
# Failed to read it.
$anvil->data->{server}{$target}{$server}{from_disk}{xml} = "";
$anvil->data->{server}{$host}{$server}{from_disk}{xml} = "";
}
else
{
$anvil->Server->_parse_definition({
debug => $debug,
host => $host,
host => $this_host,
server => $server,
source => "from_disk",
definition => $anvil->data->{server}{$target}{$server}{from_disk}{xml},
definition => $anvil->data->{server}{$host}{$server}{from_disk}{xml},
});
}
@ -457,7 +462,7 @@ Is set to C<< 0 >>, any previously seen servers and their information is cleared
If C<< target >> is set, this will be the user we connect to the remote machine as.
=head3 target (optional, default 'local')
=head3 target (optional, default '')
This is the IP or host name of the host to map the network of hosted servers on.
@ -473,7 +478,7 @@ sub map_network
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
@ -485,7 +490,16 @@ sub map_network
# Get a list of servers.
my $shell_call = $anvil->data->{path}{exe}{virsh}." list";
my $output = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local.
($output, my $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call.
($output, my $error, my $return_code) = $anvil->Remote->call({
@ -502,15 +516,6 @@ sub map_network
return_code => $return_code,
}});
}
else
{
# Local.
($output, my $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
foreach my $line (split/\n/, $output)
{
@ -535,10 +540,13 @@ sub map_network
target => $target,
});
foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$target}{$server}{from_memory}{device}{interface}})
# This is used in the hash reference when storing the data.
my $host = $target ? $target : "local";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$host}{$server}{from_memory}{device}{interface}})
{
my $device = $anvil->data->{server}{$target}{$server}{from_memory}{device}{interface}{$mac}{target};
my $bridge = $anvil->data->{server}{$target}{$server}{from_memory}{device}{interface}{$mac}{bridge};
my $device = $anvil->data->{server}{$host}{$server}{from_memory}{device}{interface}{$mac}{target};
my $bridge = $anvil->data->{server}{$host}{$server}{from_memory}{device}{interface}{$mac}{bridge};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:device' => $device,
's2:mac' => $mac,
@ -584,7 +592,6 @@ sub migrate
my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : $anvil->_host_name;
#my $target = defined $parameter->{target} ? $parameter->{target} : "local";
my $success = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server => $server,

@ -66,7 +66,7 @@ sub new
{
my $class = shift;
my $self = {
SEARCH_DIRECTORIES => \@INC,
SEARCH_DIRECTORIES => \@INC,
};
bless $self, $class;
@ -171,7 +171,33 @@ sub backup
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local file
if (not -e $source_file)
{
# File doesn't exist.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0151", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
elsif (not -f $source_file)
{
# Not a file
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0153", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
elsif (not -r $source_file)
{
# Can't read the file.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0152", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
else
{
$proceed = 1;
}
}
else
{
# Make sure the source file exists, is a file and can be read.
my $shell_call = "
@ -246,32 +272,6 @@ fi";
}
}
}
else
{
# Local file
if (not -e $source_file)
{
# File doesn't exist.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0151", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
elsif (not -f $source_file)
{
# Not a file
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0153", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
elsif (not -r $source_file)
{
# Can't read the file.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0152", variables => { source_file => $source_file }});
if ($fatal) { $anvil->nice_exit({code => 1}); }
}
else
{
$proceed = 1;
}
}
# Proceed?
if ($proceed)
@ -330,13 +330,29 @@ If it fails to write the file, an alert will be logged.
Parameters;
=head3 mode (required)
This is the numeric mode to set on the file. It expects four digits to cover the sticky bit, but will work with three digits.
=head3 path (required)
This is the file or directory to change the mode on.
=head3 mode (required)
=head3 port (optional, default 22)
This is the numeric mode to set on the file. It expects four digits to cover the sticky bit, but will work with three digits.
If C<< target >> is set, this is the TCP port number used to connect to the remote machine.
=head3 password (optional)
If C<< target >> is set, this is the password used to log into the remote system as the C<< remote_user >>. If it is not set, an attempt to connect without a password will be made (though this will usually fail).
=head3 target (optional)
If set, the file will be backed up on the target machine. This must be either an IP address or a resolvable host name.
=head3 remote_user (optional)
If C<< target >> is set, this is the user account that will be used when connecting to the remote system.
=cut
sub change_mode
@ -346,11 +362,19 @@ sub change_mode
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $path = defined $parameter->{path} ? $parameter->{path} : "";
my $mode = defined $parameter->{mode} ? $parameter->{mode} : "";
my $mode = defined $parameter->{mode} ? $parameter->{mode} : "";
my $path = defined $parameter->{path} ? $parameter->{path} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
mode => $mode,
path => $path,
mode => $mode,
path => $path,
port => $port,
password => $anvil->Log->is_secure($password),
target => $target,
remote_user => $remote_user,
}});
my $error = 0;
@ -377,14 +401,32 @@ sub change_mode
{
my $shell_call = $anvil->data->{path}{exe}{'chmod'}." $mode $path";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
if ($anvil->Network->is_local({host => $target}))
{
chomp;
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0017", variables => { line => $line }});
# Local call
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call.
my ($output, $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
return_code => $return_code,
}});
}
close $file_handle;
}
return(0);
@ -400,13 +442,29 @@ If it fails to write the file, an alert will be logged and 'C<< 1 >>' will be re
Parameters;
=head3 group (optional, default is the main group of the user running the program)
This is the group name or UID to set the path to.
=head3 path (required)
This is the file or directory to change the mode on.
=head3 group (optional, default is the main group of the user running the program)
=head3 port (optional, default 22)
This is the group name or UID to set the path to.
If C<< target >> is set, this is the TCP port number used to connect to the remote machine.
=head3 password (optional)
If C<< target >> is set, this is the password used to log into the remote system as the C<< remote_user >>. If it is not set, an attempt to connect without a password will be made (though this will usually fail).
=head3 remote_user (optional)
If C<< target >> is set, this is the user account that will be used when connecting to the remote system.
=head3 target (optional)
If set, the file will be backed up on the target machine. This must be either an IP address or a resolvable host name.
=head3 user (optional, default is the user running the program)
@ -420,13 +478,21 @@ sub change_owner
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $path = defined $parameter->{path} ? $parameter->{path} : "";
my $group = defined $parameter->{group} ? $parameter->{group} : getgrgid($();
my $user = defined $parameter->{user} ? $parameter->{user} : getpwuid($<);
my $group = defined $parameter->{group} ? $parameter->{group} : getgrgid($();
my $path = defined $parameter->{path} ? $parameter->{path} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $user = defined $parameter->{user} ? $parameter->{user} : getpwuid($<);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
path => $path,
group => $group,
user => $user,
group => $group,
path => $path,
port => $port,
password => $anvil->Log->is_secure($password),
remote_user => $remote_user,
target => $target,
user => $user,
}});
# Make sure the user and group and just one digit or word.
@ -470,14 +536,32 @@ sub change_owner
{
my $shell_call = $anvil->data->{path}{exe}{'chown'}." ".$string." ".$path;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
if ($anvil->Network->is_local({host => $target}))
{
# Local call
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
chomp;
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0017", variables => { line => $line }});
# Remote call.
my ($output, $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
return_code => $return_code,
}});
}
close $file_handle;
}
return($error);
@ -672,7 +756,54 @@ sub copy_file
file => $file,
}});
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Copying locally
if (not -e $source_file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0052", variables => {
method => "copy_file",
source_file => $source_file,
}});
return(1);
}
# If the target exists, abort
if ((-e $target_file) && (not $overwrite))
{
# This isn't an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0046", variables => {
method => "copy_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
# Make sure the target directory exists and create it, if not.
if (not -e $directory)
{
my $failed = $anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
if ($failed)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0170", variables => {
method => "copy_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
}
# Now backup the file.
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{'cp'}." -af ".$source_file." ".$target_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
}
else
{
# Copying on a remote system.
my $proceed = 1;
@ -775,53 +906,6 @@ fi";
}});
}
}
else
{
# Copying locally
if (not -e $source_file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0052", variables => {
method => "copy_file",
source_file => $source_file,
}});
return(1);
}
# If the target exists, abort
if ((-e $target_file) && (not $overwrite))
{
# This isn't an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0046", variables => {
method => "copy_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
# Make sure the target directory exists and create it, if not.
if (not -e $directory)
{
my $failed = $anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
if ($failed)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0170", variables => {
method => "copy_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
}
# Now backup the file.
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{'cp'}." -af ".$source_file." ".$target_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
}
return(0);
}
@ -991,7 +1075,49 @@ sub make_directory
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { working_directory => $working_directory }});
# Are we working locally or remotely?
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Locally.
if (not -e $working_directory)
{
# Directory doesn't exist, so create it.
my $error = "";
my $shell_call = $anvil->data->{path}{exe}{'mkdir'}." ".$working_directory;
print $THIS_FILE." ".__LINE__."; shell_call: [".$shell_call."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
{
chomp;
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0017", variables => { line => $line }});
$error .= $line."\n";
}
close $file_handle;
print $THIS_FILE." ".__LINE__."; mode: [".$mode."]\n" if $test;
if ($mode)
{
$anvil->Storage->change_mode({debug => $debug, path => $working_directory, mode => $mode});
}
print $THIS_FILE." ".__LINE__."; user: [".$user."], group: [".$group."]\n" if $test;
if (($user) or ($group))
{
$anvil->Storage->change_owner({debug => $debug, path => $working_directory, user => $user, group => $group});
}
if (not -e $working_directory)
{
$failed = 1;
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0168", variables => {
directory => $working_directory,
error => $error,
}});
}
}
}
else
{
# Assemble the command
my $shell_call = "
@ -1050,48 +1176,6 @@ fi;";
}});
}
}
else
{
# Locally.
if (not -e $working_directory)
{
# Directory doesn't exist, so create it.
my $error = "";
my $shell_call = $anvil->data->{path}{exe}{'mkdir'}." ".$working_directory;
print $THIS_FILE." ".__LINE__."; shell_call: [".$shell_call."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
{
chomp;
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0017", variables => { line => $line }});
$error .= $line."\n";
}
close $file_handle;
print $THIS_FILE." ".__LINE__."; mode: [".$mode."]\n" if $test;
if ($mode)
{
$anvil->Storage->change_mode({debug => $debug, path => $working_directory, mode => $mode});
}
print $THIS_FILE." ".__LINE__."; user: [".$user."], group: [".$group."]\n" if $test;
if (($user) or ($group))
{
$anvil->Storage->change_owner({debug => $debug, path => $working_directory, user => $user, group => $group});
}
if (not -e $working_directory)
{
$failed = 1;
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0168", variables => {
directory => $working_directory,
error => $error,
}});
}
}
}
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
last if $failed;
}
@ -1200,7 +1284,54 @@ sub move_file
}});
}
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Copying locally
if (not -e $source_file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0052", variables => {
method => "move_file",
source_file => $source_file,
}});
return(1);
}
# If the target exists, abort
if ((-e $target_file) && (not $overwrite))
{
# This isn't an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0046", variables => {
method => "move_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
# Make sure the target directory exists and create it, if not.
if (not -e $directory)
{
my $failed = $anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
if ($failed)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0170", variables => {
method => "move_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
}
# Now backup the file.
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{'mv'}." -f ".$source_file." ".$target_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
}
else
{
# Copying on a remote system.
my $proceed = 1;
@ -1273,67 +1404,10 @@ fi";
debug => $debug,
directory => $directory,
password => $password,
remote_user => $remote_user,
target => $target,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0170", variables => {
method => "move_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
# Now backup the file.
my ($output, $error, $return_code) = $anvil->Remote->call({
debug => $debug,
target => $target,
user => $remote_user,
password => $password,
remote_user => $remote_user,
shell_call => $anvil->data->{path}{exe}{mv}." -f ".$source_file." ".$target_file,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
}});
}
}
else
{
# Copying locally
if (not -e $source_file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0052", variables => {
method => "move_file",
source_file => $source_file,
}});
return(1);
}
# If the target exists, abort
if ((-e $target_file) && (not $overwrite))
{
# This isn't an error.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0046", variables => {
method => "move_file",
source_file => $source_file,
target_file => $target_file,
}});
return(1);
}
# Make sure the target directory exists and create it, if not.
if (not -e $directory)
{
my $failed = $anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
if ($failed)
{
remote_user => $remote_user,
target => $target,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0170", variables => {
method => "move_file",
source_file => $source_file,
@ -1341,11 +1415,21 @@ fi";
}});
return(1);
}
}
# Now backup the file.
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{'mv'}." -f ".$source_file." ".$target_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
# Now backup the file.
my ($output, $error, $return_code) = $anvil->Remote->call({
debug => $debug,
target => $target,
user => $remote_user,
password => $password,
remote_user => $remote_user,
shell_call => $anvil->data->{path}{exe}{mv}." -f ".$source_file." ".$target_file,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
}});
}
}
return(0);
@ -1567,8 +1651,52 @@ sub read_file
return("!!error!!");
}
### NOTE: This is called by 'is_local', so it pre-sets 'is_local' to avoid a deep recursion.
# Reading locally or remote?
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local
if (not -e $file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0021", variables => { file => $file }});
return("!!error!!");
}
elsif (not -r $file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0022", variables => { file => $file }});
return("!!error!!");
}
# If I've read this before, don't read it again.
if ((exists $anvil->data->{cache}{file}{$file}) && (not $force_read))
{
# Use the cache
$body = $anvil->data->{cache}{file}{$file};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { body => $body }});
}
else
{
# Read from storage.
my $shell_call = $file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0012", variables => { shell_call => $shell_call }});
open (my $file_handle, "<", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0015", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
{
### NOTE: Don't chop this, we want to record exactly what we read
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0023", variables => { line => $line }});
$body .= $line;
}
close $file_handle;
if ($cache)
{
$anvil->data->{cache}{file}{$file} = $body;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "cache::file::${file}" => $anvil->data->{cache}{file}{$file} }});
}
}
}
else
{
# Remote. Make sure the passed file is a full path and file name.
if ($file !~ /^\/\w/)
@ -1652,49 +1780,6 @@ sub read_file
}
}
}
else
{
# Local
if (not -e $file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0021", variables => { file => $file }});
return("!!error!!");
}
elsif (not -r $file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0022", variables => { file => $file }});
return("!!error!!");
}
# If I've read this before, don't read it again.
if ((exists $anvil->data->{cache}{file}{$file}) && (not $force_read))
{
# Use the cache
$body = $anvil->data->{cache}{file}{$file};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { body => $body }});
}
else
{
# Read from storage.
my $shell_call = $file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0012", variables => { shell_call => $shell_call }});
open (my $file_handle, "<", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0015", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
{
### NOTE: Don't chop this, we want to record exactly what we read
my $line = $_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0023", variables => { line => $line }});
$body .= $line;
}
close $file_handle;
if ($cache)
{
$anvil->data->{cache}{file}{$file} = $body;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "cache::file::${file}" => $anvil->data->{cache}{file}{$file} }});
}
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { body => $body }});
return($body);
@ -1920,7 +2005,7 @@ sub rsync
# If local, call rsync directly. If remote, setup the rsync wrapper
my $wrapper_script = "";
my $shell_call = $anvil->data->{path}{exe}{rsync}." ".$switches." ".$source." ".$destination;
if ($anvil->Network->is_remote($target))
if (not $anvil->Network->is_local({host => $target}))
{
# If we didn't get a port, but the target is pre-configured for a port, use it.
if ((not $parameter->{port}) && ($anvil->data->{hosts}{$target}{port}))
@ -2421,20 +2506,20 @@ sub update_config
# Did we see the variable?
if (not $seen)
{
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0175", variables => {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0174", variables => {
variable => $variable,
file => $anvil->data->{path}{configs}{'anvil.conf'},
target => $target,
}});
return(1);
}
else
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0174", variables => {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0175", variables => {
variable => $variable,
file => $anvil->data->{path}{configs}{'anvil.conf'},
target => $target,
}});
return(1);
}
@ -2765,7 +2850,78 @@ sub write_file
}});
# Now, are we writing locally or on a remote system?
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local
if (-e $file)
{
if (not $overwrite)
{
# Nope.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0040", variables => { file => $file }});
$error = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
}
if ($backup)
{
# Back it up.
my $backup_file = $anvil->Storage->backup({
debug => $debug,
file => $file,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { backup_file => $backup_file }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
if (not $error)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { directory => $directory }});
if (not -e $directory)
{
# Don't pass the mode as the file's mode is likely not executable.
$anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
group => $group,
user => $user,
});
}
# If 'secure' is set, the file will probably contain sensitive data so touch the file and set
# the mode before writing it.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { secure => $secure }});
if ($secure)
{
$anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{touch}." ".$file});
$anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode});
}
# Now write the file.
my $shell_call = $file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, key => "log_0013", variables => { shell_call => $shell_call }});
open (my $file_handle, ">", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0016", variables => { shell_call => $shell_call, error => $! }});
#open (my $file_handle, ">", $shell_call) or die "Failed to write: [$shell_call], error was: [".$!."]\n";;
print $file_handle $body;
close $file_handle;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { mode => $mode }});
if ($mode)
{
$anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
user => $user,
group => $group,
}});
if (($user) or ($group))
{
$anvil->Storage->change_owner({debug => $debug, path => $file, user => $user, group => $group});
}
}
}
else
{
# If we didn't get a port, but the target is pre-configured for a port, use it.
if ((not $parameter->{port}) && ($anvil->data->{hosts}{$target}{port}))
@ -2909,77 +3065,6 @@ fi";
}
}
}
else
{
# Local
if (-e $file)
{
if (not $overwrite)
{
# Nope.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0040", variables => { file => $file }});
$error = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
}
if ($backup)
{
# Back it up.
my $backup_file = $anvil->Storage->backup({
debug => $debug,
file => $file,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { backup_file => $backup_file }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
if (not $error)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { directory => $directory }});
if (not -e $directory)
{
# Don't pass the mode as the file's mode is likely not executable.
$anvil->Storage->make_directory({
debug => $debug,
directory => $directory,
group => $group,
user => $user,
});
}
# If 'secure' is set, the file will probably contain sensitive data so touch the file and set
# the mode before writing it.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { secure => $secure }});
if ($secure)
{
$anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{touch}." ".$file});
$anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode});
}
# Now write the file.
my $shell_call = $file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, key => "log_0013", variables => { shell_call => $shell_call }});
open (my $file_handle, ">", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0016", variables => { shell_call => $shell_call, error => $! }});
#open (my $file_handle, ">", $shell_call) or die "Failed to write: [$shell_call], error was: [".$!."]\n";;
print $file_handle $body;
close $file_handle;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { mode => $mode }});
if ($mode)
{
$anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
user => $user,
group => $group,
}});
if (($user) or ($group))
{
$anvil->Storage->change_owner({debug => $debug, path => $file, user => $user, group => $group});
}
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
return($error);

@ -1263,8 +1263,18 @@ sub host_name
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call
($output, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
@ -1278,14 +1288,6 @@ sub host_name
output => $output,
}});
}
else
{
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
}
# Pretty
@ -1298,8 +1300,18 @@ sub host_name
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
else
{
# Remote call
($output, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
@ -1313,14 +1325,6 @@ sub host_name
output => $output,
}});
}
else
{
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
}
# Get the static (traditional) host name
@ -1331,8 +1335,18 @@ sub host_name
my $descriptive = "";
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call
($host_name, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,
return_code => $return_code,
}});
}
else
{
# Remote call
($host_name, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
@ -1346,14 +1360,6 @@ sub host_name
output => $output,
}});
}
else
{
($host_name, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,
return_code => $return_code,
}});
}
# Get the pretty (descriptive) host name
$shell_call = $anvil->data->{path}{exe}{hostnamectl}." --pretty";
@ -1361,8 +1367,18 @@ sub host_name
$output = "";
$return_code = "";
if ($anvil->Network->is_remote($target))
if ($anvil->Network->is_local({host => $target}))
{
# Local call
($descriptive, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
descriptive => $descriptive,
return_code => $return_code,
}});
}
else
{
# Remove call
($descriptive, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
@ -1376,14 +1392,6 @@ sub host_name
output => $output,
}});
}
else
{
($descriptive, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
descriptive => $descriptive,
return_code => $return_code,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,

@ -696,7 +696,7 @@ sub process_anvil_menu
}
elsif ($anvil->data->{cgi}{task}{value} eq "configure-network")
{
#process_configure_network($anvil);
process_configure_network($anvil);
}
elsif ($anvil->data->{cgi}{task}{value} eq "manifest")
{
@ -713,6 +713,25 @@ sub process_anvil_menu
return(0);
}
# This handles configuring a remote target's network interfaces (renaming them, bonding and bridging them).
sub process_configure_network
{
my ($anvil) = @_;
my $host_name = defined $anvil->data->{cgi}{host_name}{value} ? $anvil->data->{cgi}{host_name}{value} : "";
my $host_ip_address = defined $anvil->data->{cgi}{host_ip_address}{value} ? $anvil->data->{cgi}{host_ip_address}{value} : "";
my $host_password = defined $anvil->data->{cgi}{host_password}{value} ? $anvil->data->{cgi}{host_password}{value} : "";
my $confirm = defined $anvil->data->{cgi}{confirm}{value} ? $anvil->data->{cgi}{confirm}{value} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_name => $host_name,
host_ip_address => $host_ip_address,
host_password => $anvil->Log->is_secure($host_password),
confirm => $confirm,
}});
return(0);
}
# This handles installing our repo, installing the appropriate 'anvil-X' rpm, running OS updates if selected
# and configuring the network on a machine destined to be an Anvil! node or DR host.
sub process_prep_host_page

@ -1085,7 +1085,7 @@ sub prep_database
if ($host_type eq "dashboard")
{
my ($database_output, $return_code) = $anvil->System->call({
debug => 3,
debug => 2,
shell_call => $anvil->data->{path}{exe}{'striker-prep-database'},
source => $THIS_FILE,
line => __LINE__,

Loading…
Cancel
Save