* Updated fence_delay to set the ownership of the log file to 'hacluster:haclient'. This should address https://github.com/digimer/fence_delay/issues/1

* WIP - COntinuing work on anvil-manage-server, far from done yet.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent bc8b9274cb
commit 8d2e454d69
  1. 4
      notes
  2. 1
      share/words.xml
  3. 111
      tools/anvil-manage-server
  4. 47
      tools/fence_delay

@ -1398,3 +1398,7 @@ totem.transport (str) = knet
==================================== ====================================
Gi1/0/24 + Gi2/0/24

@ -1120,6 +1120,7 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0352">Manage a server menu:</key> <key name="job_0352">Manage a server menu:</key>
<key name="job_0353">* Please enter the name of the server you want to manage</key> <key name="job_0353">* Please enter the name of the server you want to manage</key>
<key name="job_0354">-=] Servers available to manage on the Anvil! [#!variable!anvil_name!#] [=-</key> <key name="job_0354">-=] Servers available to manage on the Anvil! [#!variable!anvil_name!#] [=-</key>
<key name="job_0355">-=] Managing the server: [#!variable!server_name!#] on the Anvil!: [#!variable!anvil_name!#]</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -469,14 +469,26 @@ sub interactive_question
host => $short_host_name, host => $short_host_name,
}); });
$anvil->data->{target_server}{server_cpu_sockets} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{sockets} if not defined $anvil->data->{target_server}{server_cpu_sockets}; # If only VCPU is set, cores and threads will both be '1' but 'total' will be higher.
$anvil->data->{target_server}{server_cpu_cores} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{threads} if not defined $anvil->data->{target_server}{server_cpu_cores}; # Windows (and others?) interprets this as X number of single core sockets.
$anvil->data->{target_server}{server_cpu_total} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{total_cores} if not defined $anvil->data->{target_server}{server_cpu_total};
$anvil->data->{target_server}{server_cpu_sockets} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{sockets} if not defined $anvil->data->{target_server}{server_cpu_sockets};
$anvil->data->{target_server}{server_cpu_cores} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{threads} if not defined $anvil->data->{target_server}{server_cpu_cores};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:target_server::server_cpu_sockets' => $anvil->data->{target_server}{server_cpu_sockets}, 's1:target_server::server_cpu_sockets' => $anvil->data->{target_server}{server_cpu_sockets},
's2:target_server::server_cpu_cores' => $anvil->data->{target_server}{server_cpu_cores}, 's2:target_server::server_cpu_cores' => $anvil->data->{target_server}{server_cpu_cores},
's3:target_server::server_cpu_total' => $anvil->data->{target_server}{server_cpu_total},
}}); }});
# server::an-a02n01::srv02-c8s-fujitsu:: from_db::device::disk::target::vda if (($anvil->data->{target_server}{server_cpu_sockets} == 1) && ($anvil->data->{target_server}{server_cpu_cores} == 1) && ($anvil->data->{target_server}{server_cpu_total} > 1))
{
$anvil->data->{target_server}{server_cpu_sockets} = $anvil->data->{target_server}{server_cpu_total};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:target_server::server_cpu_sockets' => $anvil->data->{target_server}{server_cpu_sockets},
}});
}
# Pull out the existing disks.
foreach my $target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}}) foreach my $target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { target => $target }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { target => $target }});
@ -626,17 +638,13 @@ sub interactive_configure_main
{ {
my ($anvil, $terminal) = @_; my ($anvil, $terminal) = @_;
my $selection = 0;
my $retry = 0;
while(1) while(1)
{ {
my $default = "";
print $terminal->Tputs('cl'); print $terminal->Tputs('cl');
print $anvil->Words->string({key => "job_0352"})."\n"; print $anvil->Words->string({key => "job_0355", variables => {
print $anvil->Words->string({key => "job_0151", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n"; anvil_name => $anvil->data->{target_server}{anvil_name},
print $anvil->Words->string({key => "job_0157", variables => { server_name => $anvil->data->{target_server}{server_name} }})."\n"; server_name => $anvil->data->{target_server}{server_name},
print "\n"; }})."\n";
print "[ 1 ] - CPU\n"; print "[ 1 ] - CPU\n";
print "[ 2 ] - RAM\n"; print "[ 2 ] - RAM\n";
print "[ 3 ] - Storage\n"; print "[ 3 ] - Storage\n";
@ -646,15 +654,14 @@ sub interactive_configure_main
print "[ B ] - Back\n"; print "[ B ] - Back\n";
print "[ Q ] - Quit\n"; print "[ Q ] - Quit\n";
print "\n"; print "\n";
print $terminal->Tgoto('cm', 0, 13)."? "; print $terminal->Tgoto('cm', 0, 9)."? ";
my $answer = <STDIN>; my $answer = <STDIN>;
chomp $answer; chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if ($answer eq "1") if ($answer eq "1")
{ {
print "Going to CPU menu\n"; interactive_configure_cpu($anvil, $terminal)
sleep 1;
} }
elsif ($answer eq "2") elsif ($answer eq "2")
{ {
@ -681,12 +688,11 @@ sub interactive_configure_main
$anvil->data->{target_server}{server_name} = ""; $anvil->data->{target_server}{server_name} = "";
$anvil->data->{target_server}{server_uuid} = ""; $anvil->data->{target_server}{server_uuid} = "";
$anvil->data->{switches}{server} = ""; $anvil->data->{switches}{server} = "";
print "Going back\n";
interactive_ask_server_name($anvil, $terminal); interactive_ask_server_name($anvil, $terminal);
} }
elsif (lc($answer) eq "q") elsif (lc($answer) eq "q")
{ {
print "Good bye.\n"; print "NO CARRIER, good bye.\n";
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
} }
else else
@ -734,6 +740,75 @@ sub interactive_configure_main
return(0); return(0);
} }
sub interactive_configure_cpu
{
my ($anvil, $terminal) = @_;
while(1)
{
my $anvil_uuid = $anvil->data->{target_server}{anvil_uuid};
my $maximum = $anvil->data->{anvil_resources}{$anvil_uuid}{cpu}{cores} * $anvil->data->{anvil_resources}{$anvil_uuid}{cpu}{threads};
my $current_cores = $anvil->data->{target_server}{server_cpu_cores};
if (not exists $anvil->data->{new_config}{cpu}{sockets})
{
$anvil->data->{new_config}{cpu}{sockets} = "";
}
if (not exists $anvil->data->{new_config}{cpu}{cores})
{
$anvil->data->{new_config}{cpu}{cores} = "";
}
my $star_cores = " ";
if (($anvil->data->{new_config}{cpu}{cores}) && ($anvil->data->{new_config}{cpu}{cores} ne $anvil->data->{target_server}{server_cpu_cores}))
{
$star_cores = "*";
}
my $star_sockets = " ";
if (($anvil->data->{new_config}{cpu}{sockets}) && ($anvil->data->{new_config}{cpu}{sockets} ne $anvil->data->{target_server}{server_cpu_sockets}))
{
$star_sockets = "*";
}
print $terminal->Tputs('cl');
print $anvil->Words->string({key => "job_0355", variables => {
anvil_name => $anvil->data->{target_server}{anvil_name},
server_name => $anvil->data->{target_server}{server_name},
}})."\n";
print "* CPU configuration. Maximum cores X sockets is: [".$maximum."]\n";
print "[ 1 ] - Cores per socket".$star_cores." (currently: [".$anvil->data->{target_server}{server_cpu_cores}."], new: [".$anvil->data->{new_config}{cpu}{cores}."])\n";
print "[ 2 ] - Sockets".$star_sockets." (currently: [".$anvil->data->{target_server}{server_cpu_sockets}."], new: [".$anvil->data->{new_config}{cpu}{sockets}."])\n";
print "\n";
print "[ B ] - Back\n";
print "[ Q ] - Quit\n";
print $terminal->Tgoto('cm', 0, 7)."? ";
my $answer = <STDIN>;
chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if ($answer eq "1")
{
print "How many cores per socket would you like? ";
}
elsif ($answer eq "2")
{
}
elsif (lc($answer) eq "b")
{
}
elsif (lc($answer) eq "q")
{
}
else
{
}
}
return(0);
}
sub interactive_ask_anvil_name sub interactive_ask_anvil_name
{ {
my ($anvil, $terminal) = @_; my ($anvil, $terminal) = @_;
@ -841,7 +916,7 @@ sub interactive_ask_anvil_name
} }
elsif (lc($answer) eq "q") elsif (lc($answer) eq "q")
{ {
print "Good bye.\n"; print "NO CARRIER, good bye.\n";
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
} }
else else
@ -982,7 +1057,7 @@ sub interactive_ask_server_name
} }
elsif (lc($answer) eq "q") elsif (lc($answer) eq "q")
{ {
print "Good bye.\n"; print "NO CARRIER, good bye.\n";
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
} }
else else

@ -37,6 +37,7 @@ my $conf = {
'system' => { 'system' => {
action => "off", action => "off",
agent_version => "1.0", agent_version => "1.0",
do_chown => 0,
log_level => 1, log_level => 1,
'wait' => 60, 'wait' => 60,
device => "", device => "",
@ -54,8 +55,14 @@ my $conf = {
}; };
# Log file for output. # Log file for output.
if (not -e $conf->{'system'}{'log'})
{
# We'll chown the log.
$conf->{'system'}{do_chown} = 1;
}
my $log = IO::Handle->new(); my $log = IO::Handle->new();
open ($log, ">>".$conf->{'system'}{'log'}) || warn "Failed to open: [".$conf->{'system'}{'log'}."] for writing; Error: $!\n"; open ($log, ">>".$conf->{'system'}{'log'}) || die "Failed to open: [".$conf->{'system'}{'log'}."] for writing; Error: $!\n";
# Set $log and STDOUT to hot (unbuffered) output. # Set $log and STDOUT to hot (unbuffered) output.
if (1) if (1)
{ {
@ -74,7 +81,7 @@ read_cla($conf, $log);
read_stdin($conf, $log); read_stdin($conf, $log);
# If I've been asked to show the metadata XML, do so and then exit. # If I've been asked to show the metadata XML, do so and then exit.
if (($conf->{'system'}{action} eq "metadata") or ($conf->{'system'}{action} eq "meta-data")) if ($conf->{'system'}{action} eq "metadata")
{ {
metadata($conf, $log); metadata($conf, $log);
do_exit($conf, $log, 0); do_exit($conf, $log, 0);
@ -116,6 +123,16 @@ sub do_exit
# Close the log file handle, if it exists. # Close the log file handle, if it exists.
$log->close() if $log; $log->close() if $log;
record($conf, $log, "system::do_chown: [".$conf->{'system'}{do_chown}."].\n", 2);
if ($conf->{'system'}{do_chown})
{
record($conf, $log, "Changing ownership of: [".$conf->{'system'}{do_chown}."] to [hacluster:haclient].\n", 1);
my $uid = getpwnam('hacluster');
my $gid = getgrnam('haclient');
record($conf, $log, "chown'ing: [".$conf->{'system'}{do_chown}."].\n", 2);
chown $uid, $gid, $conf->{'system'}{'log'};
}
exit ($exit_status); exit ($exit_status);
} }
@ -274,36 +291,36 @@ sub read_cla
{ {
# Print the version information and then exit. # Print the version information and then exit.
$conf->{'system'}{version} = 1; $conf->{'system'}{version} = 1;
record($conf, $log, "[ Debug ] - 'system::version': . [".$conf->{'system'}{version}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::version': [".$conf->{'system'}{version}."]\n", 2);
} }
elsif (($arg eq "-q") or ($arg eq "--quiet")) elsif (($arg eq "-q") or ($arg eq "--quiet"))
{ {
# Suppress all messages, including critical messages, from STDOUT. # Suppress all messages, including critical messages, from STDOUT.
$conf->{'system'}{log_level} = 0; $conf->{'system'}{log_level} = 0;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{quiet}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{quiet}."]\n", 2);
} }
elsif ($arg eq "--debug") elsif ($arg eq "--debug")
{ {
# Enable debug mode. # Enable debug mode.
$conf->{'system'}{log_level} = 2; $conf->{'system'}{log_level} = 2;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2);
} }
elsif (($arg eq "-w") or ($arg eq "--wait")) elsif (($arg eq "-w") or ($arg eq "--wait"))
{ {
# How long to wait before exiting. # How long to wait before exiting.
$set_next = "wait"; $set_next = "wait";
record($conf, $log, "[ Debug ] - 'set_next': ........ [".$set_next."]\n", 1); record($conf, $log, "[ Debug ] - 'set_next': [".$set_next."]\n", 2);
} }
elsif (($arg eq "-o") or ($arg eq "--action")) elsif (($arg eq "-o") or ($arg eq "--action"))
{ {
# This is the action to take. # This is the action to take.
$set_next = "action"; $set_next = "action";
record($conf, $log, "[ Debug ] - 'set_next': ........ [".$set_next."]\n", 1); record($conf, $log, "[ Debug ] - 'set_next': [".$set_next."]\n", 2);
} }
else else
{ {
# Bad argument. # Bad argument.
record($conf, $log, "[ Warning ] - Argument: [".$arg."] is not valid arguments.\n", 1); record($conf, $log, "[ Warning ] - Argument: [".$arg."] is not valid arguments.\n", 2);
} }
} }
@ -344,7 +361,7 @@ sub read_stdin
my ($name, $value) = split /\s*=\s*/, $option; my ($name, $value) = split /\s*=\s*/, $option;
# Record the line for now, but comment this out before release. # Record the line for now, but comment this out before release.
record ($conf, $log, "Name: [$name], value: [$value].\n", 2); record ($conf, $log, "Name: [$name], value: [$value].\n");
# Set my variables depending on the veriable name. # Set my variables depending on the veriable name.
if ($name eq "agent") if ($name eq "agent")
@ -352,27 +369,27 @@ sub read_stdin
# This is only used by 'fenced', but I record it for # This is only used by 'fenced', but I record it for
# potential debugging. # potential debugging.
$conf->{'system'}{agent} = $value; $conf->{'system'}{agent} = $value;
record($conf, $log, "[ Debug ] - 'system::agent': ... [".$conf->{'system'}{agent}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::agent': [".$conf->{'system'}{agent}."]\n", 2);
} }
elsif ($name eq "action") elsif ($name eq "action")
{ {
$conf->{'system'}{action} = $value; $conf->{'system'}{action} = $value;
record($conf, $log, "[ Debug ] - 'system::action': .. [".$conf->{'system'}{action}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::action': [".$conf->{'system'}{action}."]\n", 2);
} }
elsif ($name eq "quiet") elsif ($name eq "quiet")
{ {
$conf->{'system'}{log_level} = 0; $conf->{'system'}{log_level} = 0;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2);
} }
elsif ($name eq "debug") elsif ($name eq "debug")
{ {
$conf->{'system'}{log_level} = 2; $conf->{'system'}{log_level} = 2;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2);
} }
elsif ($name eq "wait") elsif ($name eq "wait")
{ {
$conf->{'system'}{wait} = $value; $conf->{'system'}{wait} = $value;
record($conf, $log, "[ Debug ] - 'system::wait': .... [".$conf->{'system'}{'wait'}."]\n", 1); record($conf, $log, "[ Debug ] - 'system::wait': [".$conf->{'system'}{wait}."]\n", 2);
} }
else else
{ {
@ -392,7 +409,7 @@ sub record
return if $level > $conf->{'system'}{log_level}; return if $level > $conf->{'system'}{log_level};
# Print to the log # Print to the log
print $log get_date_time($conf)." - ".$msg; print $log $msg;
# Print to the screen if we're not 'quiet'. # Print to the screen if we're not 'quiet'.
print $msg if not $conf->{'system'}{quiet}; print $msg if not $conf->{'system'}{quiet};

Loading…
Cancel
Save