mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 11:22:27 +00:00 
			
		
		
		
	Added descriptions to the db tables.
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@545 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -536,7 +536,7 @@ sub handle_response { | ||||
|   } | ||||
|  | ||||
|   # Handle {data} structure with no nodes | ||||
|   if (scalar @{$rsp->{data}}) { | ||||
|   if ($rsp->{data}) { | ||||
| #print "printing data\n"; | ||||
|     my $data=($rsp->{data}); | ||||
|     my $data_entry; | ||||
| @@ -556,9 +556,7 @@ sub handle_response { | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|       if ($desc) { | ||||
|          print "$desc\n"; | ||||
|       } | ||||
|       if ($desc) { print "$desc\n"; } | ||||
|     } | ||||
|   } | ||||
| }      # end of handle_response | ||||
|   | ||||
| @@ -212,54 +212,56 @@ sub message | ||||
|  | ||||
|     # Check that correct structure is filled in. If the data is not in the | ||||
|     # structure corresponding to the $sev,  then look for it in "data" | ||||
|     #TODO: this is not really right for a couple reasons:  1) all the fields in the | ||||
|     #TODO: this is not really right for a few reasons:  1) all the fields in the | ||||
|     #		response structure are arrays, so can handle multiple lines of text.  We | ||||
|     #		should not just be check the 0th element.  2) a cmd may have both error | ||||
|     #		text and data text.  3) this message() function should just take in a plain | ||||
|     #		string and put it in the correct place based on the severity. | ||||
|     if ($call_back) {    # callback routine provided | ||||
|     	my $sevkey; | ||||
|     	if ($sev =~ /I/) { $sevkey = 'info'; } | ||||
|     	if ($sev =~ /W/) { $sevkey = 'warning'; } | ||||
|     	if ($sev =~ /E/) { | ||||
|     	if ($sev =~ /D/) { $sevkey = 'data'; } | ||||
|     	elsif ($sev =~ /I/) { $sevkey = 'info'; } | ||||
|     	elsif ($sev =~ /W/) { $sevkey = 'warning'; } | ||||
|     	elsif ($sev =~ /E/) { | ||||
|     		$sevkey = 'error'; | ||||
|             if (!defined($exitcode)) { $exitcode = 1; }   # default to something non-zero | ||||
|     	} | ||||
|     	if (defined($sevkey)) { | ||||
|     	else { print "Internal Error: Invalid severity passed to MsgUtils::message().\n"; return 1; } | ||||
|  | ||||
|     	if ($sevkey ne 'data') { | ||||
|             if (!defined ($rsp->{$sevkey}) || !scalar(@{$rsp->{$sevkey}})) {   # did not pass the text in in the severity-specific field | ||||
|             	if (defined ($rsp->{data}) && scalar(@{$rsp->{data}})) { | ||||
|                 	push @{$rsp->{$sevkey}}, shift @{$rsp->{data}};    # assume they passed in the text in the data field instead | ||||
|                 	push @{$rsp->{$sevkey}}, @{$rsp->{data}};    # assume they passed in the text in the data field instead | ||||
|                 	@{$rsp->{data}} = ();     # clear out the data field | ||||
|             	} | ||||
|             } | ||||
|     	} | ||||
|     	if (!defined ($rsp->{$sevkey}) || !scalar(@{$rsp->{$sevkey}})) { return; }      # if still nothing in the array, there is nothing to print out | ||||
|  | ||||
|         if ($sev ne 'S')      # if sev is anything but only-syslog, print the msg | ||||
|         {                                   # not just syslog | ||||
|     		if ($exitcode) { $rsp->{errorcode}->[0] = $exitcode; } | ||||
|         if ($sev ne 'S') {     # if sev is anything but only-syslog, print the msg | ||||
|     		if ($exitcode) { push @{$rsp->{errorcode}}, $exitcode; } | ||||
|             $call_back->($rsp); # send message to daemon/Client.pm | ||||
|             shift @{$rsp->{$sevkey}};         # clear out the rsp structure in case they use it again | ||||
|             if ($exitcode) { shift @{$rsp->{errorcode}}; } | ||||
|             @{$rsp->{$sevkey}} = ();         # clear out the rsp structure in case they use it again | ||||
|             @{$rsp->{data}} = (); | ||||
|             @{$rsp->{errorcode}} = (); | ||||
|         } | ||||
| 	    # No need to support syslog writing when they specified a callback | ||||
|     } | ||||
|  | ||||
|     else                        # no callback provided | ||||
|     { | ||||
|         if ($sev ne 'S')        # syslog only | ||||
|         if ($sev ne 'S')        # it is not syslog only | ||||
|         { | ||||
|             print $stdouterrf $rsp;    # print the message | ||||
|  | ||||
|         } | ||||
| 	    if ($sev =~ /S/) { | ||||
|     		# If they want this msg to also go to syslog, do that now | ||||
|         	openlog("xCAT", '', 'local4'); | ||||
|         	syslog("err", $rsp); | ||||
|         	closelog(); | ||||
|     	} | ||||
|     } | ||||
|     if ($sev =~ /[S]/) | ||||
|     { | ||||
|  | ||||
|         # need to syslog , the message | ||||
|         openlog("xCAT", '', 'local4'); | ||||
|  | ||||
|         syslog("err", $rsp); | ||||
|         closelog(); | ||||
|     } | ||||
|     return 0; | ||||
|     return; | ||||
| } | ||||
|  | ||||
| 1; | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -26,7 +26,7 @@ use xCAT::NotifHandler; | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
|  | ||||
| =head1 xCAT::Table  | ||||
| =head1 xCAT::Table | ||||
|  | ||||
| xCAT::Table - Perl module for xCAT configuration access | ||||
|  | ||||
| @@ -68,13 +68,13 @@ xCAT::Table is released under an IBM license.... | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head2   Subroutines  | ||||
| =head2   Subroutines | ||||
|  | ||||
| =cut | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3   buildcreatestmt  | ||||
| =head3   buildcreatestmt | ||||
|  | ||||
|     Description:  Build create table statement ( see new) | ||||
|  | ||||
| @@ -82,13 +82,13 @@ xCAT::Table is released under an IBM license.... | ||||
|                 Table name | ||||
| 				Table schema ( hash of column names) | ||||
|     Returns: | ||||
|                 Table creation SQL  | ||||
|                 Table creation SQL | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|                 my $str = | ||||
|                   buildcreatestmt($self->{tabname}, | ||||
|                                   $xCAT::Schema::tabspec{$self->{tabname}}); | ||||
| @@ -123,10 +123,10 @@ sub buildcreatestmt | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3   new  | ||||
| =head3   new | ||||
|  | ||||
|     Description: Constructor: Connects to  or Creates Database Table | ||||
|   | ||||
|  | ||||
|  | ||||
|     Arguments:  Table name | ||||
|                 0 = Connect to table | ||||
| @@ -134,11 +134,11 @@ sub buildcreatestmt | ||||
|     Returns: | ||||
|                Hash: Database Handle, Statement Handle, nodelist | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|        $nodelisttab = xCAT::Table->new("nodelist");  | ||||
|        $nodelisttab = xCAT::Table->new("nodelist"); | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -157,6 +157,7 @@ sub new | ||||
|     unless (defined($xCAT::Schema::tabspec{$self->{tabname}})) { return undef; } | ||||
|     $self->{schema}   = $xCAT::Schema::tabspec{$self->{tabname}}; | ||||
|     $self->{colnames} = \@{$self->{schema}->{cols}}; | ||||
|     $self->{descriptions} = \%{$self->{schema}->{descriptions}}; | ||||
|     my %otherargs  = @_; | ||||
|     my $create     = $otherargs{'-create'};      #(scalar(@_) == 1 ? shift : 0); | ||||
|     $self->{autocommit} = $otherargs{'-autocommit'}; | ||||
| @@ -216,7 +217,7 @@ sub new | ||||
|         #return undef; | ||||
|     } | ||||
|     unless ($::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}}) { #= $self->{tabname}; | ||||
|       $::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}} =  | ||||
|       $::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}} = | ||||
|         DBI->connect($self->{connstring}, $self->{dbuser}, $self->{dbpass}, {AutoCommit => $self->{autocommit}}); | ||||
|      } | ||||
|  | ||||
| @@ -280,7 +281,7 @@ sub new | ||||
| 	} | ||||
|      } | ||||
|  | ||||
| 	 | ||||
|  | ||||
|     updateschema($self); | ||||
|     if ($self->{tabname} eq 'nodelist') | ||||
|     { | ||||
| @@ -296,23 +297,23 @@ sub new | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3  updateschema  | ||||
| =head3  updateschema | ||||
|  | ||||
|     Description: Alters table schema | ||||
|  | ||||
|     Arguments: Hash containing Database and Table Handle and schema | ||||
|          | ||||
|  | ||||
|     Returns: None | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
| 		  $self->{tabname} = shift; | ||||
|           $self->{schema}   = $xCAT::Schema::tabspec{$self->{tabname}}; | ||||
|           $self->{colnames} = \@{$self->{schema}->{cols}}; | ||||
|           updateschema($self);         | ||||
|           updateschema($self); | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -384,11 +385,11 @@ sub updateschema | ||||
|                Node name | ||||
| 			   Attribute hash | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|        my $mactab = xCAT::Table->new('mac',-create=>1); | ||||
| 	   $mactab->setNodeAttribs($node,{mac=>$mac}); | ||||
| @@ -414,15 +415,15 @@ sub setNodeAttribs | ||||
|     Description: Add new attributes input to the routine to the nodes | ||||
|  | ||||
|     Arguments: | ||||
|            Hash of new attributes           | ||||
|            Hash of new attributes | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -441,19 +442,19 @@ sub addNodeAttribs | ||||
|  | ||||
|     Description: add new attributes | ||||
|  | ||||
|     Arguments:  | ||||
|     Arguments: | ||||
|                Hash: Database Handle, Statement Handle, nodelist | ||||
|                Key name | ||||
| 		       Key value | ||||
| 			   Hash reference of column-value pairs to set | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -513,22 +514,22 @@ sub addAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 rollback  | ||||
| =head3 rollback | ||||
|  | ||||
|     Description:  rollback changes | ||||
|  | ||||
|     Arguments: | ||||
|               Database Handle | ||||
|     Returns: | ||||
|            none  | ||||
|            none | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|  | ||||
|        my $tab = xCAT::Table->new($table,-create =>1,-autocommit=>0); | ||||
| 	   $tab->rollback();	 | ||||
| 	   $tab->rollback(); | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
| @@ -544,22 +545,22 @@ sub rollback | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 commit  | ||||
| =head3 commit | ||||
|  | ||||
|     Description: | ||||
|              Commit changes | ||||
|     Arguments: | ||||
|         Database Handle | ||||
|     Returns: | ||||
|        none  | ||||
|        none | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|        my $tab = xCAT::Table->new($table,-create =>1,-autocommit=>0); | ||||
| 	   $tab->commit();	 | ||||
|          | ||||
| 	   $tab->commit(); | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -574,7 +575,7 @@ sub commit | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 setAttribs  | ||||
| =head3 setAttribs | ||||
|  | ||||
|     Description: | ||||
|  | ||||
| @@ -584,11 +585,11 @@ sub commit | ||||
| 		 Hash reference of column-value pairs to set | ||||
|  | ||||
|     Returns: | ||||
|          None     | ||||
|          None | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|        my $tab = xCAT::Table->new( 'ppc', -create=>1, -autocommit=>0 ); | ||||
| 	   $keyhash{'node'}    = $name; | ||||
| @@ -758,7 +759,7 @@ sub setAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 setAttribsWhere  | ||||
| =head3 setAttribsWhere | ||||
|  | ||||
|     Description: | ||||
|        This function sets the attributes for the rows selected by the where clause. | ||||
| @@ -766,9 +767,9 @@ sub setAttribs | ||||
|          Where clause. | ||||
| 	 Hash reference of column-value pairs to set | ||||
|     Returns: | ||||
|          None     | ||||
|     Globals:         | ||||
|     Error:         | ||||
|          None | ||||
|     Globals: | ||||
|     Error: | ||||
|     Example: | ||||
|        my $tab = xCAT::Table->new( 'ppc', -create=>1, -autocommit=>1 ); | ||||
| 	   $updates{'type'}    = lc($type); | ||||
| @@ -859,24 +860,24 @@ sub setAttribsWhere | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getNodeAttribs  | ||||
| =head3 getNodeAttribs | ||||
|  | ||||
|     Description: Retrieves the requested attribute  | ||||
|     Description: Retrieves the requested attribute | ||||
|  | ||||
|     Arguments: | ||||
|             Table handle | ||||
| 			Noderange | ||||
| 	        Attribute type array	 | ||||
| 	        Attribute type array | ||||
|     Returns: | ||||
|         | ||||
| 			Attribute hash ( key attribute type)  | ||||
|  | ||||
| 			Attribute hash ( key attribute type) | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|            my $ostab = xCAT::Table->new('nodetype'); | ||||
| 		   my $ent = $ostab->getNodeAttribs($node,['profile','os','arch']);	 | ||||
| 		   my $ent = $ostab->getNodeAttribs($node,['profile','os','arch']); | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
| @@ -956,20 +957,20 @@ sub getNodeAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getNodeAttribs_nosub   | ||||
| =head3 getNodeAttribs_nosub | ||||
|  | ||||
|     Description: | ||||
|  | ||||
|     Arguments: | ||||
|          | ||||
|  | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1016,20 +1017,20 @@ sub getNodeAttribs_nosub | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getNodeAttribs_nosub_returnany   | ||||
| =head3 getNodeAttribs_nosub_returnany | ||||
|  | ||||
|     Description: | ||||
|  | ||||
|     Arguments: | ||||
|          | ||||
|  | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1080,23 +1081,23 @@ sub getNodeAttribs_nosub_returnany | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getAllEntries   | ||||
| =head3 getAllEntries | ||||
|  | ||||
|     Description:  Read entire table | ||||
|  | ||||
|     Arguments: | ||||
|            Table handle  | ||||
|            Table handle | ||||
|     Returns: | ||||
|        Hash containing all rows in table   | ||||
|        Hash containing all rows in table | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|  | ||||
| 	 my $tabh = xCAT::Table->new($table); | ||||
| 	 my $recs=$tabh->getAllEntries(); | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1126,7 +1127,7 @@ sub getAllEntries | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getAllAttribsWhere   | ||||
| =head3 getAllAttribsWhere | ||||
|  | ||||
|     Description:  Get all attributes with "where" clause | ||||
|  | ||||
| @@ -1134,13 +1135,13 @@ sub getAllEntries | ||||
|        Database Handle | ||||
|        Where clause | ||||
|     Returns: | ||||
|         Array of attributes      | ||||
|         Array of attributes | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|     $nodelist->getAllAttribsWhere("groups like '%".$atom."%'",'node','group');  | ||||
|     $nodelist->getAllAttribsWhere("groups like '%".$atom."%'",'node','group'); | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1183,7 +1184,7 @@ sub getAllAttribsWhere | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getAllNodeAttribs    | ||||
| =head3 getAllNodeAttribs | ||||
|  | ||||
|     Description: Get all the node attributes values for the input table on the | ||||
| 				 attribute list | ||||
| @@ -1194,9 +1195,9 @@ sub getAllAttribsWhere | ||||
|     Returns: | ||||
|                  Array of attribute values | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          my @entries = $self->{switchtab}->getAllNodeAttribs(['port','switch']); | ||||
|     Comments: | ||||
| @@ -1259,7 +1260,7 @@ sub getAllNodeAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getAllAttribs    | ||||
| =head3 getAllAttribs | ||||
|  | ||||
|     Description: Returns a list of records in the input table for the input | ||||
| 				 list of attributes. | ||||
| @@ -1270,9 +1271,9 @@ sub getAllNodeAttribs | ||||
|     Returns: | ||||
|         Array of attribute values | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|         $nodelisttab = xCAT::Table->new("nodelist"); | ||||
| 		my @attribs = ("node"); | ||||
| @@ -1316,7 +1317,7 @@ sub getAllAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 delEntries     | ||||
| =head3 delEntries | ||||
|  | ||||
|     Description:  Delete table entries | ||||
|  | ||||
| @@ -1324,11 +1325,11 @@ sub getAllAttribs | ||||
|                 Table Handle | ||||
|                 Entry to delete | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
| 	my $table=xCAT::Table->new("notification", -create => 1,-autocommit => 0); | ||||
| 	my %key_col = (filename=>$fname); | ||||
| @@ -1408,7 +1409,7 @@ sub delEntries | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getAttribs     | ||||
| =head3 getAttribs | ||||
|  | ||||
|     Description: | ||||
|  | ||||
| @@ -1416,11 +1417,11 @@ sub delEntries | ||||
|                key | ||||
| 			   List of attributes | ||||
|     Returns: | ||||
|                Hash of requested attributes  | ||||
|                Hash of requested attributes | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|         $table = xCAT::Table->new('passwd'); | ||||
| 		@tmp=$table->getAttribs({'key'=>'ipmi'},('username','password'); | ||||
| @@ -1497,7 +1498,7 @@ sub getAttribs | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 getTable     | ||||
| =head3 getTable | ||||
|  | ||||
|     Description:  Read entire Table | ||||
|  | ||||
| @@ -1505,11 +1506,11 @@ sub getAttribs | ||||
|                 Table Handle | ||||
|  | ||||
|     Returns: | ||||
|                 Array of table rows        | ||||
|                 Array of table rows | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|                   my $table=xCAT::Table->new("notification", -create =>0); | ||||
| 				  my @row_array= $table->getTable; | ||||
| @@ -1556,18 +1557,18 @@ sub getTable | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 close     | ||||
| =head3 close | ||||
|  | ||||
|     Description: Close out Table transaction | ||||
|  | ||||
|     Arguments: | ||||
|                 Table Handle        | ||||
|                 Table Handle | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|                   my $mactab = xCAT::Table->new('mac'); | ||||
| 				  $mactab->setNodeAttribs($macmap{$mac},{mac=>$mac}); | ||||
| @@ -1592,20 +1593,20 @@ sub close | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 open     | ||||
| =head3 open | ||||
|  | ||||
|     Description: Connect to Database | ||||
|  | ||||
|     Arguments: | ||||
|            Empty Hash         | ||||
|            Empty Hash | ||||
|     Returns: | ||||
|            Data Base Handle        | ||||
|            Data Base Handle | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1620,20 +1621,20 @@ sub open | ||||
|  | ||||
| #-------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 DESTROY     | ||||
| =head3 DESTROY | ||||
|  | ||||
|     Description:  Disconnect from Database | ||||
|  | ||||
|     Arguments: | ||||
|               Database Handle      | ||||
|               Database Handle | ||||
|     Returns: | ||||
|          | ||||
|  | ||||
|     Globals: | ||||
|          | ||||
|  | ||||
|     Error: | ||||
|          | ||||
|  | ||||
|     Example: | ||||
|          | ||||
|  | ||||
|     Comments: | ||||
|         none | ||||
|  | ||||
| @@ -1649,5 +1650,33 @@ sub DESTROY | ||||
|     undef $self->{nodelist};    #Could be circular | ||||
| } | ||||
|  | ||||
|  | ||||
| =head3 getTableList | ||||
| 	Description: Returns a list of the table names in the xCAT database. | ||||
| =cut | ||||
| sub getTableList { return keys %xCAT::Schema::tabspec; } | ||||
|  | ||||
|  | ||||
| =head3 getTableSchema | ||||
| 	Description: Returns the db schema for the specified table. | ||||
| 	Returns: A reference to a hash that contains the cols, keys, etc. for this table. (See Schema.pm for details.) | ||||
| =cut | ||||
| sub getTableSchema { return $xCAT::Schema::tabspec{$_[1]}; } | ||||
|  | ||||
|  | ||||
| =head3 getTableList | ||||
| 	Description: Returns a summary description for each table. | ||||
| 	Returns: A reference to a hash.  Each key is the table name. | ||||
| 			Each value is the table description. | ||||
| =cut | ||||
| sub getDescriptions { | ||||
| 	my $classname = shift;     # we ignore this because this function is static | ||||
| 	# List each table name and the value for table_desc. | ||||
| 	my $ret = {}; | ||||
| 	#my @a = keys %{$xCAT::Schema::tabspec{nodelist}};  print 'a=', @a, "\n"; | ||||
| 	foreach my $t (keys %xCAT::Schema::tabspec) { $ret->{$t} = $xCAT::Schema::tabspec{$t}->{table_desc}; } | ||||
| 	return $ret; | ||||
| } | ||||
|  | ||||
| 1; | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ use lib "$::XCATROOT/lib/perl"; | ||||
|  | ||||
| use File::Basename; | ||||
| use xCAT::MsgUtils; | ||||
| use xCAT::Client submit_request; | ||||
| use xCAT::Client; | ||||
|  | ||||
| my $bname = basename($0); | ||||
|  | ||||
| @@ -25,7 +25,7 @@ my $bname = basename($0); | ||||
| #		are, for the most part, in: | ||||
| #			/opt/xcat/lib/perl/xCAT_plugin/DBobjectdefs.pm | ||||
| #			/opt/xcat/lib/perl/xCAT_plugin/xcat2nim.pm | ||||
| #			/opt/xcat/lib/perl/xCAT/DBobjUtils.pm  | ||||
| #			/opt/xcat/lib/perl/xCAT/DBobjUtils.pm | ||||
| #		-on the xCAT management node | ||||
| # | ||||
| ######################################### | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| #!/usr/bin/perl | ||||
| #  !/usr/bin/env perl | ||||
| #!/usr/bin/env perl | ||||
| # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html | ||||
| BEGIN | ||||
| { | ||||
|   | ||||
| @@ -4,19 +4,21 @@ B<tabdump> - display a database table in csv format. | ||||
|  | ||||
| =head1 SYNOPSIS | ||||
|  | ||||
| I<tabdump [table]> | ||||
| I<tabdump [-d] [table]> | ||||
|  | ||||
| I<tabdump [? | -h | --help]> | ||||
|  | ||||
| =head1 DESCRIPTION | ||||
|  | ||||
| The tabdump command displays the header and all the rows of the specified table in csv format. | ||||
| The tabdump command displays the header and all the rows of the specified table in CSV (comma separated values) format. | ||||
| Only one table can be specified.  If no table is specified, the list of existing | ||||
| tables will be displayed. | ||||
|  | ||||
| =head1 OPTIONS | ||||
|  | ||||
| B<-?|-h|--help>          Display usage message. | ||||
| B<-?|-h|--help>    Display usage message. | ||||
|  | ||||
| B<-d>              Show descriptions of the tables, instead of the contents of the tables.  If a table name is also specified, descriptions of the columns (attributes) of the table will be displayed.  Otherwise, a summary of each table will be displayed. | ||||
|  | ||||
| =head1 RETURN VALUE | ||||
|  | ||||
| @@ -34,11 +36,19 @@ B<-?|-h|--help>          Display usage message. | ||||
|  | ||||
|   tabdump | ||||
|  | ||||
| 3. To see what tables exist in the xCAT database: | ||||
| 3. To back up all the xCAT database tables: | ||||
|  | ||||
|   mkdir -p /tmp/xcatdb.backup | ||||
|   for i in `tabdump`;do echo "Dumping $i..."; tabdump $i > /tmp/xcatdb.backup/$i.csv; done | ||||
|  | ||||
| 4. To display a summary description of each table: | ||||
|  | ||||
|   tabdump -d | ||||
|  | ||||
| 5. To display a description of each column in the nodehm table: | ||||
|  | ||||
|   tabdump -d nodehm | ||||
|  | ||||
| =head1 FILES | ||||
|  | ||||
| /opt/xcat/sbin/tabdump | ||||
|   | ||||
| @@ -129,22 +129,24 @@ | ||||
| .\" ======================================================================== | ||||
| .\" | ||||
| .IX Title "TABDUMP.1 1" | ||||
| .TH TABDUMP.1 1 "2008-02-18" "perl v5.8.8" "User Contributed Perl Documentation" | ||||
| .TH TABDUMP.1 1 "2008-02-20" "perl v5.8.8" "User Contributed Perl Documentation" | ||||
| .SH "NAME" | ||||
| \&\fBtabdump\fR \- display a database table in csv format. | ||||
| .SH "SYNOPSIS" | ||||
| .IX Header "SYNOPSIS" | ||||
| \&\fItabdump [table]\fR | ||||
| \&\fItabdump [\-d] [table]\fR | ||||
| .PP | ||||
| \&\fItabdump [? | \-h | \-\-help]\fR | ||||
| .SH "DESCRIPTION" | ||||
| .IX Header "DESCRIPTION" | ||||
| The tabdump command displays the header and all the rows of the specified table in csv format. | ||||
| The tabdump command displays the header and all the rows of the specified table in \s-1CSV\s0 (comma separated values) format. | ||||
| Only one table can be specified.  If no table is specified, the list of existing | ||||
| tables will be displayed. | ||||
| .SH "OPTIONS" | ||||
| .IX Header "OPTIONS" | ||||
| \&\fB\-?|\-h|\-\-help\fR          Display usage message. | ||||
| \&\fB\-?|\-h|\-\-help\fR    Display usage message. | ||||
| .PP | ||||
| \&\fB\-d\fR              Show descriptions of the tables, instead of the contents of the tables.  If a table name is also specified, descriptions of the columns (attributes) of the table will be displayed.  Otherwise, a summary of each table will be displayed. | ||||
| .SH "RETURN VALUE" | ||||
| .IX Header "RETURN VALUE" | ||||
| 0 The command completed successfully. | ||||
| @@ -164,12 +166,24 @@ tables will be displayed. | ||||
| \&  tabdump | ||||
| .Ve | ||||
| .PP | ||||
| 3. To see what tables exist in the xCAT database: | ||||
| 3. To back up all the xCAT database tables: | ||||
| .PP | ||||
| .Vb 2 | ||||
| \&  mkdir -p /tmp/xcatdb.backup | ||||
| \&  for i in `tabdump`;do echo "Dumping $i..."; tabdump $i > /tmp/xcatdb.backup/$i.csv; done | ||||
| .Ve | ||||
| .PP | ||||
| 4. To display a summary description of each table: | ||||
| .PP | ||||
| .Vb 1 | ||||
| \&  tabdump -d | ||||
| .Ve | ||||
| .PP | ||||
| 5. To display a description of each column in the nodehm table: | ||||
| .PP | ||||
| .Vb 1 | ||||
| \&  tabdump -d nodehm | ||||
| .Ve | ||||
| .SH "FILES" | ||||
| .IX Header "FILES" | ||||
| /opt/xcat/sbin/tabdump | ||||
|   | ||||
| @@ -52,7 +52,7 @@ $Getopt::Long::ignorecase = 0; | ||||
|  | ||||
| =head1    DBobjectdefs | ||||
|  | ||||
| This program module file supports the management of the xCAT data object  | ||||
| This program module file supports the management of the xCAT data object | ||||
| definitions. | ||||
|  | ||||
| Supported xCAT data object commands: | ||||
| @@ -108,12 +108,12 @@ sub handled_commands | ||||
|         Check for xCAT command and call the appropriate subroutine. | ||||
|  | ||||
|         Arguments: | ||||
|                  | ||||
|  | ||||
|         Returns: | ||||
|                 0 - OK | ||||
|                 1 - error | ||||
|         Globals: | ||||
|                 | ||||
|  | ||||
|         Error: | ||||
|  | ||||
|         Example: | ||||
| @@ -179,7 +179,7 @@ sub process_request | ||||
|                 1 - just print usage | ||||
| 				2 - error | ||||
|         Globals: | ||||
|                  | ||||
|  | ||||
|         Error: | ||||
|  | ||||
|         Example: | ||||
| @@ -194,7 +194,7 @@ sub processArgs | ||||
|     my $gotattrs = 0; | ||||
|  | ||||
|     @ARGV = @{$::args}; | ||||
|      | ||||
|  | ||||
|     if (scalar(@ARGV) <= 0) { | ||||
|         return 2; | ||||
|     } | ||||
| @@ -426,8 +426,7 @@ sub processArgs | ||||
|  | ||||
|             } | ||||
|             my $rsp; | ||||
|             $rsp->{data}->[0] = | ||||
|               "\nThe valid attribute names for object type \'$t\' are:\n\n"; | ||||
|             $rsp->{data}->[0] = "The valid attribute names for object type '$t' are:\n"; | ||||
|  | ||||
|             # get the data type  definition from Schema.pm | ||||
|             my $datatype = $xCAT::Schema::defspec{$t}; | ||||
| @@ -444,20 +443,27 @@ sub processArgs | ||||
|             { | ||||
|                 my $attr = $this_attr->{attr_name}; | ||||
|                 my $desc = $this_attr->{description}; | ||||
|                 if (!defined($desc)) {     # description key not there, so go to the corresponding entry in tabspec to get the description | ||||
|                 	my ($tab, $at) = split(/\./, $this_attr->{tabentry}); | ||||
|                 	my $schema = xCAT::Table->getTableSchema($tab); | ||||
|                 	$desc = $schema->{descriptions}->{$at}; | ||||
|                 } | ||||
|  | ||||
| 				# could display the table that the attr is in  | ||||
| 				# could display the table that the attr is in | ||||
| 				# however some attrs are in more than one table!!! | ||||
| 				my ($tab, $junk) = split('\.', $this_attr->{tabentry}); | ||||
| 				#my ($tab, $junk) = split('\.', $this_attr->{tabentry}); | ||||
|  | ||||
|                 if (!grep(/^$attr$/, @alreadydone)) | ||||
|                 {    | ||||
|                 { | ||||
|                 #    $outstr .= "$attr\n\t\t- $desc \n\t\t(Table: $tab)\n\n"; | ||||
| 					$outstr .= "$attr\n\t\t- $desc\n\n"; | ||||
| 			 | ||||
| 					#$outstr .= "$attr\n\t\t- $desc\n\n"; | ||||
| 					my $space = (length($attr)<7 ? "\t\t" : "\t"); | ||||
| 					$outstr .= "$attr:$space$desc\n\n"; | ||||
|                 } | ||||
|                 push(@alreadydone, $attr); | ||||
|             } | ||||
|              | ||||
|  | ||||
| 			chop($outstr);  chop($outstr); | ||||
|             $rsp->{data}->[2] = $outstr; | ||||
|             xCAT::MsgUtils->message("I", $rsp, $::callback); | ||||
|         } | ||||
| @@ -479,10 +485,10 @@ sub processArgs | ||||
|         if (($::opt_t eq 'site') && ($::opt_o ne 'clustersite')) | ||||
|         { | ||||
|             push(@::clobjnames, 'clustersite'); | ||||
| 			my $rsp;   | ||||
| 			my $rsp; | ||||
|             $rsp->{data}->[0] ="Only one site definition is supported."; | ||||
| 			$rsp->{data}->[1] = "Setting the name of the site definition to \'clustersite\'.\n"; | ||||
|             xCAT::MsgUtils->message("I", $rsp, $::callback);	 | ||||
|             xCAT::MsgUtils->message("I", $rsp, $::callback); | ||||
|  | ||||
|         } | ||||
|         elsif ($::opt_t eq 'node') | ||||
| @@ -515,7 +521,7 @@ sub processArgs | ||||
|     # special case for site table!!!!!!!!!!!!!! | ||||
|     if (($::opt_t eq 'site') && !$::opt_o) | ||||
|     { | ||||
| 		my $rsp;    | ||||
| 		my $rsp; | ||||
|         $rsp->{data}->[0] ="Setting the name of the site definition to \'clustersite\'."; | ||||
|         xCAT::MsgUtils->message("I", $rsp, $::callback); | ||||
|         push(@::clobjnames, 'clustersite'); | ||||
| @@ -700,7 +706,7 @@ sub processArgs | ||||
|         Example: | ||||
|  | ||||
|         Comments: | ||||
| 			Object names to create are derived from  | ||||
| 			Object names to create are derived from | ||||
| 				-o, -t, w, -z, -x, or noderange! | ||||
| 			Attr=val pairs come from cmd line args or -z/-x files | ||||
| =cut | ||||
| @@ -1147,7 +1153,7 @@ sub defmk | ||||
|         Example: | ||||
|  | ||||
|         Comments: | ||||
| 			Object names to create are derived from  | ||||
| 			Object names to create are derived from | ||||
| 				-o, -t, w, -z, -x, or noderange! | ||||
| 			Attr=val pairs come from cmd line args or -z/-x files | ||||
| =cut | ||||
| @@ -1878,7 +1884,7 @@ sub setFINALattrs | ||||
| 			Object names derived from -o, -t, w, -a or noderange! | ||||
|             List of attrs to display is given by -i. | ||||
|             Output goes to standard out or a stanza/xml file (-z or -x) | ||||
| 		 | ||||
|  | ||||
| =cut | ||||
|  | ||||
| #----------------------------------------------------------------------------- | ||||
| @@ -2442,7 +2448,7 @@ sub defls | ||||
|                 0 - OK | ||||
|                 1 - error | ||||
|         Globals: | ||||
|             | ||||
|  | ||||
|         Error: | ||||
|  | ||||
|         Example: | ||||
|   | ||||
| @@ -345,11 +345,12 @@ sub tabdump | ||||
|     my $cb    = shift; | ||||
|     my $table = ""; | ||||
|     my $HELP; | ||||
|     my $DESC; | ||||
|  | ||||
|     sub tabdump_usage { | ||||
|     	my $exitcode = shift @_; | ||||
|         my %rsp; | ||||
|         push @{$rsp{data}}, "Usage: tabdump [table]"; | ||||
|         push @{$rsp{data}}, "Usage: tabdump [-d] [table]"; | ||||
|         push @{$rsp{data}}, "       tabdump [-?|-h|--help]"; | ||||
|         if ($exitcode) { $rsp{errorcode} = $exitcode; } | ||||
|         $cb->(\%rsp); | ||||
| @@ -357,7 +358,7 @@ sub tabdump | ||||
|  | ||||
| 	# Process arguments | ||||
|     @ARGV = @{$args}; | ||||
|     if (!GetOptions('h|?|help'  => \$HELP)) { tabdump_usage(1); return; } | ||||
|     if (!GetOptions('h|?|help' => \$HELP, 'd' => \$DESC)) { tabdump_usage(1); return; } | ||||
|  | ||||
|     if ($HELP) { tabdump_usage(0); return; } | ||||
|     if (scalar(@ARGV)>1) { tabdump_usage(1); return; } | ||||
| @@ -365,12 +366,35 @@ sub tabdump | ||||
|     my %rsp; | ||||
|     # If no arguments given, we display a list of the tables | ||||
|     if (!scalar(@ARGV)) { | ||||
|     	push @{$rsp{data}}, keys %xCAT::Schema::tabspec; | ||||
|     	if ($DESC) {  # display the description of each table | ||||
|     		my $tab = xCAT::Table->getDescriptions(); | ||||
|     		foreach my $key (keys %$tab) { | ||||
|     			my $space = (length($key)<7 ? "\t\t" : "\t"); | ||||
|     			push @{$rsp{data}}, "$key:$space".$tab->{$key}."\n"; | ||||
|     		} | ||||
|     	} | ||||
|     	else { push @{$rsp{data}}, xCAT::Table->getTableList(); }   # if no descriptions, just display the list of table names | ||||
|     	@{$rsp{data}} = sort @{$rsp{data}}; | ||||
| 		if ($DESC && scalar(@{$rsp{data}})) { chop($rsp{data}->[scalar(@{$rsp{data}})-1]); }   # remove the final newline | ||||
|         $cb->(\%rsp); | ||||
|     	return; | ||||
|     } | ||||
|  | ||||
|     $table = $ARGV[0]; | ||||
|     if ($DESC) {     # only show the attribute descriptions, not the values | ||||
|     	my $schema = xCAT::Table->getTableSchema($table); | ||||
|     	if (!$schema) { $cb->({error => "table $table does not exist.",errorcode=>1}); return; } | ||||
| 		my $desc = $schema->{descriptions}; | ||||
| 		foreach my $c (@{$schema->{cols}}) { | ||||
| 			my $space = (length($c)<7 ? "\t\t" : "\t"); | ||||
| 			push @{$rsp{data}}, "$c:$space".$desc->{$c}."\n"; | ||||
| 		} | ||||
| 		if (scalar(@{$rsp{data}})) { chop($rsp{data}->[scalar(@{$rsp{data}})-1]); }   # remove the final newline | ||||
|         $cb->(\%rsp); | ||||
| 		return; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     my $tabh = xCAT::Table->new($table); | ||||
|  | ||||
|     sub tabdump_header { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user