From 45b13721d1a12d1b9b93e50e8fef881607f2eec1 Mon Sep 17 00:00:00 2001 From: chenglch Date: Fri, 22 Apr 2016 04:49:23 -0400 Subject: [PATCH] Add configuration in site table to inherit attributes 'heirarchicalattrs' is added in site table to apply attributes from multiple groups in order. close-issue #115 --- .../admin-guides/references/man5/site.5.rst | 24 ++++++++------ perl-xCAT/xCAT/Schema.pm | 3 ++ perl-xCAT/xCAT/Table.pm | 31 ++++++++++++++----- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man5/site.5.rst b/docs/source/guides/admin-guides/references/man5/site.5.rst index 962517f45..b93dd663e 100644 --- a/docs/source/guides/admin-guides/references/man5/site.5.rst +++ b/docs/source/guides/admin-guides/references/man5/site.5.rst @@ -300,16 +300,16 @@ site Attributes: xcatconfdir: Where xCAT config data is (default /etc/xcat). xcatdebugmode: the xCAT debug level. xCAT provides a batch of techniques - to help user debug problems while using xCAT, especially on OS provision, - such as collecting logs of the whole installation process and accessing - the installing system via ssh, etc. These techniques will be enabled - according to different xCAT debug levels specified by 'xcatdebugmode', - currently supported values: - '0': disable debug mode - '1': enable basic debug mode - '2': enalbe expert debug mode - For the details on 'basic debug mode' and 'expert debug mode', - please refer to xCAT documentation. + to help user debug problems while using xCAT, especially on OS provision, + such as collecting logs of the whole installation process and accessing + the installing system via ssh, etc. These techniques will be enabled + according to different xCAT debug levels specified by 'xcatdebugmode', + currently supported values: + '0': disable debug mode + '1': enable basic debug mode + '2': enalbe expert debug mode + For the details on 'basic debug mode' and 'expert debug mode', + please refer to xCAT documentation. -------------------- REMOTESHELL ATTRIBUTES @@ -380,6 +380,10 @@ site Attributes: entries generated by 'makehosts' will put the FQDN before the PQDN(Partially Qualified Domain Name). Otherwise, the original behavior will be performed. + heirarchicalattrs: Table attributes(e.g. postscripts, postbootscripts) that will be + included hierarchically. Attribute values for all the node's groups + will be applied to the node in the groups' order except the repeat one. + .. code-block:: perl diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 35bcb91b7..402d1aa0a 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -1188,6 +1188,9 @@ use xCAT::ExtTab; "FQDNfirst: Fully Qualified Domain Name first. If set to 1/yes/enable, the /etc/hosts \n" . " entries generated by 'makehosts' will put the FQDN before the PQDN(Partially \n" . " Qualified Domain Name). Otherwise, the original behavior will be performed.\n\n" . +"heirarchicalattrs: Table attributes(e.g. postscripts, postbootscripts) that will be\n". +" included hierarchically. Attribute values for all the node's groups\n". +" will be applied to the node in the groups' order except the repeat one.\n\n". " -----------------------\n" . "VIRTUALIZATION ATTRIBUTES\n" . " -----------------------\n" . diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 68205c876..cfbdd6896 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -2554,16 +2554,25 @@ sub getNodeAttribs_nosub_returnany my $attrib; my $result; - + my @hierarchy_attrs; + my $hierarchy_field = xCAT::TableUtils->get_site_attribute("heirarchicalattrs"); + if ($hierarchy_field) { + @hierarchy_attrs = split(/,/, $hierarchy_field); + } + my $data = $results[0]; if(defined{$data}) { #if there was some data for the node, loop through and check it foreach $result (@results) { foreach $attrib (keys %attribsToDo) { + if (defined($result) && defined($result->{$attrib}) + && @hierarchy_attrs && grep (/^$attrib$/, @hierarchy_attrs) ) { + $result->{$attrib} .= ',+=NEXTRECORD'; + } #check each item in the results to see which attributes were satisfied if(defined($result) && defined($result->{$attrib}) && $result->{$attrib} !~ $nextRecordAtEnd) { delete $attribsToDo{$attrib}; - } - } + } + } } } @@ -2578,7 +2587,7 @@ sub getNodeAttribs_nosub_returnany unless (defined($nodeghash) && defined($nodeghash->{groups})) { return @results; } - + my @nodegroups = split(/,/, $nodeghash->{groups}); my $group; my @groupResults; @@ -2601,8 +2610,10 @@ sub getNodeAttribs_nosub_returnany #print "looking for attrib $attrib\n"; if(defined($groupResult->{$attrib})){ $attribsDone{$attrib} = 0; -#print "found attArib $attrib = $groupResult->{$attrib}\n"; -#print "and results look like this: \n".Dumper(\@results)."\n\n\n"; + # for hierarchy attribute, append attributes from all the node's group + if (@hierarchy_attrs && grep (/^$attrib$/, @hierarchy_attrs) ) { + $groupResult->{$attrib} .= ',+=NEXTRECORD'; + } foreach $result (@results){ #loop through our existing results to add or modify the value for this attribute if(defined($result)) { if(defined($result->{$attrib})) { @@ -2639,7 +2650,6 @@ sub getNodeAttribs_nosub_returnany } } else {#no results in the array so far -#print "pushing for the first time. attr=$attrib groupResults=$groupResult->{$attrib}\n"; $toPush{$attrib} = $groupResult->{$attrib}; if($options{withattribution} && $attrib ne $nodekey){ $toPush{'!!xcatgroupattribution!!'}->{$attrib} = $group; @@ -2685,6 +2695,13 @@ sub getNodeAttribs_nosub_returnany for $result (@results) { for my $key (keys %$result) { $result->{$key} =~ s/\+=NEXTRECORD//g; + if (@hierarchy_attrs && grep (/^$key$/, @hierarchy_attrs) ) { + my @attribs = split(/,/, $result->{$key}); + my %count; + # remove the repeat value + @attribs = grep { ++$count{ $_ } < 2; } @attribs; + $result->{$key} = join(',', @attribs); + } } }