mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-22 11:42:05 +00:00
Modify startup configuration for goconserver and conserver
After running makegocons, startup configuration would be changed to make sure goconserver could start after rebooting. Changes are made in makeconservercf too.
This commit is contained in:
parent
8dc18c3989
commit
cc588f4af1
@ -559,16 +559,17 @@ sub message
|
||||
|
||||
Example:
|
||||
|
||||
$rsp->{data}->[0] = "message";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message($msg, $callback);
|
||||
=cut
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sub error_message
|
||||
{
|
||||
shift;
|
||||
my $rsp = shift;
|
||||
my $msg = shift;
|
||||
my $callback = shift;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = $msg;
|
||||
if (!defined($callback)) {
|
||||
message(undef, "S", $rsp, undef);
|
||||
return;
|
||||
@ -591,16 +592,17 @@ sub error_message
|
||||
|
||||
Example:
|
||||
|
||||
$rsp->{data}->[0] = "message";
|
||||
xCAT::MsgUtils->info_message($rsp, $callback);
|
||||
xCAT::MsgUtils->info_message($msg, $callback);
|
||||
=cut
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sub info_message
|
||||
{
|
||||
shift;
|
||||
my $rsp = shift;
|
||||
my $msg = shift;
|
||||
my $callback = shift;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = $msg;
|
||||
if (!defined($callback)) {
|
||||
message(undef, "S", $rsp, undef);
|
||||
return;
|
||||
@ -613,7 +615,38 @@ sub info_message
|
||||
message(undef, "I", $rsp, $callback);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
=head3 warn_message
|
||||
|
||||
A wrap function for message. If $callback is not defined, send the log to
|
||||
syslog, otherwise, send warning message to client. Print service host if runs
|
||||
on service node.
|
||||
|
||||
Example:
|
||||
|
||||
xCAT::MsgUtils->warn_message($msg, $callback);
|
||||
=cut
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sub warn_message
|
||||
{
|
||||
shift;
|
||||
my $msg = shift;
|
||||
my $callback = shift;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = $msg;
|
||||
if (!defined($callback)) {
|
||||
message(undef, "S", $rsp, undef);
|
||||
return;
|
||||
}
|
||||
if ($isSN && !$host) {
|
||||
my @hostinfo = xCAT::NetworkUtils->determinehostname();
|
||||
$host = $hostinfo[-1];
|
||||
}
|
||||
$rsp->{host} = $host if $host;
|
||||
message(undef, "W", $rsp, $callback);
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -104,8 +104,7 @@ sub gen_request_data {
|
||||
foreach my $node (@openbmc_nodes) {
|
||||
if (defined($openbmc_hash->{$node}->[0])) {
|
||||
if (!$openbmc_hash->{$node}->[0]->{'bmc'}) {
|
||||
$rsp->{data}->[0] = "$node: Failed to send delete request.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("$node: Unable to get attribute bmc.", $callback);
|
||||
delete $data->{$node};
|
||||
next;
|
||||
}
|
||||
@ -115,8 +114,7 @@ sub gen_request_data {
|
||||
} elsif ($passwd_hash and $passwd_hash->{username}) {
|
||||
$data->{$node}->{params}->{user} = $passwd_hash->{username};
|
||||
} else {
|
||||
$rsp->{data}->[0] = "$node: Unable to get attribute username.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("$node: Unable to get attribute username.", $callback);
|
||||
delete $data->{$node};
|
||||
next;
|
||||
}
|
||||
@ -125,8 +123,7 @@ sub gen_request_data {
|
||||
} elsif ($passwd_hash and $passwd_hash->{password}) {
|
||||
$data->{$node}->{params}->{password} = $passwd_hash->{password};
|
||||
} else {
|
||||
$rsp->{data}->[0] = "$node: Unable to get attribute password.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("$node: Unable to get attribute password.", $callback);
|
||||
delete $data->{$node};
|
||||
next;
|
||||
}
|
||||
@ -259,14 +256,12 @@ sub delete_nodes {
|
||||
$ret = 0;
|
||||
my $response = http_request("DELETE", $url, $data);
|
||||
if (!defined($response)) {
|
||||
$rsp->{data}->[0] = "Failed to send delete request.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to send delete request.", $callback);
|
||||
return 1;
|
||||
} elsif ($delmode) {
|
||||
while (my ($k, $v) = each %{$response}) {
|
||||
if ($v ne "Deleted") {
|
||||
$rsp->{data}->[0] = "$k: Failed to delete entry in goconserver: $v";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("$k: Failed to delete entry in goconserver: $v", $callback);
|
||||
$ret = 1;
|
||||
} else {
|
||||
if ($callback) {
|
||||
@ -279,8 +274,7 @@ sub delete_nodes {
|
||||
}
|
||||
if (@update_nodes) {
|
||||
if (disable_nodes_in_db(\@update_nodes)) {
|
||||
$rsp->{data}->[0] = "Failed to update consoleenabled status in db.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to update consoleenabled status in db.", $callback);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -297,14 +291,12 @@ sub create_nodes {
|
||||
$ret = 0;
|
||||
my $response = http_request("POST", $url, $data);
|
||||
if (!defined($response)) {
|
||||
$rsp->{data}->[0] = "Failed to send create request.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to send create request.", $callback);
|
||||
return 1;
|
||||
} elsif ($response) {
|
||||
while (my ($k, $v) = each %{$response}) {
|
||||
if ($v ne "Created") {
|
||||
$rsp->{data}->[0] = "$k: Failed to create console entry in goconserver: $v";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("$k: Failed to create console entry in goconserver: $v", $callback);
|
||||
$ret = 1;
|
||||
} else {
|
||||
$rsp->{data}->[0] = "$k: $v";
|
||||
@ -315,8 +307,7 @@ sub create_nodes {
|
||||
}
|
||||
if (@update_nodes) {
|
||||
if (enable_nodes_in_db(\@update_nodes)) {
|
||||
$rsp->{data}->[0] = "Failed to update consoleenabled status in db.";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to update consoleenabled status in db.", $callback);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -328,13 +319,11 @@ sub list_nodes {
|
||||
my $rsp;
|
||||
my $response = http_request("GET", $url);
|
||||
if (!defined($response)) {
|
||||
$rsp->{data}->[0] = "Failed to send list request. Is goconserver service started?";
|
||||
xCAT::MsgUtils->error_message($rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to send list request. Is goconserver service started?", $callback);
|
||||
return 1;
|
||||
}
|
||||
if (!$response->{nodes}) {
|
||||
$rsp->{data}->[0] = "Could not find any node.";
|
||||
xCAT::MsgUtils->info_message($rsp, $callback);
|
||||
xCAT::MsgUtils->info_message("Could not find any node.", $callback);
|
||||
return 0;
|
||||
}
|
||||
$rsp->{data}->[0] = sprintf("\n".PRINT_FORMAT, "NODE", "SERVER", "STATE");
|
||||
@ -345,8 +334,7 @@ sub list_nodes {
|
||||
}
|
||||
$node_map->{$node->{name}}->{vis} = 1;
|
||||
if (!$node->{host} || !$node->{state}) {
|
||||
$rsp->{data}->[0] = sprintf(PRINT_FORMAT, $node->{name}, "", "Unable to parse the response message");
|
||||
xCAT::MsgUtils->error_message("E", $rsp, $callback);
|
||||
xCAT::MsgUtils->error_message(sprintf(PRINT_FORMAT, $node->{name}, "", "Unable to parse the response message"), $callback);
|
||||
next;
|
||||
}
|
||||
$rsp->{data}->[0] = sprintf(PRINT_FORMAT, $node->{name}, $node->{host}, substr($node->{state}, 0, 16));
|
||||
@ -370,8 +358,7 @@ sub cleanup_nodes {
|
||||
my $rsp;
|
||||
my $response = http_request("GET", "$api_url/nodes");
|
||||
if (!defined($response)) {
|
||||
$rsp->{data}->[0] = "Failed to send list request. Is goconserver service started?";
|
||||
xCAT::MsgUtils->error_message("E", $rsp, $callback);
|
||||
xCAT::MsgUtils->error_message("Failed to send list request. Is goconserver service started?", $callback);
|
||||
return 1;
|
||||
}
|
||||
if (!$response->{nodes}) {
|
||||
@ -491,6 +478,70 @@ sub is_goconserver_running {
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 switch_goconserver
|
||||
Disable conserver and enable goconserver during startup.
|
||||
|
||||
Globals:
|
||||
none
|
||||
Example:
|
||||
xCAT::Goconserver::switch_goconserver()
|
||||
Comments:
|
||||
none
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub switch_goconserver {
|
||||
my $callback = shift;
|
||||
# ignore SN as it is handled by AAsn
|
||||
if ((-x "/usr/bin/systemctl" || -x "-x /bin/systemctl") && !$isSN) {
|
||||
my $cmd = "systemctl disable conserver";
|
||||
xCAT::Utils->runcmd($cmd, -1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->warn_message("Failed to execute command: $cmd.", $callback);
|
||||
}
|
||||
$cmd = "systemctl enable goconserver";
|
||||
xCAT::Utils->runcmd($cmd, -1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->warn_message("Failed to execute command: $cmd.", $callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 switch_conserver
|
||||
Disable goconserver and enable conserver during startup.
|
||||
|
||||
Globals:
|
||||
none
|
||||
Example:
|
||||
xCAT::Goconserver::switch_conserver()
|
||||
Comments:
|
||||
none
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub switch_conserver {
|
||||
my $callback = shift;
|
||||
# ignore SN as it is handled by AAsn
|
||||
if ((-x "/usr/bin/systemctl" || -x "-x /bin/systemctl") && !$isSN) {
|
||||
my $cmd = "systemctl disable goconserver";
|
||||
xCAT::Utils->runcmd($cmd, -1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->warn_message("Failed to execute command: $cmd.", $callback);
|
||||
}
|
||||
$cmd = "systemctl enable conserver";
|
||||
xCAT::Utils->runcmd($cmd, -1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->warn_message("Failed to execute command: $cmd.", $callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 is_conserver_running
|
||||
Check if the conserver service is running
|
||||
|
||||
|
@ -209,6 +209,7 @@ sub process_request {
|
||||
xCAT::MsgUtils->message("E", $rsp, $cb);
|
||||
return;
|
||||
}
|
||||
xCAT::Goconserver::switch_conserver($cb);
|
||||
}
|
||||
makeconservercf($req, $cb);
|
||||
}
|
||||
|
@ -142,16 +142,15 @@ sub process_request {
|
||||
sub start_goconserver {
|
||||
my ($rsp, $running, $ready, $ret);
|
||||
unless (-x "/usr/bin/goconserver") {
|
||||
$rsp->{data}->[0] = "goconserver is not installed.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("goconserver is not installed.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
# if goconserver is installed, check the status of conserver service.
|
||||
if (xCAT::Goconserver::is_conserver_running()) {
|
||||
$rsp->{data}->[0] = "conserver is started, please stop it at first.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("conserver is started, please stop it at first.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
xCAT::Goconserver::switch_goconserver($::callback);
|
||||
$running = xCAT::Goconserver::is_goconserver_running();
|
||||
$ready = xCAT::Goconserver::is_xcat_conf_ready();
|
||||
if ( $running && $ready ) {
|
||||
@ -163,19 +162,16 @@ sub start_goconserver {
|
||||
if (!$ready) {
|
||||
$ret = xCAT::Goconserver::build_conf();
|
||||
if ($ret) {
|
||||
$rsp->{data}->[0] = "Failed to create configuration file for goconserver.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Failed to create configuration file for goconserver.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
$ret = xCAT::Goconserver::restart_service();
|
||||
if ($ret) {
|
||||
$rsp->{data}->[0] = "Failed to start goconserver service.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Failed to start goconserver service.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
$rsp->{data}->[0] = "Starting goconserver service ...";
|
||||
xCAT::MsgUtils->info_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->info_message("Starting goconserver service ...", $::callback);
|
||||
sleep(3);
|
||||
return 0;
|
||||
}
|
||||
@ -203,16 +199,14 @@ sub makegocons {
|
||||
}
|
||||
if ($cleanupmode) {
|
||||
if (exists($req->{_allnodes}) && $req->{_allnodes}->[0] != 1) {
|
||||
$rsp->{data}->[0] = "Failed to start goconserver service.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Can not specify noderange together with -C|--cleanup.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
return xCAT::Goconserver::cleanup_nodes($::callback);
|
||||
}
|
||||
my %cons_map = xCAT::Goconserver::get_cons_map($req);
|
||||
if (! %cons_map) {
|
||||
$rsp->{data}->[0] = "Could not get any console request entry.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Could not get any console request entry.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
my $api_url = "https://$host:". xCAT::Goconserver::get_api_port();
|
||||
@ -233,15 +227,13 @@ sub makegocons {
|
||||
}
|
||||
elsif (lc($site_entry) ne "no") {
|
||||
# consoleondemand attribute is set, but it is not "yes" or "no"
|
||||
$rsp->{data}->[0] = "Unexpected value $site_entry for consoleondemand attribute in site table.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Unexpected value $site_entry for consoleondemand attribute in site table.", $::callback);
|
||||
}
|
||||
}
|
||||
my (@nodes);
|
||||
my $data = xCAT::Goconserver::gen_request_data(\%cons_map, $siteondemand, $::callback);
|
||||
if (! $data) {
|
||||
$rsp->{data}->[0] = "Could not generate the request data.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Could not generate the request data.", $::callback);
|
||||
return 1;
|
||||
}
|
||||
$ret = xCAT::Goconserver::delete_nodes($api_url, $data, $delmode, $::callback);
|
||||
@ -250,8 +242,7 @@ sub makegocons {
|
||||
}
|
||||
$ret = xCAT::Goconserver::create_nodes($api_url, $data, $::callback);
|
||||
if ($ret != 0) {
|
||||
$rsp->{data}->[0] = "Failed to create console entry in goconserver.";
|
||||
xCAT::MsgUtils->error_message($rsp, $::callback);
|
||||
xCAT::MsgUtils->error_message("Failed to create console entry in goconserver.", $::callback);
|
||||
return $ret;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user