Skip to content

Commit

Permalink
whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Apr 24, 2014
1 parent 38e9312 commit ce1e887
Showing 1 changed file with 113 additions and 120 deletions.
233 changes: 113 additions & 120 deletions aii-pxelinux/src/main/perl/pxelinux.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
# ${developer-info
# ${author-info}
# ${build-info}
# File: pxelinux.pm
# Implementation of ncm-pxelinux
# Author: Luis Fernando Muñoz Mejías
# Version: 1.1.12 : 05/01/12 19:24
# ** Generated file : do not edit **
#
# Capitalized methods are "public" methods. Methods in lowercase are
# "private" methods.

package NCM::Component::pxelinux;

Expand All @@ -25,25 +17,25 @@ use LC::Fatal qw (symlink);
use File::stat;
use Time::localtime;

use constant PXEROOT => "/system/aii/nbp/pxelinux";
use constant NBPDIR => 'nbpdir';
use constant LOCALBOOT => 'bootconfig';
use constant HOSTNAME => "/system/network/hostname";
use constant DOMAINNAME => "/system/network/domainname";
use constant ETH => "/system/network/interfaces";
use constant INSTALL => 'install';
use constant BOOT => 'boot';
use constant RESCUE => 'rescue';
use constant PXEROOT => "/system/aii/nbp/pxelinux";
use constant NBPDIR => 'nbpdir';
use constant LOCALBOOT => 'bootconfig';
use constant HOSTNAME => "/system/network/hostname";
use constant DOMAINNAME => "/system/network/domainname";
use constant ETH => "/system/network/interfaces";
use constant INSTALL => 'install';
use constant BOOT => 'boot';
use constant RESCUE => 'rescue';
use constant RESCUEBOOT => 'rescueconfig';
use constant FIRMWARE => 'firmware';
use constant LIVECD => 'livecd';
use constant FIRMWARE => 'firmware';
use constant LIVECD => 'livecd';
# Hooks for NBP plug-in
use constant RESCUE_HOOK_PATH => '/system/aii/hooks/rescue';
use constant INSTALL_HOOK_PATH => '/system/aii/hooks/install';
use constant REMOVE_HOOK_PATH => '/system/aii/hooks/remove';
use constant BOOT_HOOK_PATH => '/system/aii/hooks/boot';
use constant FIRMWARE_HOOK_PATH => '/system/aii/hooks/firmware';
use constant LIVECD_HOOK_PATH => '/system/aii/hooks/livecd';
use constant RESCUE_HOOK_PATH => '/system/aii/hooks/rescue';
use constant INSTALL_HOOK_PATH => '/system/aii/hooks/install';
use constant REMOVE_HOOK_PATH => '/system/aii/hooks/remove';
use constant BOOT_HOOK_PATH => '/system/aii/hooks/boot';
use constant FIRMWARE_HOOK_PATH => '/system/aii/hooks/firmware';
use constant LIVECD_HOOK_PATH => '/system/aii/hooks/livecd';

our @ISA = qw (NCM::Component);
our $EC = LC::Exception::Context->new->will_store_all;
Expand All @@ -70,20 +62,20 @@ sub link_filepath

my $cfgpath = PXEROOT . "/" . $cmd;
if ($cfg->elementExists ($cfgpath)) {
my $linkname = $cfg->getElement ($cfgpath)->getValue;
return "$dir/$linkname";
my $linkname = $cfg->getElement ($cfgpath)->getValue;
return "$dir/$linkname";
} elsif ($cmd eq RESCUE) {
# Backwards compatibility: use the option set on the command line
# if the profile does not define a rescue image
my $path = $this_app->option (RESCUEBOOT);
unless ($path =~ m{^([-.\w]+)$}) {
$this_app->error ("Unexpected RESCUE configuration file");
}
return "$dir/$1";
# Backwards compatibility: use the option set on the command line
# if the profile does not define a rescue image
my $path = $this_app->option (RESCUEBOOT);
unless ($path =~ m{^([-.\w]+)$}) {
$this_app->error ("Unexpected RESCUE configuration file");
}
return "$dir/$1";
} else {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$this_app->debug(3, "No $cmd defined for $h.$d");
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$this_app->debug(3, "No $cmd defined for $h.$d");
}
return undef;
}
Expand All @@ -98,7 +90,8 @@ sub pxeprint
my $server = hostname();
$ksloc =~ s{LOCALHOST}{$server};
my $fh = CAF::FileWriter->open (filepath ($cfg),
log => $this_app, mode => 0644);
log => $this_app,
mode => 0644);
$t->{append} = "" unless exists $t->{append};
$fh->print (<<EOF
# File generated by pxelinux AII plug-in.
Expand All @@ -108,7 +101,7 @@ default $t->{label}
kernel $t->{kernel}
append ramdisk=32768 initrd=$t->{initrd} ks=$ksloc ksdevice=$t->{ksdevice} $t->{append}
EOF
);
);

$fh->print (" ipappend 2\n") if $t->{ksdevice} eq 'bootif';
$fh->close();
Expand All @@ -131,49 +124,49 @@ sub pxelink
my $t = $cfg->getElement (ETH)->getTree;
my $path;
if (!$cmd) {
$path = $this_app->option (LOCALBOOT);
$this_app->debug (5, "Configuring on $path");
$path = $this_app->option (LOCALBOOT);
$this_app->debug (5, "Configuring on $path");
} elsif ($cmd eq BOOT) {
$path = $this_app->option (LOCALBOOT);
unless ($path =~ m{^([-.\w]+)$}) {
$this_app->error ("Unexpected BOOT configuration file");
return -1;
}
$path = $1;
$this_app->debug (5, "Local booting from $path");
$path = $this_app->option (LOCALBOOT);
unless ($path =~ m{^([-.\w]+)$}) {
$this_app->error ("Unexpected BOOT configuration file");
return -1;
}
$path = $1;
$this_app->debug (5, "Local booting from $path");
} elsif ($cmd eq RESCUE || $cmd eq LIVECD || $cmd eq FIRMWARE) {
$path = link_filepath($cfg, $cmd);
if (! -f $path) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$this_app->error("Missing $cmd config file for $h.$d: $path");
return -1;
}
$this_app->debug (5, "Using $cmd from: $path");
$path = link_filepath($cfg, $cmd);
if (! -f $path) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$this_app->error("Missing $cmd config file for $h.$d: $path");
return -1;
}
$this_app->debug (5, "Using $cmd from: $path");
} elsif ($cmd eq INSTALL) {
$path = filepath ($cfg);
$this_app->debug (5, "Installing on $path");
$path = filepath ($cfg);
$this_app->debug (5, "Installing on $path");
} else {
$this_app->debug (5, "Unknown command");
return -1;
$this_app->debug (5, "Unknown command");
return -1;
}
# Set the same settings for every network interface that has a
# defined IP address.
foreach my $st (values (%$t)) {
next unless exists ($st->{ip});
my $dir = $this_app->option (NBPDIR);
my $lnname = "$dir/".hexip ($st->{ip});
if ($cmd || ! -l $lnname) {
if ($NoAction) {
$this_app->info ("Would symlink $path to $lnname");
} else {
unlink ($lnname);
# This must be stripped to work with chroot'edg
# environments.
$path =~ s{$dir/?}{};
symlink ($path, $lnname);
}
}
next unless exists ($st->{ip});
my $dir = $this_app->option (NBPDIR);
my $lnname = "$dir/".hexip ($st->{ip});
if ($cmd || ! -l $lnname) {
if ($NoAction) {
$this_app->info ("Would symlink $path to $lnname");
} else {
unlink ($lnname);
# This must be stripped to work with chroot'edg
# environments.
$path =~ s{$dir/?}{};
symlink ($path, $lnname);
}
}
}
return 0;
}
Expand All @@ -184,10 +177,10 @@ sub Install
my ($self, $cfg) = @_;

unless (pxelink ($cfg, INSTALL)==0) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to install");
return 0;
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to install");
return 0;
}
ksuserhooks ($cfg, INSTALL_HOOK_PATH) unless $NoAction;
return 1;
Expand All @@ -199,10 +192,10 @@ sub Firmware
my ($self, $cfg) = @_;

unless (pxelink ($cfg, FIRMWARE)==0) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to firmware");
return 0;
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to firmware");
return 0;
}
ksuserhooks ($cfg, FIRMWARE_HOOK_PATH) unless $NoAction;
return 1;
Expand All @@ -214,10 +207,10 @@ sub Livecd
my ($self, $cfg) = @_;

unless (pxelink ($cfg, LIVECD)==0) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error("Failed to change the status of $h.$d to livecd");
return 0;
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error("Failed to change the status of $h.$d to livecd");
return 0;
}
ksuserhooks ($cfg, LIVECD_HOOK_PATH) unless $NoAction;
return 1;
Expand All @@ -229,10 +222,10 @@ sub Rescue
my ($self, $cfg) = @_;

unless (pxelink ($cfg, RESCUE)==0) {
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to rescue");
return 0;
my $h = $cfg->getElement (HOSTNAME)->getValue;
my $d = $cfg->getElement (DOMAINNAME)->getValue;
$self->error ("Failed to change the status of $h.$d to rescue");
return 0;
}
ksuserhooks ($cfg, RESCUE_HOOK_PATH) unless $NoAction;
return 1;
Expand All @@ -253,34 +246,34 @@ sub Status
my $firmware = link_filepath($cfg, FIRMWARE);
my $livecd = link_filepath($cfg, LIVECD);
foreach my $s (values (%$t)) {
next unless exists ($s->{ip});
my $ln = hexip ($s->{ip});
my $since = "unknown";
my $st;
if (-l "$dir/$ln") {
$since = ctime(lstat("$dir/$ln")->ctime());
my $name = readlink ("$dir/$ln");
my $name_path = "$dir/$name";
if (! -e $name_path) {
$st = "broken";
} elsif ($name =~ m{^(?:.*/)?$fqdn\.cfg$}) {
$st = "install";
} elsif ($name =~ m{^$boot$}) {
$st = "boot";
} elsif ($firmware && ($name_path =~ m{$firmware})) {
$st = "firmware";
} elsif ($livecd && ($name_path =~ m{$livecd})) {
$st = "livecd";
} elsif ($rescue && ($name_path =~ m{$rescue})) {
$st = "rescue";
} else {
$st = "unknown";
}
} else {
$st = "undefined";
}
$self->info(ref($self), " status for $fqdn: $s->{ip} $st ",
"since: $since");
next unless exists ($s->{ip});
my $ln = hexip ($s->{ip});
my $since = "unknown";
my $st;
if (-l "$dir/$ln") {
$since = ctime(lstat("$dir/$ln")->ctime());
my $name = readlink ("$dir/$ln");
my $name_path = "$dir/$name";
if (! -e $name_path) {
$st = "broken";
} elsif ($name =~ m{^(?:.*/)?$fqdn\.cfg$}) {
$st = "install";
} elsif ($name =~ m{^$boot$}) {
$st = "boot";
} elsif ($firmware && ($name_path =~ m{$firmware})) {
$st = "firmware";
} elsif ($livecd && ($name_path =~ m{$livecd})) {
$st = "livecd";
} elsif ($rescue && ($name_path =~ m{$rescue})) {
$st = "rescue";
} else {
$st = "unknown";
}
} else {
$st = "undefined";
}
$self->info(ref($self), " status for $fqdn: $s->{ip} $st ",
"since: $since");
}
return 1;
}
Expand Down Expand Up @@ -311,8 +304,8 @@ sub Unconfigure
my ($self, $cfg) = @_;

if ($NoAction) {
$self->info ("Would remove " . ref ($self));
return 1;
$self->info ("Would remove " . ref ($self));
return 1;
}

my $t = $cfg->getElement (ETH)->getTree;
Expand Down

0 comments on commit ce1e887

Please sign in to comment.