first commit for prefix hostname feature

This commit is contained in:
Arif Ali 2014-01-09 21:02:53 +00:00
parent 23c464cbe8
commit e01827f9d3
4 changed files with 51 additions and 6 deletions

View File

@ -265,6 +265,7 @@ sub rackformat_to_numricformat{
values are attributes of a specific nic, like:
type : nic type
hostnamesuffix: hostname suffix
hostnameprefix: hostname prefix
customscript: custom script for this nic
network: network name for this nic
ip: ip address of this nic.
@ -276,7 +277,7 @@ sub get_nodes_nic_attrs{
my $nodes = shift;
my $nicstab = xCAT::Table->new( 'nics');
my $entry = $nicstab->getNodesAttribs($nodes, ['nictypes', 'nichostnamesuffixes', 'niccustomscripts', 'nicnetworks', 'nicips']);
my $entry = $nicstab->getNodesAttribs($nodes, ['nictypes', 'nichostnamesuffixes', 'nichostnameprefixes', 'niccustomscripts', 'nicnetworks', 'nicips']);
my %nicsattrs;
my @nicattrslist;
@ -308,6 +309,20 @@ sub get_nodes_nic_attrs{
}
}
if($entry->{$node}->[0]->{'nichostnameprefixes'}){
@nicattrslist = split(",", $entry->{$node}->[0]->{'nichostnameprefixes'});
foreach (@nicattrslist){
my @nicattrs;
if ($_ =~ /!/) {
@nicattrs = split("!", $_);
} else {
@nicattrs = split(":", $_);
}
$nicsattrs{$node}{$nicattrs[0]}{'hostnameprefix'} = $nicattrs[1];
}
}
if($entry->{$node}->[0]->{'niccustomscripts'}){
@nicattrslist = split(",", $entry->{$node}->[0]->{'niccustomscripts'});
foreach (@nicattrslist){

View File

@ -1329,7 +1329,7 @@ firmware => {
},
nics => {
cols => [qw(node nicips nichostnamesuffixes nictypes niccustomscripts nicnetworks nicaliases comments disable)],
cols => [qw(node nicips nichostnamesuffixes nichostnameprefixes nictypes niccustomscripts nicnetworks nicaliases comments disable)],
keys => [qw(node)],
tablespace =>'XCATTBS16K',
table_desc => 'Stores NIC details.',
@ -1347,6 +1347,13 @@ nics => {
<nic1>!<ext1>|<ext2>,<nic2>!<ext1>|<ext2>,..., for example, eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6.
The xCAT object definition commands support to use nichostnamesuffixes.<nicname> as the sub attributes.
Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-),and period (.). When you are specifying "nichostnamesuffixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention',
nichostnameprefixes => 'Comma-separated list of hostname prefixes per NIC.
If only one ip address is associated with each NIC:
<nic1>!<ext1>,<nic2>!<ext2>,..., for example, eth0!eth0-,ib0!ib-
If multiple ip addresses are associcated with each NIC:
<nic1>!<ext1>|<ext2>,<nic2>!<ext1>|<ext2>,..., for example, eth0!eth0-|eth0-ipv6i-,ib0!ib-|ib-ipv6-.
The xCAT object definition commands support to use nichostnameprefixes.<nicname> as the sub attributes.
Note: According to DNS rules a hostname must be a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-),and period (.). When you are specifying "nichostnameprefixes" or "nicaliases" make sure the resulting hostnames will conform to this naming convention',
nictypes => 'Comma-separated list of NIC types per NIC. <nic1>!<type1>,<nic2>!<type2>, e.g. eth0!Ethernet,ib0!Infiniband. The xCAT object definition commands support to use nictypes.<nicname> as the sub attributes.',
niccustomscripts => 'Comma-separated list of custom scripts per NIC. <nic1>!<script1>,<nic2>!<script2>, e.g. eth0!configeth eth0, ib0!configib ib0. The xCAT object definition commands support to use niccustomscripts.<nicname> as the sub attribute
.',

View File

@ -538,7 +538,7 @@ sub processArgs
# --nics is the equivalent of -i nicips,nichostnamesuffixes...
if ($::opt_nics) {
$::opt_i="nicips,nichostnamesuffixes,nictypes,niccustomscripts,nicnetworks,nicaliases";
$::opt_i="nicips,nichostnamesuffixes,nihostnameprefixes,nictypes,niccustomscripts,nicnetworks,nicaliases";
}
# -i and -s cannot be used together

View File

@ -91,7 +91,7 @@ sub addnode
# at this point "othernames", if any is just a space
# delimited list - so just add the node name to the list
$othernames .= " $node";
#$othernames .= " $node";
$hosts[$idx] = build_line($callback, $ip, $hnode, $domain, $othernames);
} else {
# otherwise just try to completely update the existing
@ -599,6 +599,7 @@ sub donics
$node,
[
'nicips', 'nichostnamesuffixes',
'nichostnameprefixes',
'nicnetworks', 'nicaliases'
]
);
@ -644,6 +645,7 @@ sub donics
}
my @nicandsufx = split(',', $et->{'nichostnamesuffixes'});
my @nicandprfx = split(',', $et->{'nichostnameprefixes'});
foreach (@nicandsufx)
{
@ -665,12 +667,32 @@ sub donics
$nich->{$nicname}->{nicsufx}->[0] = $nicsufx;
}
}
foreach (@nicandprfx)
{
my ($nicname, $nicprfx);
if ($_ =~ /!/) {
($nicname, $nicprfx) = split('!', $_);
} else {
($nicname, $nicprfx) = split(':', $_);
}
if ( $nicprfx =~ /\|/) {
my @prfs = split( /\|/, $nicprfx);
my $index=0;
foreach my $prf (@prfs) {
$nich->{$nicname}->{nicprfx}->[$index] = $prf;
$index++;
}
} else {
$nich->{$nicname}->{nicprfx}->[0] = $nicprfx;
}
}
# see if we need to fill in a default suffix
# nich has all the valid nics - ie. that have IPs provided!
foreach my $nic (keys %{$nich}) {
for (my $i = 0; $i < $nicindex{$nic}; $i++ ){
if (!$nich->{$nic}->{nicsufx}->[$i]) {
if (!$nich->{$nic}->{nicsufx}->[$i] && !$nich->{$nic}->{nicprfx}->[$i]) {
# then we have no suffix at all for this
# so set a default
$nich->{$nic}->{nicsufx}->[$i] = "-$nic";
@ -741,6 +763,7 @@ sub donics
my $nicip = $nich->{$nic}->{nicip}->[$i];
my $nicsuffix = $nich->{$nic}->{nicsufx}->[$i];
my $nicprefix = $nich->{$nic}->{nicprfx}->[$i];
my $nicnetworks = $nich->{$nic}->{netwrk}->[$i];
my $nicaliases = $nich->{$nic}->{nicaliases}->[$i];
@ -749,7 +772,7 @@ sub donics
}
# construct hostname for nic
my $nichostname = "$shorthost$nicsuffix";
my $nichostname = "$nicprefix$shorthost$nicsuffix";
# get domain from network def provided by nic attr
my $nt = $nettab->getAttribs({ netname => "$nicnetworks"}, 'domain');