Merge branch 'master' of ssh://git.code.sf.net/p/xcat/xcat-core

This commit is contained in:
litingt 2015-02-01 20:26:36 -08:00
commit e8019a65ec
6 changed files with 195 additions and 4 deletions

View File

@ -0,0 +1,92 @@
#!/usr/bin/python
"""
Usage:
softlayer_nas.py [--verbose --hostname=<hostname> --username=<username> --password=<password> --mountpoint=<mountpoint> ] (mount | unmount)
softlayer_nas.py [OPTIONS] (mount | unmount)
Options:
-h --help Show help screen
--version Show version
--verbose Print verbose information
--hostname=<hostname> SoftLayer Storage hostname
--username=<username> SoftLayer Storage LUN username
--password=<password> SoftLayer Storage LUN password
--mountpoint=<mountpoint> The mountpoint to use [default: /mnt/nas]
"""
import os
import sys
import docopt
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
if path.startswith('/opt'):
# if installed into system path, do not muck with things
sys.path.append(path)
from xcat import xcatutils
def mount_nas(hostname, user, passwd, mountPoint):
print "Attempting to mount the NAS at %s" %(mountPoint)
if xcatutils.isMounted(mountPoint):
raise xcatutils.xCatError("The mount point %s is already in use." %(mountPoint))
cmd = "mount -t cifs //%s/%s -o username=%s,password=%s,rw,nounix,iocharset=utf8,file_mode=0644,dir_mode=0755 %s" %(hostname, user, user, passwd, mountPoint)
out,err = xcatutils.run_command(cmd)
def unmount_nas(mountPoint):
print "Attempting to unmount the NAS at %s..." %(mountPoint)
if not xcatutils.isMounted(mountPoint):
raise xcatutils.xCatError("The mount point %s is NOT mounted." %(mountPoint))
else:
cmd = "umount %s" %(mountPoint)
out,err = xcatutils.run_command(cmd)
if err:
print "Encountered error while unmounting..."
print err
def configure_nas_automount(hostname, user, passwd, mountPoint):
print "\nNote: To configure automount on reboot, add the following into /etc/fstab:"
cmd = "//%s/%s %s cifs defaults,username=%s,password=%s 0 0" %(hostname,user,mountPoint,user,passwd)
print "%s\n" %(cmd)
def setup_softlayer_nas():
# verify information before starting
if arguments['--hostname'] is None:
arguments['--hostname'] = xcatutils.getUserInput("Enter the SoftLayer storage hostname")
if arguments['--username'] is None:
arguments['--username'] = xcatutils.getUserInput("Enter the SoftLayer storage username")
if arguments['--password'] is None:
arguments['--password'] = xcatutils.getUserInput("Enter the SoftLayer storage password")
# install prereqs
preReqPackages = ['cifs-utils']
if arguments['--verbose']:
print "Checking for installed packages: %s" %(preReqPackages)
xcatutils.installPackages(preReqPackages)
# mount the NAS
mount_nas(arguments['--hostname'],arguments['--username'],arguments['--password'],arguments['--mountpoint'])
configure_nas_automount(arguments['--hostname'],arguments['--username'],arguments['--password'],arguments['--mountpoint'])
if __name__ == '__main__':
try:
arguments = (docopt.docopt(__doc__, version="1.0"))
if arguments['unmount']:
unmount_nas(arguments['--mountpoint'])
else:
setup_softlayer_nas()
except docopt.DocoptExit as e:
print e
except xcatutils.xCatError as e:
print "xCatError: %s" %(e)

View File

@ -0,0 +1,85 @@
import sys
import os
import platform
class xCatError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def isMounted(mountPoint):
if os.path.ismount(mountPoint):
return True
else:
return False
def run_command(cmd):
"""
Function: run_command
Arguments: cmd - string to be run as a command
Description: runs the command then returns out and err
"""
import subprocess
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
(out,err) = p.communicate()
return (out,err)
def isRhel():
myDistro = platform.linux_distribution()
if "Red Hat Enterprise Linux Server" or "CentOS" in myDistro:
return True
else:
return False
def isSles():
myDistro = platform.linux_distribution()
if "SUSE Linux Enterprise Server" in myDistro:
return True
else:
return False
def isUbuntu():
myDistro = platform.linux_distribution()
if "Ubuntu" in myDistro:
return True
else:
return False
def getUserInput(question):
response = raw_input("%s: " %(question))
return response
def filterInstalledPackages(pkglist=[]):
fulllist = ""
if isRhel():
# using YUM
import yum
yb = yum.YumBase()
for x in pkglist:
if not yb.rpmdb.searchNevra(name='%s' %(x)):
fulllist += "%s " %(x)
return fulllist
def installPackages(pkglist=[]):
fulllist = filterInstalledPackages(pkglist)
if isRhel():
if fulllist.strip() != "":
cmd = "yum -y install %s" %(fulllist)
out,err = xcatutils.run_command(cmd)
elif isSles():
print "Using zyppr..."
elif isUbuntu():
print "Using apt-get..."
else:
print "Error!"

View File

@ -47,6 +47,9 @@ xCAT-SoftLayer provides Utilities to make xCAT work in a SoftLayer environment.
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib
mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/python
mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/python/xcat
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/install
#mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/sysclone/postscripts
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/packages/xCAT-SoftLayer
@ -59,6 +62,8 @@ cp -p -R share/xcat/install/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/install/
cp -d bin/* $RPM_BUILD_ROOT/%{prefix}/bin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
cp -d lib/python/xcat/* $RPM_BUILD_ROOT/%{prefix}/lib/python/xcat/
#cp -d postscripts/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/sysclone/postscripts
#chmod 755 $RPM_BUILD_ROOT/%{prefix}/share/xcat/sysclone/postscripts/*

View File

@ -52,7 +52,7 @@ if [ -n "$2" ]; then
fi
fi
if [ -x "/opt/confluent/bin/confetty" ] || [ -x "/usr/bin/confetty" ]; then
if [ -x "/opt/confluent/bin/confetty" ] || [ -x "/usr/bin/confetty" ] || [ -x "/usr/local/bin/confetty" ]; then
#use confluent
CONFETTY="confetty"
if [ -x "/opt/confluent/bin/confetty" ]; then

View File

@ -18,9 +18,11 @@ my $sb;
my $tilefact;
my $xrm="-xrm xterm.mainMenu.*.font:fixed -xrm xterm.vtMenu.*.font:fixed -xrm xterm.fontMenu.*.font:fixed -xrm xterm -xrm xterm.vt100.font6:grvga.737";
my $font = "5x7";
my $sizegeometry;
GetOptions(
#'sb' => \$sb,
'tile|t:i' => \$tilefact,
'geometry|g:s' => \$sizegeometry,
#'font|f=s' => \$font
);
my $noderange = $ARGV[$#ARGV];
@ -104,7 +106,8 @@ if (defined($tilefact)) {
$ENV{CONSCONTROLPATH} = "/tmp/wconscontrol.$firstnode.$$";
system("xterm $xrm -bg black -fg white -title $firstnode -n $firstnode -geometry +0+0 ".join(" ",@ARGV)." -e /bin/bash -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi \" &");
system("xterm $xrm -bg black -fg white -title $firstnode -n $firstnode -geometry $sizegeometry+0+0 ".join(" ",@ARGV)." -e /bin/bash -c \"/bin/true ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi \" &");
$ENV{CONSCONTROLPATH} = "";
my $remainwait = 2;
while (not -S "/tmp/wconscontrol.$firstnode.$$" and $remainwait > 0) {
sleep(0.1);
@ -154,7 +157,11 @@ if (defined($tilefact)) {
$currx=0;
}
} else {
system("xterm $xrm -bg black -fg white -title $firstnode -n $firstnode ".join(" ",@ARGV)." -e /bin/bash -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi\" &");
my $geo;
if ($sizegeometry) {
$geo = "-g $sizegeometry ";
}
system("xterm $xrm $geo-bg black -fg white -title $firstnode -n $firstnode ".join(" ",@ARGV)." -e /bin/bash -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi\" &");
}
my $geometry="";
@ -162,7 +169,7 @@ foreach (@nodes) {
if ($tilefact) {
my $corrected_x=$currx+$wmxo;
my $corrected_y=$curry+$wmyo;
$geometry="-geometry +$corrected_x+$corrected_y";
$geometry="-geometry $sizegeometry+$corrected_x+$corrected_y";
$currx+=$window_width;
if ($currx >= ($tilefact * $window_width)) {
$currx=0;
@ -171,6 +178,8 @@ foreach (@nodes) {
$curry = $panel_pad; #+$top_pad;
}
}
} elsif ($sizegeometry) {
$geometry = "-geometry $sizegeometry";
}
system("xterm $xrm -bg black -fg white ".join(" ",@ARGV)." -title $_ -n $_ $geometry -e /bin/bash -c \"$mydir/xtcd.pl .".$ENV{DISPLAY}." $_ $_ & let SDATE=`date +%s`+5; $mydir/rcons $_ ".$conservers{$_}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi\" &");