diff --git a/perl-xCAT/xCAT/zvmUtils.pm b/perl-xCAT/xCAT/zvmUtils.pm index 9b0114914..a790d9dfb 100644 --- a/perl-xCAT/xCAT/zvmUtils.pm +++ b/perl-xCAT/xCAT/zvmUtils.pm @@ -1104,4 +1104,50 @@ sub inArray { # Get inputs my ( $class, $needle, @haystack ) = @_; return grep{ $_ eq $needle } @haystack; +} + +#------------------------------------------------------- + +=head3 getOsVersion + + Description : Get the operating system of a given node + Arguments : Node + Returns : Operating system name + Example : my $os = xCAT::zvmUtils->getOsVersion($node); + +=cut + +#------------------------------------------------------- +sub getOsVersion { + + # Get inputs + my ( $class, $node ) = @_; + + my $os = ''; + my $version = ''; + + # Get operating system + my $release = `ssh -o ConnectTimeout=2 $node "cat /etc/*release"`; + my @lines = split('\n', $release); + if (grep(/SLES|Enterprise Server/, @lines)) { + $os = 'sles'; + $version = $lines[0]; + $version =~ tr/\.//; + $version =~ s/[^0-9]*([0-9]+).*/$1/; + $os = $os . $version; + + # Append service level + $version = `echo "$release" | grep "LEVEL"`; + $version =~ tr/\.//; + $version =~ s/[^0-9]*([0-9]+).*/$1/; + $os = $os . 'sp' . $version; + } elsif (grep(/Red Hat Enterprise Linux Server/, @lines)) { + $os = 'rhel'; + $version = $lines[0]; + $version =~ tr/\.//; + $version =~ s/([A-Za-z\s\(\)]+)//g; + $os = $os . $version; + } + + return xCAT::zvmUtils->trimStr($os); } \ No newline at end of file diff --git a/xCAT-server/lib/xcat/plugins/zvm.pm b/xCAT-server/lib/xcat/plugins/zvm.pm index e885bbf74..a9b44faa6 100644 --- a/xCAT-server/lib/xcat/plugins/zvm.pm +++ b/xCAT-server/lib/xcat/plugins/zvm.pm @@ -1312,7 +1312,7 @@ sub scanVM { # Parse options GetOptions( 'w' => \$write2db ); } - + # Get node properties from 'zvm' table my @propNames = ( 'hcp', 'userid' ); my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); @@ -1441,22 +1441,33 @@ sub scanVM { $arch = 's390x'; } - # Save to 'zvm' table + # Get OS + $os = xCAT::zvmUtils->getOsVersion($node); + + # Save node attributes if ($write2db) { + # Save to 'zvm' table %propHash = ( 'hcp' => $hcp, 'userid' => $id, 'nodetype' => 'vm', 'parent' => $host - ); - + ); xCAT::zvmUtils->setNodeProps( 'zvm', $node, \%propHash ); + + # Save to 'nodetype' table + %propHash = ( + 'arch' => $arch, + 'os' => $os + ); + xCAT::zvmUtils->setNodeProps( 'nodetype', $node, \%propHash ); } # Create output string $str .= "$node:\n"; $str .= " objtype=node\n"; $str .= " arch=$arch\n"; + $str .= " os=$os\n"; $str .= " hcp=$hcp\n"; $str .= " userid=$id\n"; $str .= " nodetype=vm\n";