Permalink
Browse files

Actual code for multi-boot

  • Loading branch information...
edolnx committed Jun 3, 2012
1 parent 1e81f2f commit 6ac9d5223f5a6b399be2915f69fcc96d04a05b28
Showing with 19 additions and 6 deletions.
  1. +19 −6 nephology-server.pl
View
@@ -20,7 +20,7 @@
}
Mojo::IOLoop->recurring( 60 => sub {
- my $sth = $dbh->prepare("SELECT 1 WHERE 1=1");
+ my $sth = $dbh->prepare("SELECT 1");
$sth->execute or die "Database went away, try again"
});
@@ -52,13 +52,26 @@ sub gensalt {
else {
my $db_node_info = $dbh->selectrow_hashref("SELECT * FROM node WHERE boot_mac='$machine'");
if (!defined($db_node_info)) {
+ # If the node does not exist, go into bootstrap mode
$self->render(template => "boot/bootstrap.ipxe", format => 'txt');
}
- elsif ($db_node_info->{'status_id'} == 1000) {
- $self->render(template => "boot/localboot.ipxe", format => 'txt');
- }
else {
- $self->render(template => "boot/bootstrap.ipxe", format => 'txt');
+ # Since the node exists, check it's status for for what action to perform
+ my $db_node_status_info = $dbh->selectrow_hashref("SELECT * FROM node_status WHERE status_id=" . $db_node_info->{'status_id'});
+ if (defined($db_node_status_info)) {
+ # If a status is defined, use it's information
+ if (defined($db_node_status_info->{'next_status'})) {
+ # Change node status
+ my $sth = $dbh->prepare("UPDATE node SET status_id=" . $db_node_status_info->{'next_status'} . " WHERE id=" . $db_node_info->{'id'});
+ $sth->execute or $self->render(text => "Unable to update node [$machine]", status => 500);
+ }
+ # Send back the template defined by the status information
+ $self->render(template => 'boot/' . $db_node_status_info->{'template'}, format => 'txt');
+ }
+ else {
+ # There was no status information found, so abort
+ $self->render(text => "Unable to find information for this node status", status => 404);
+ }
}
}
};
@@ -109,7 +122,7 @@ sub gensalt {
$self->render(text => $data);
}
elsif ($db_rule_info->{'type_id'} == 2) {
- my $sth = $dbh->prepare("UPDATE node SET status_id=1000 WHERE id=" . $db_node_info->{'id'});
+ my $sth = $dbh->prepare("UPDATE node SET status_id=" . $db_rule_info->{'template'} . " WHERE id=" . $db_node_info->{'id'});
$sth->execute or $self->render(text => "Unable to update node [$machine]", status => 500);
$self->render(text => "Reboot rule [$rule] for [$machine] success!");
}

0 comments on commit 6ac9d52

Please sign in to comment.