add the loadclouddata, share/xcat/mypostscript/mypostscript_cloud.tmpl into xCAT-OpenStack
This commit is contained in:
		
							
								
								
									
										224
									
								
								xCAT-OpenStack/postscripts/loadclouddata
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										224
									
								
								xCAT-OpenStack/postscripts/loadclouddata
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,224 @@ | ||||
| #!/bin/sh  | ||||
| # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html | ||||
|  | ||||
| # This script, ("loadclouddata"), is a sample xCAT post script for  | ||||
| #	upload the openstack-cookbooks, roles, enviornment to the  | ||||
| #       xCAT chef-server node, and then create the chef-client  | ||||
| #        nodes, and then assign the role and environment name to the | ||||
| #       chef-client nodes   | ||||
| # | ||||
| #	Make sure your script is executable and that is is in the  | ||||
| #	/install/postscripts directory on the xCAT management node. | ||||
| # | ||||
| #	You must add the script name to the list of scripts that  | ||||
| #	must be run at install time,  or use it with updatenode. | ||||
| # | ||||
| # 	To use this script you should make sure it gets run after the  | ||||
| #	"mountinstall" script or any other scipts that may need to use | ||||
| #       scripts in the /install directory. | ||||
| #	 | ||||
| #	For example, to get it to run after the "mountinstall" script you | ||||
| #	could set the "postbootscripts" attribute of the chef-server node | ||||
| #	definitions as follows: | ||||
| # | ||||
| #	chdef -t node -o chef-server postbootscripts="mountinstall,loadclouddata"	 | ||||
| # | ||||
|  | ||||
|  | ||||
| ## defined HASH functions here | ||||
| hput() { | ||||
|     eval "HASH""$1""$2"='$3' | ||||
| } | ||||
|  | ||||
| hget() { | ||||
|     eval echo '${'"HASH$1$2"'}' | ||||
| } | ||||
|  | ||||
| hkeys() { | ||||
|     set | grep -o "^HASH${1}[[:alnum:]]*=" | sed -re "s/^HASH${1}(.*)=/\\1/g" | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| #flags | ||||
| no_args=0 | ||||
| only_load_cookbook=0 | ||||
| only_load_role=0 | ||||
| only_load_clouddata=0 | ||||
|  | ||||
| if [ $# -eq 0 ] | ||||
| then | ||||
|     no_args=1 | ||||
| else | ||||
|   for arg in "$@" | ||||
|   do | ||||
|     if [ "$arg" = "--cookbook" ] | ||||
|     then | ||||
|         only_load_cookbook=1 | ||||
|     elif [ "$arg" = "--role" ] | ||||
|     then | ||||
|         only_load_role=1 | ||||
|     elif [ "$arg" = "--clouddata" ] | ||||
|     then | ||||
|         only_load_clouddata=1 | ||||
|     else  | ||||
|         errmsg="no argument $arg in the loadchefdata script" | ||||
|         logger -t xcat -p local4.err $errmsg | ||||
|         echo $errmsg | ||||
|         exit 1 | ||||
|     fi | ||||
|   done | ||||
| fi | ||||
|  | ||||
|  | ||||
|  | ||||
| # enter the repository director | ||||
| # for example: cd /install/chef-cookbooks/grizzy-xcat/ | ||||
| if [ ! -d "$REPOSITORY" ]  | ||||
| then | ||||
|     errmsg="$REPOSITORY is not a OpenStack Chef cookbooks directory." | ||||
|     logger -t xcat -p local4.err $errmsg | ||||
|     echo $errmsg | ||||
|     exit 1 | ||||
| fi | ||||
| cd $REPOSITORY | ||||
|  | ||||
| if [ $no_args -eq 1 -o $only_load_cookbook -eq 1 ] | ||||
| then | ||||
|    # upload coobooks | ||||
|    knife cookbook bulk delete '.*' -y  > /dev/null 2>&1 | ||||
|    knife cookbook upload -o cookbooks --all | ||||
|    if [ $? != 0 ] | ||||
|    then   | ||||
|        errmsg="Failed to run knife cookbook upload -o cookbooks --all on the chefserver $NODE." | ||||
|        logger -t xcat -p local4.err $errmsg | ||||
|        echo $errmsg | ||||
|        exit 1 | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| if [ $no_args -eq 1 -o $only_load_role -eq 1 ] | ||||
| then | ||||
|     # upload roles | ||||
|     knife role bulk delete '.*' -y  > /dev/null 2>&1 | ||||
|     knife role from file roles/*.rb | ||||
|     if [ $? != 0 ] | ||||
|     then   | ||||
|        errmsg="Failed to run knife role from file roles/*.rb  on the chefserver $NODE." | ||||
|        logger -t xcat -p local4.err $errmsg | ||||
|        echo $errmsg | ||||
|        exit 1 | ||||
|     fi | ||||
|  | ||||
| fi | ||||
|  | ||||
|  | ||||
| if [ $no_args -eq 1 -o $only_load_clouddata -eq 1 ] | ||||
| then | ||||
|  | ||||
|     if [ -z $CFGCLIENTLIST ] | ||||
|     then | ||||
|         msg="No cfgclient on the cfgserver $NODE?" | ||||
|         logger -t xcat -p local3.info $msg | ||||
|         echo $errmsg | ||||
|         exit 0 | ||||
|     fi | ||||
|  | ||||
|     #CLOUDLIST='cloud1,cloud1,cloud3' | ||||
|     OIFS=$IFS | ||||
|     IFS=',' | ||||
|     for cloud in $CLOUDLIST | ||||
|     do | ||||
|         echo "loading the enviornment file $cloud.rb for $cloud" | ||||
|         # knife environment delete xcat_per-tenant_routers_with_private_networks  -y | ||||
|         # knife environment delete xcat_per-tenant_routers_with_private_networks  -y | ||||
|         # load the environment file  | ||||
|         # knife environment from file environments/xcat_per-tenant_routers_with_private_networks.rb | ||||
|         if [ ! -e "$REPOSITORY/environments/$cloud.rb" ]  | ||||
|         then | ||||
|             errmsg="$REPOSITORY/environments/$cloud.rb doesn't exsit. run mkclouddata at first." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|         knife environment from file environments/$cloud.rb | ||||
|         if [ $? != 0 ] | ||||
|         then   | ||||
|             errmsg="Failed to run knife environment from file environments/$cloud.rb on the chef-server $NODE." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|     done | ||||
|     #IFS=$OIFS | ||||
|  | ||||
|     #CFGCLIENTLIST='node1,node1,node3' | ||||
|     #OIFS=$IFS | ||||
|     #IFS=',' | ||||
|     for client in $CFGCLIENTLIST | ||||
|     do | ||||
|         echo "Configuring the chef-client node $client on the chef-server $NODE." | ||||
|         c_fullname="$client.$DOMAIN" | ||||
|         knife client delete -y $c_fullname  > /dev/null 2>&1 | ||||
|         knife node delete -y $c_fullname    > /dev/null 2>&1 | ||||
|  | ||||
|         #create nodes on this chef-server | ||||
|         # knife node create test3 -d | ||||
|         knife node create $c_fullname -d | ||||
|         if [ $? != 0 ] | ||||
|         then   | ||||
|             errmsg="Failed to run knife node create $client -d on the chef-server $NODE." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|  | ||||
|         roles=`hget $client roles` | ||||
|         if [ -z $roles ]  | ||||
|         then | ||||
|             errmsg="No roles for $client. Please check the cfgmgt table." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|  | ||||
|         # assign the role for the chef node | ||||
|         knife node run_list add $c_fullname "role[$roles]" | ||||
|         if [ $? != 0 ] | ||||
|         then   | ||||
|             errmsg="Failed to run knife node run_list add $client 'role[$roles]' on the chef-server $NODE." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|  | ||||
|         # assign the new environment to the chef client node  | ||||
|         newenv=`hget $client cloud` | ||||
|         if [ -z $newenv ]  | ||||
|         then | ||||
|             errmsg="No cloud for $client. Please check the cloud table." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|         origenv=`knife node show $c_fullname -E | sed -e 's/[ ]*//g'| awk -F: '{print $2}'` | ||||
|         EDITOR="sed -e s/$origenv/$newenv/ -i" knife node edit $c_fullname | ||||
|         if [ $? != 0 ] | ||||
|         then   | ||||
|             errmsg="Failed to run knife node edit $client on the chef-server $NODE." | ||||
|             logger -t xcat -p local4.err $errmsg | ||||
|             echo $errmsg | ||||
|             exit 1 | ||||
|         fi | ||||
|  | ||||
|  | ||||
|     done | ||||
| fi | ||||
|  | ||||
| IFS=$OIFS | ||||
|  | ||||
|  | ||||
| exit 0 | ||||
|  | ||||
|  | ||||
|  | ||||
							
								
								
									
										56
									
								
								xCAT-OpenStack/sbin/makeclouddata
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										56
									
								
								xCAT-OpenStack/sbin/makeclouddata
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| #!/usr/bin/env perl | ||||
| # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html | ||||
|  | ||||
| # Used as a standard client cmd that can be used for xcat cmds that do not have | ||||
| # noderange as an argument.  See xcatclient for additional documentation. | ||||
|  | ||||
| # To put the cloud command only in xCAT-OpenStack, just copy the ../bin/xcatclientnnr  | ||||
| # as makeclouddata command here. we couldn't sym link the command makecloudata | ||||
| # to this script ../bin/xcatclientnnr in xCAT-OpenStack.spec. | ||||
|  | ||||
| BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } | ||||
| use lib "$::XCATROOT/lib/perl"; | ||||
| use Cwd; | ||||
| use File::Basename; | ||||
| use xCAT::Client; | ||||
| use strict; | ||||
|  | ||||
| my $bname = basename($0); | ||||
| my $cmdref; | ||||
| if ($bname =~ /xcatclientnnr/) { $cmdref->{command}->[0]=shift @ARGV; }  # xcatclientnnr was invoked directly and the 1st arg is cmd name that is used to locate the plugin | ||||
| else { $cmdref->{command}->[0] = $bname; }        # the cmd was sym linked to xcatclientnnr | ||||
| $cmdref->{cwd}->[0] = cwd(); | ||||
| my $data; | ||||
| # allows our plugins to get the stdin of the cmd that invoked the plugin | ||||
| if ( (($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/))  || !defined($ENV{'TERM'}) ) | ||||
| { | ||||
|     my $rout; | ||||
|     my $rin=""; | ||||
|     vec($rin,fileno(STDIN),1)=1; | ||||
|     my $nfound=select($rout=$rin,"","",1); | ||||
|     if ($nfound) | ||||
|     { | ||||
|         while ( <STDIN> ) { $data.=$_; } | ||||
|         $cmdref->{stdin}->[0]=$data; | ||||
|     } | ||||
| } | ||||
| else | ||||
| { | ||||
|     if (-p STDIN) { | ||||
|         while ( <STDIN> ) { $data.=$_; } | ||||
|         $cmdref->{stdin}->[0]=$data; | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| push (@{$cmdref->{arg}}, @ARGV); | ||||
| foreach (keys %ENV) { | ||||
|     if (/^XCAT_/) { | ||||
|         $cmdref->{environment}->{$_} = $ENV{$_}; | ||||
|     } | ||||
| } | ||||
|  | ||||
| xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response); | ||||
| exit $xCAT::Client::EXITCODE; | ||||
|  | ||||
|  | ||||
| @@ -0,0 +1 @@ | ||||
| #CLOUDINFO_EXPORT# | ||||
| @@ -29,20 +29,40 @@ management. | ||||
| %install | ||||
| mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_schema | ||||
| mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin | ||||
| mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT | ||||
| mkdir -p $RPM_BUILD_ROOT/install/postscripts | ||||
| mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/mypostscript | ||||
| mkdir -p $RPM_BUILD_ROOT/%{prefix}/sbin | ||||
|  | ||||
| cp -a lib/perl/xCAT_schema/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_schema | ||||
| find $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_schema -type d -exec chmod 755 {} \; | ||||
| find $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_schema -type f -exec chmod 644 {} \; | ||||
|  | ||||
| cp -a lib/perl/xCAT_plugin/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin | ||||
| chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/* | ||||
|  | ||||
| ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/makeclouddata | ||||
| cp -a lib/perl/xCAT/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT | ||||
| chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/* | ||||
|  | ||||
| cp sbin/* $RPM_BUILD_ROOT/%{prefix}/sbin | ||||
| chmod 755 $RPM_BUILD_ROOT/%{prefix}/sbin/* | ||||
|  | ||||
|  | ||||
| #ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/makeclouddata | ||||
|  | ||||
| #cd - | ||||
| cp -a postscripts/* $RPM_BUILD_ROOT/install/postscripts | ||||
| chmod 755 $RPM_BUILD_ROOT/install/postscripts/* | ||||
|  | ||||
| cp -a share/xcat/mypostscript/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/mypostscript | ||||
| chmod 644 $RPM_BUILD_ROOT/%{prefix}/share/xcat/mypostscript/* | ||||
|  | ||||
| %clean | ||||
| rm -rf $RPM_BUILD_ROOT | ||||
|  | ||||
| %files | ||||
| %{prefix} | ||||
| /install/postscripts | ||||
| %defattr(-,root,root) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -121,6 +121,10 @@ export CFGMGR | ||||
| CFGSERVER=#TABLE:cfgmgt:$NODE:cfgserver# | ||||
| export CFGSERVER | ||||
|  | ||||
| #CFGMGTINFO_EXPORT# | ||||
|  | ||||
| #INCLUDE:/opt/xcat/share/xcat/mypostscript/mypostscript_cloud.tmpl# | ||||
|  | ||||
|  | ||||
| ## | ||||
| ##The line postscripts-start-here must not be deleted.  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user