From 5ed353a3aed778f4975035fa8c22f5d151783bb0 Mon Sep 17 00:00:00 2001 From: leiaibj Date: Mon, 19 Nov 2012 08:56:16 +0000 Subject: [PATCH] Resolve 2 issues: 1- restrict numric part length in hostname format; 2- resolve db not update timely after calling nodeaddunmgd git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14358 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/ProfiledNodeUtils.pm | 28 +++++++++-- xCAT-server/lib/xcat/plugins/profilednodes.pm | 50 ++++++++++++++----- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm index c3d9a6d47..9af9d2745 100644 --- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm +++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm @@ -70,6 +70,7 @@ sub get_allocable_staticips_innet Description : Generate numric hostnames using numric template name. Arguments : $format - The hostname format string.. $rank - The start number. + $amount - The total hostname number to be generated. Returns : numric hostname list Example : calling genhosts_with_numric_tmpl("compute#NNnode") will return a list like: @@ -79,10 +80,10 @@ sub get_allocable_staticips_innet #------------------------------------------------------------------------------- sub genhosts_with_numric_tmpl { - my ($class, $format, $rank) = @_; + my ($class, $format, $rank, $amount) = @_; my ($prefix, $appendix, $len) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N'); - return xCAT::ProfiledNodeUtils->gen_numric_hostnames($prefix, $appendix, $len, $rank); + return xCAT::ProfiledNodeUtils->gen_numric_hostnames($prefix, $appendix, $len, $rank, $amount); } #------------------------------------------------------------------------------- @@ -133,6 +134,8 @@ sub split_hostname Arguments : $prefix - The prefix string of the hostname. $appendix - The appendix string of the hostname. $len - the numric number length in hostname. + $rank - the start number for numric part + $amount - the amount of hostnames to be generated. Returns : numric hostname list Example : calling gen_numric_hostnames("compute", "node",2) will return a list like: @@ -142,7 +145,7 @@ sub split_hostname #------------------------------------------------------------------------------- sub gen_numric_hostnames { - my ($class, $prefix, $appendix, $len, $rank) = @_; + my ($class, $prefix, $appendix, $len, $rank, $amount) = @_; my @hostnames; my $cnt = 0; @@ -155,6 +158,9 @@ sub gen_numric_hostnames my $fullnum = $maxnum + $cnt; my $hostname = $prefix.(substr $fullnum, 1).$appendix; push (@hostnames, $hostname); + if ($amount && (@hostnames == $amount)){ + last; + } $cnt++; } return \@hostnames; @@ -177,13 +183,25 @@ sub gen_numric_hostnames sub get_hostname_format_type{ my ($class, $format) = @_; my $type; + my ($prefix, $appendix, $rlen, $nlen); my $ridx = index $format, "#R"; my $nidx = index $format, "#N"; if ($ridx >= 0){ - $type = "rack"; + ($prefix, $appendix, $rlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'R'); + ($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N'); + if ($rlen >= 10 || $nlen >= 10){ + $type = "unknown"; + } else{ + $type = "rack"; + } } elsif ($nidx >= 0){ - $type = "numric"; + ($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N'); + if ($nlen >= 10){ + $type = "unknown"; + } else{ + $type = "numric"; + } } else{ $type = "unknown"; } diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm index d61506aaa..e2d221e6f 100644 --- a/xCAT-server/lib/xcat/plugins/profilednodes.pm +++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm @@ -608,15 +608,20 @@ Usage: return; } - # run nodeadd to create node records. - my $retref = xCAT::Utils->runxcmd({command=>["nodeadd"], arg=>[$args_dict{"hostname"}, "groups=__Unmanaged", "hosts.ip=$args_dict{'ip'}"]}, $request_command, 0, 2); + my %updatenodeshash = (); + $updatenodeshash{$args_dict{'hostname'}}{'ip'} = $args_dict{'ip'}; + my $hoststab = xCAT::Table->new('hosts',-create=>1); + $hoststab->setNodesAttribs(\%updatenodeshash); + $hoststab->close(); + + %updatenodeshash = (); + $updatenodeshash{$args_dict{'hostname'}}{'groups'} = "__Unmanaged"; + my $nodetab = xCAT::Table->new('nodelist',-create=>1); + $nodetab->setNodesAttribs(\%updatenodeshash); + $nodetab->close(); + + my $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>[$args_dict{"hostname"}]}, $request_command, 0, 2); my $retstrref = parse_runxcmd_ret($retref); - if ($::RUNCMD_RC != 0){ - setrsp_errormsg("Failed to call nodeadd to create node."); - return; - } - $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>[$args_dict{"hostname"}]}, $request_command, 0, 2); - $retstrref = parse_runxcmd_ret($retref); if ($::RUNCMD_RC != 0){ setrsp_progress("Warning: failed to call makehosts."); } @@ -1330,6 +1335,11 @@ sub parse_hosts_string{ } } # Verify each node entry. + my $rank = 0; + if (exists($args_dict{'rank'})){ + $rank = $args_dict{'rank'}; + } + foreach (keys %::FILEATTRS){ my $errmsg = validate_node_entry($_, $::FILEATTRS{$_}); if ($errmsg) { @@ -1359,16 +1369,30 @@ sub parse_hosts_string{ } # Generate hostnames based on numric hostname format. + my $hostnamelistref; if (! exists $freehostnames{$numricformat}){ - my $rank = 0; - if (exists($args_dict{'rank'})){ - $rank = $args_dict{'rank'}; + $hostnamelistref = xCAT::ProfiledNodeUtils->genhosts_with_numric_tmpl($numricformat, $rank, 10000); + $rank = $rank + 10000; + if (! @$hostnamelistref){ + push @invalid_records, ["__hostname__", "Can not generate sufficient hostnames from hostname format."]; + last; + }else{ + $freehostnames{$numricformat} = $hostnamelistref; } - $freehostnames{$numricformat} = xCAT::ProfiledNodeUtils->genhosts_with_numric_tmpl($numricformat, $rank); } - my $hostnamelistref = $freehostnames{$numricformat}; + + $hostnamelistref = $freehostnames{$numricformat}; my $nexthostname = shift @$hostnamelistref; while (exists $allhostnames{$nexthostname}){ + if (! @$hostnamelistref){ + $hostnamelistref = xCAT::ProfiledNodeUtils->genhosts_with_numric_tmpl($numricformat, $rank, 10000); + $rank = $rank + 10000; + if(! @$hostnamelistref){ + push @invalid_records, ["__hostname__", "Can not generate sufficient hostnames from hostname format."]; + last; + } + } + $nexthostname = shift @$hostnamelistref; } $hostinfo_dict{$nexthostname} = $::FILEATTRS{$_};