Fix bug 3261047:ExtTab loads user tables for every perl process
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9236 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		@@ -3,7 +3,7 @@
 | 
			
		||||
package xCAT_plugin::fsp;
 | 
			
		||||
use strict;
 | 
			
		||||
use xCAT::PPC;
 | 
			
		||||
 | 
			
		||||
use xCAT::DBobjUtils;
 | 
			
		||||
 | 
			
		||||
##########################################################################
 | 
			
		||||
# Command handler method from tables
 | 
			
		||||
@@ -26,7 +26,8 @@ sub handled_commands {
 | 
			
		||||
      mkvm      => 'nodehm:mgt',
 | 
			
		||||
      lsvm      => 'nodehm:mgt',
 | 
			
		||||
      chvm      => 'nodehm:mgt',
 | 
			
		||||
      rscan     => 'nodehm:mgt'
 | 
			
		||||
      rscan     => 'nodehm:mgt',
 | 
			
		||||
      getfspcon => 'nodehm:cons',
 | 
			
		||||
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -57,6 +58,13 @@ sub preprocess_request {
 | 
			
		||||
        $callback->( {errorcode=>1,data=>[$@]} );
 | 
			
		||||
        return(1);
 | 
			
		||||
    }
 | 
			
		||||
    my ($arg1, $arg2, $arg3) = @_;
 | 
			
		||||
    if ($arg1->{command}->[0] eq "getfspcon") { #Can handle it here and now
 | 
			
		||||
        my $node = $arg1->{noderange}->[0];
 | 
			
		||||
		my $callback = $arg2;
 | 
			
		||||
        getfspcon($node,$callback);
 | 
			
		||||
        return [];
 | 
			
		||||
    }	
 | 
			
		||||
    xCAT::PPC::preprocess_request(__PACKAGE__,@_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -67,6 +75,77 @@ sub process_request {
 | 
			
		||||
    xCAT::PPC::process_request(__PACKAGE__,@_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
##########################################################################
 | 
			
		||||
# get hcp and id for rcons with fsp
 | 
			
		||||
##########################################################################
 | 
			
		||||
sub getfspcon {
 | 
			
		||||
 
 | 
			
		||||
    my $node = shift;
 | 
			
		||||
	my $callback = shift;
 | 
			
		||||
    my @attribs = qw(id parent hcp);
 | 
			
		||||
    my %tabs    = ();
 | 
			
		||||
	my $rsp;
 | 
			
		||||
	
 | 
			
		||||
    ##################################
 | 
			
		||||
    # Open databases needed
 | 
			
		||||
    ##################################
 | 
			
		||||
    foreach ( qw(ppc vpd nodetype) ) {
 | 
			
		||||
        $tabs{$_} = xCAT::Table->new($_);
 | 
			
		||||
    
 | 
			
		||||
        if ( !exists( $tabs{$_} )) {
 | 
			
		||||
            #return( sprintf( $errmsg{DB_UNDEF}, $_ ));
 | 
			
		||||
			$rsp->{node}->[0]->{error}=["open table $_ error"];
 | 
			
		||||
            $rsp->{node}->[0]->{errorcode}=[1];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    #################################
 | 
			
		||||
    # Get node type
 | 
			
		||||
    #################################
 | 
			
		||||
    my $type = xCAT::DBobjUtils->getnodetype($node);
 | 
			
		||||
    #my ($type) = grep( /^(lpar|osi)$/, @types );
 | 
			
		||||
    
 | 
			
		||||
    if ( !defined( $type ) or !($type =~/^(lpar|osi)$/) ) {
 | 
			
		||||
        #return( "Invalid node type: $ent->{nodetype}" );
 | 
			
		||||
        $rsp->{node}->[0]->{error}=["Invalid node type: $type"];
 | 
			
		||||
        $rsp->{node}->[0]->{errorcode}=[1];		
 | 
			
		||||
    }
 | 
			
		||||
    #################################
 | 
			
		||||
    # Get attributes
 | 
			
		||||
    #################################
 | 
			
		||||
    my ($att) = $tabs{ppc}->getAttribs({'node'=>$node}, @attribs );
 | 
			
		||||
    
 | 
			
		||||
    if ( !defined( $att )) {
 | 
			
		||||
        #return( sprintf( $errmsg{NODE_UNDEF}, "ppc" ));
 | 
			
		||||
        $rsp->{node}->[0]->{error}=["node is not defined in ppc table"];
 | 
			
		||||
        $rsp->{node}->[0]->{errorcode}=[1];			
 | 
			
		||||
    }
 | 
			
		||||
    #################################
 | 
			
		||||
    # Verify required attributes
 | 
			
		||||
    #################################
 | 
			
		||||
    foreach my $at ( @attribs ) {
 | 
			
		||||
        if ( !exists( $att->{$at} )) {
 | 
			
		||||
            #return( sprintf( $errmsg{NO_ATTR}, $at, "ppc" ));
 | 
			
		||||
            $rsp->{node}->[0]->{error}=["Can't find node tarribute $at in ppc table"];
 | 
			
		||||
            $rsp->{node}->[0]->{errorcode}=[1];			   
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    my $fsp_name   = $att->{hcp};
 | 
			
		||||
    my $id = $att->{id};
 | 
			
		||||
	
 | 
			
		||||
    my $fsp_ip = xCAT::Utils::getNodeIPaddress( $fsp_name );
 | 
			
		||||
    if(!defined($fsp_ip)) {
 | 
			
		||||
        #return "Failed to get the $fsp_name\'s ip";
 | 
			
		||||
        $rsp->{node}->[0]->{error}=["Can't get node address"];
 | 
			
		||||
        $rsp->{node}->[0]->{errorcode}=[1];				
 | 
			
		||||
    }	
 | 
			
		||||
	
 | 
			
		||||
	$rsp = {node=>[{name=>[$node]}]};
 | 
			
		||||
	$rsp->{node}->[0]->{fsp_ip}->[0]=$fsp_ip;
 | 
			
		||||
    $rsp->{node}->[0]->{id}->[0]=$id;	
 | 
			
		||||
    $callback->($rsp);	
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user