SLP automatic naming for HMC
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2262 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -1076,20 +1076,81 @@ sub process_request { | ||||
|     process_command( \%request ); | ||||
| } | ||||
|  | ||||
| ########################################################################## | ||||
| # connect hmc via ssh and execute remote command | ||||
| ########################################################################## | ||||
| sub sshcmds_on_hmc | ||||
| { | ||||
|     my $ip = shift; | ||||
|     my $user = shift; | ||||
|     my $password = shift; | ||||
|     my @cmds = @_; | ||||
|      | ||||
|     my %handled; | ||||
|     my @data; | ||||
|     my @exp; | ||||
|     for my $cmd (@cmds) | ||||
|     { | ||||
|         if ( $cmd =~ /(.+?)=(.*)/) | ||||
|         { | ||||
|             my ($command,$value) = ($1,$2); | ||||
|             $handled{$command} = $value; | ||||
|         } | ||||
|     } | ||||
|     my %request = ( | ||||
|             ppcretry => 1, | ||||
|             verbose  => 0, | ||||
|             ppcmaxp    => 64, | ||||
|             ppctimeout => 0, | ||||
|             fsptimeout => 0, | ||||
|             ppcretry   => 3, | ||||
|             maxssh     => 10 | ||||
|  | ||||
|             ); | ||||
|  | ||||
|     my $valid_ip; | ||||
|     foreach my $individual_ip ( split /,/, $ip ) { | ||||
|          ################################ | ||||
|          # Get userid and password  | ||||
|          ################################ | ||||
|          my @cred = xCAT::PPCdb::credentials( $individual_ip, "hmc" ); | ||||
|          $request{$individual_ip}{cred} = \@cred; | ||||
|  | ||||
|         @exp = xCAT::PPCcli::connect( \%request, 'hmc', $individual_ip); | ||||
| #################################### | ||||
| # Successfully connected  | ||||
| #################################### | ||||
|         if ( ref($exp[0]) eq "Expect" ) { | ||||
|             $valid_ip = $individual_ip; | ||||
|             last; | ||||
|         } | ||||
|     } | ||||
|  | ||||
| ######################################## | ||||
| # Error connecting  | ||||
| ######################################## | ||||
|     if ( ref($exp[0]) ne "Expect" ) { | ||||
|         return ([1,@cmds]); | ||||
|     } | ||||
| ######################################## | ||||
| # Process specific command  | ||||
| ######################################## | ||||
|     for my $cmd ( keys %handled) | ||||
|     { | ||||
|         my $result; | ||||
|         if ($cmd eq 'network_reset') | ||||
|         { | ||||
|             $result = xCAT::PPCcli::network_reset( \@exp, $valid_ip, $handled{$cmd}); | ||||
|             my $RC = shift( @$result); | ||||
|         } | ||||
|         push @data, @$result[0];  | ||||
|     } | ||||
| ######################################## | ||||
| # Close connection to remote server | ||||
| ######################################## | ||||
|     xCAT::PPCcli::disconnect( \@exp ); | ||||
|  | ||||
|     return ([0, undef, \@data]); | ||||
| } | ||||
|  | ||||
| 1; | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -976,7 +976,68 @@ sub power_cmd { | ||||
|     return undef; | ||||
| } | ||||
|  | ||||
| ##################################### | ||||
| # Reset HMC network (hostname & IP) | ||||
| ##################################### | ||||
| sub network_reset { | ||||
|  | ||||
|     my $exp    = shift; | ||||
|     my $current_ip   = shift; | ||||
|     my $hostname_ip  =shift; | ||||
|     my $hwtype = @$exp[2]; | ||||
|  | ||||
|     my ($ip,$hostname) = split /,/, $hostname_ip; | ||||
|     if ( !$hostname || !$ip) | ||||
|     { | ||||
|         return ( [RC_ERROR,"No valid hostname or IP find. This could be a internal bug of xCAT."] ); | ||||
|     } | ||||
| ##################################### | ||||
| # Format command based on HW Type | ||||
| ##################################### | ||||
|     my %cmd = ( | ||||
|             hmc =>"lshmc -n -F hostname:ipaddr", | ||||
|             ivm =>"lsivm" #just for future consideration | ||||
|             ); | ||||
|  | ||||
| ##################################### | ||||
| # Get current hostname and IP | ||||
| ##################################### | ||||
|     my $result = send_cmd( $exp, $cmd{$hwtype} ); | ||||
|     if ( @$result[0] != SUCCESS ) { | ||||
|         return( $result ); | ||||
|     } | ||||
|     my ($current_hostname,$current_all_ip) = split /:/, @$result[1]; | ||||
|  | ||||
| ##################################### | ||||
| # Find the correct interface | ||||
| ##################################### | ||||
|     my @eth_ip = split /,/,$current_all_ip; | ||||
|     my $i; | ||||
|     for( $i=0; $i < scalar(@eth_ip); $i++) | ||||
|     { | ||||
|         if (@eth_ip[$i] eq $current_ip) | ||||
|         { | ||||
|             last; | ||||
|         } | ||||
|     } | ||||
|     if ($i >= scalar(@eth_ip)) | ||||
|     { | ||||
| # What's happen? | ||||
|         return ( [RC_ERROR,"No appropriate IP addresses to be updated. This could be a internal bug of xCAT."]); | ||||
|     } | ||||
|  | ||||
|     %cmd = ( | ||||
| # probably need update netmask also | ||||
|             hmc => "chhmc -c network  -s modify -h $hostname -i eth$i -a $ip", | ||||
|             ivm => "nothing" | ||||
|            ); | ||||
|     $result = send_cmd( $exp, $cmd{$hwtype} ); | ||||
| ##################################### | ||||
| # Return error | ||||
| ##################################### | ||||
|     return( $result ); | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| 1; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user