1. support groups arg while import/discovering
2. import hostinfo file format should support windows txt file 3. If no dynamic range set, display an error message while start auto discover. 4. distinguish error codes for arguments validation and hostinfo file validation errors: 1 for arguments validation failure, 2 for hostinfo file parse. 5. support hostname format validation. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14144 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
c58f6e361e
commit
c8b1b3219c
@ -184,7 +184,10 @@ sub get_hostname_format_type{
|
||||
$type = "rack";
|
||||
} elsif ($nidx >= 0){
|
||||
$type = "numric";
|
||||
} else{
|
||||
$type = "unknown";
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
@ -296,7 +299,7 @@ sub get_nodes_nic_attrs{
|
||||
sub get_netprofile_bmcnet{
|
||||
my ($class, $netprofilename) = @_;
|
||||
|
||||
my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_netprofile_nic_attrs($netprofilename);
|
||||
my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs($netprofilename)->{$netprofilename};
|
||||
my %netprofile_nicshash = %$netprofile_nicshash_ref;
|
||||
if (exists $netprofile_nicshash{'bmc'}{"network"}){
|
||||
return $netprofile_nicshash{'bmc'}{"network"}
|
||||
@ -317,7 +320,7 @@ sub get_netprofile_bmcnet{
|
||||
sub get_netprofile_provisionnet{
|
||||
my ($class, $netprofilename) = @_;
|
||||
|
||||
my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_netprofile_nic_attrs($netprofilename);
|
||||
my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs([$netprofilename])->{$netprofilename};
|
||||
my %netprofile_nicshash = %$netprofile_nicshash_ref;
|
||||
my $restab = xCAT::Table->new('noderes');
|
||||
my $installnicattr = $restab->getNodeAttribs($netprofilename, ['installnic']);
|
||||
|
@ -220,6 +220,13 @@ sub nodeimport{
|
||||
return;
|
||||
}
|
||||
|
||||
# validate hostnameformat:
|
||||
my $nameformattype = xCAT::ProfiledNodeUtils->get_hostname_format_type($args_dict{'hostnameformat'});
|
||||
if ($nameformattype eq "unknown"){
|
||||
setrsp_errormsg("Invalid hostname format: $args_dict{'hostnameformat'}");
|
||||
return;
|
||||
}
|
||||
|
||||
# Get database records: all hostnames, all ips, all racks...
|
||||
xCAT::MsgUtils->message('S', "Getting database records.");
|
||||
my $recordsref = xCAT::ProfiledNodeUtils->get_allnode_singleattrib_hash('nodelist', 'node');
|
||||
@ -673,7 +680,7 @@ sub nodediscoverstart{
|
||||
return;
|
||||
}
|
||||
|
||||
my @enabledparams = ('networkprofile', 'hardwareprofile', 'imageprofile', 'hostnameformat', 'rank', 'rack', 'chassis', 'height', 'unit');
|
||||
my @enabledparams = ('networkprofile', 'hardwareprofile', 'imageprofile', 'hostnameformat', 'rank', 'rack', 'chassis', 'height', 'unit', 'groups');
|
||||
foreach my $argname (keys %args_dict){
|
||||
if (! grep{ $_ eq $argname} @enabledparams){
|
||||
setrsp_errormsg("Illegal attribute $argname specified.");
|
||||
@ -688,6 +695,13 @@ sub nodediscoverstart{
|
||||
}
|
||||
}
|
||||
|
||||
# validate hostnameformat:
|
||||
my $nameformattype = xCAT::ProfiledNodeUtils->get_hostname_format_type($args_dict{'hostnameformat'});
|
||||
if ($nameformattype eq "unknown"){
|
||||
setrsp_errormsg("Invalid hostname format: $args_dict{'hostnameformat'}");
|
||||
return;
|
||||
}
|
||||
|
||||
my $recordsref = xCAT::ProfiledNodeUtils->get_all_rack(1);
|
||||
%allracks = %$recordsref;
|
||||
$recordsref = xCAT::ProfiledNodeUtils->get_all_chassis(1);
|
||||
@ -747,6 +761,19 @@ sub nodediscoverstart{
|
||||
return;
|
||||
}
|
||||
|
||||
# Make sure provisioning network has a dynamic range.
|
||||
my $provnet = xCAT::ProfiledNodeUtils->get_netprofile_provisionnet($args_dict{networkprofile});
|
||||
if (! $provnet){
|
||||
setrsp_errormsg("No provisioning network defined for network profile.");
|
||||
return;
|
||||
}
|
||||
my $networkstab = xCAT::Table->new("networks");
|
||||
my $netentry = ($networkstab->getAllAttribsWhere("netname = '$provnet'", 'ALL'))[0];
|
||||
if (! $netentry->{'dynamicrange'}){
|
||||
setrsp_errormsg("No dynamicrange defined for the provisioning network.");
|
||||
return;
|
||||
}
|
||||
|
||||
# save discover args into table site.
|
||||
my $valuestr = "";
|
||||
foreach (keys %args_dict){
|
||||
@ -1136,6 +1163,7 @@ sub gen_new_hostinfo_string{
|
||||
if (exists $args_dict{'networkprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'networkprofile'}}
|
||||
if (exists $args_dict{'imageprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'imageprofile'}}
|
||||
if (exists $args_dict{'hardwareprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'hardwareprofile'}}
|
||||
if (exists $args_dict{'groups'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'groups'}}
|
||||
|
||||
# Update BMC records.
|
||||
if (exists $netprofileattr{"bmc"}){
|
||||
@ -1184,6 +1212,8 @@ sub read_and_generate_hostnames{
|
||||
# Auto generate hostnames for "__hostname__" entries.
|
||||
open(HOSTFILE, $hostfile);
|
||||
my $filecontent = join("", <HOSTFILE>);
|
||||
# Convert windows txt file into unix format.
|
||||
$filecontent =~ s/\cM\cJ/\n/g;
|
||||
while ((index $filecontent, "__hostname__:") >= 0){
|
||||
my $nexthost = shift @$freehostnamesref;
|
||||
# no more valid hostnames to assign.
|
||||
@ -1401,7 +1431,7 @@ sub setrsp_invalidrecords
|
||||
|
||||
# The total number of invalid records.
|
||||
$rsp->{error} = "Some error records detected";
|
||||
$rsp->{errorcode} = 1;
|
||||
$rsp->{errorcode} = 2;
|
||||
$rsp->{invalid_records_num} = scalar @$recordsref;
|
||||
|
||||
# We write details of invalid records into a file.
|
||||
|
Loading…
Reference in New Issue
Block a user