You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2009/11/13 17:37:42 UTC
svn commit: r835906 - in /incubator/vcl/sandbox/xcat2partimageng:
listener.py partimageng
Author: jfthomps
Date: Fri Nov 13 16:37:42 2009
New Revision: 835906
URL: http://svn.apache.org/viewvc?rev=835906&view=rev
Log:
initial add
Added:
incubator/vcl/sandbox/xcat2partimageng/listener.py (with props)
incubator/vcl/sandbox/xcat2partimageng/partimageng (with props)
Added: incubator/vcl/sandbox/xcat2partimageng/listener.py
URL: http://svn.apache.org/viewvc/incubator/vcl/sandbox/xcat2partimageng/listener.py?rev=835906&view=auto
==============================================================================
--- incubator/vcl/sandbox/xcat2partimageng/listener.py (added)
+++ incubator/vcl/sandbox/xcat2partimageng/listener.py Fri Nov 13 16:37:42 2009
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+import socket
+import os
+import linecache
+import re
+
+#sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+#sock.connect(('MASTERIP',3001))
+
+#response = sock.recv(100)
+#if(response == "ready\n"):
+# sock.send("installmonitor\n")
+# response = sock.recv(100)
+
+#sock.close()
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+port = 3001
+sock.bind(('', port))
+
+sock.listen(5)
+
+try:
+ while 1:
+ newSocket, address = sock.accept()
+ while 1:
+ received = newSocket.recv(200)
+ if not received:
+ break
+ command = re.split('\s+',received)
+ if(command[0] == "stat"):
+ ilog = ""
+ firstline = ""
+ line = ""
+ gzipping = 0
+ done = 0
+ percent = 0
+ count = 0
+ numpack = 0
+ action = ''
+ if(os.path.isfile('/tmp/save')):
+ action = 'imaging'
+ elif(os.path.isfile('/tmp/restore')):
+ action = 'installing'
+ if(os.path.isfile('/tmp/partimageng')):
+ ilog = '/tmp/partimageng'
+ if(os.path.isfile('/tmp/savegzip')):
+ gzipping = 1
+ if(os.path.isfile('/tmp/done')):
+ done = 1
+ if(ilog):
+ count = len(open(ilog).readlines())
+ firstline = linecache.getline(ilog,1)
+ line = linecache.getline(ilog,count)
+ linecache.clearcache()
+ if(line and not done and not gzipping):
+ r1 = re.compile("(\d+)/(\d+) - ([\d\.]+)")
+ m1 = r1.search(line)
+ if m1:
+ newline = "%s partition %s of %s: %s %%" % (action, str(m1.group(1)), str(m1.group(2)), str(m1.group(3)))
+ else:
+ newline = "unknown progress"
+ line = "partimage-ng: " + newline
+ elif(not line):
+ line = "partimage-ng: unknown progress"
+ elif(done):
+ line = "partimage-ng: complete"
+ elif(gzipping):
+ line = "partimage-ng: gzipping saved image"
+ newSocket.send(line)
+ break
+# if(command[0] == "sh"): #DEBUG purposes only, wide open root priv command here.
+# newcommand = ""
+# for i in command[1:]:
+# newcommand = newcommand + i + " "
+# output = os.popen(newcommand).read()
+# newSocket.send(output)
+# break
+ if(command[0] == "screendump"):
+ newcommand = "cat /dev/vcs"
+ for i in command[1:]:
+ newcommand = newcommand + i
+ output = os.popen(newcommand).read()
+ newSocket.send(output)
+ break
+
+ newSocket.close()
+
+finally:
+ sock.close()
Propchange: incubator/vcl/sandbox/xcat2partimageng/listener.py
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/vcl/sandbox/xcat2partimageng/partimageng
URL: http://svn.apache.org/viewvc/incubator/vcl/sandbox/xcat2partimageng/partimageng?rev=835906&view=auto
==============================================================================
--- incubator/vcl/sandbox/xcat2partimageng/partimageng (added)
+++ incubator/vcl/sandbox/xcat2partimageng/partimageng Fri Nov 13 16:37:42 2009
@@ -0,0 +1,272 @@
+#!/bin/bash
+export PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+partimageinstall () {
+ # based on install.sh from xcat 1.3 by Egan Ford
+
+ imgpath=$(dirname $1) # needs to be path to image files
+ myimage=$(basename $1 .img) # needs to be image without path or .gz
+ disk=$(basename $2) # needs to be disk - i.e. sda
+
+ DONE=0
+ OLD=""
+
+ cd $imgpath
+ NUMPART=$(cat $myimage-$disk.sfdisk | grep "^/dev/$disk" | grep -v Win95 | grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | grep -v "Id=82" | grep -v swap | awk '{print $1}' | wc -l)
+ for i in $(cat $myimage-$disk.sfdisk | grep "^/dev/$disk" | grep -v Win95 | grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | grep -v "Id=82" | grep -v swap | awk '{print $1}')
+ do
+ PARTNAME=$(basename $i)
+ if (("$NUMPART" > "1"))
+ then
+ PARTNAMEIMG=${PARTNAME/#??/part}
+ INPUTFILE=$myimage-$PARTNAMEIMG.gz
+ else
+ INPUTFILE=$myimage.gz
+ fi
+ if [ "$DONE" = "0" ]
+ then
+ if [ -r $myimage-$disk.sfdisk ]
+ then
+ sfdisk /dev/$disk <$myimage-$disk.sfdisk
+ fi
+ if [ -r $myimage-$disk.mbr ]
+ then
+ dd if=$myimage-$disk.mbr of=/dev/$disk
+ sfdisk /dev/$disk <$myimage-$disk.sfdisk
+ else
+ OLD=".6.0"
+ partimage$OLD -b -f3 restmbr $INPUTFILE
+ fi
+ sfdisk /dev/$disk -R
+ DONE=1
+ fi
+ echo running partimage$OLD -b -f3 restore /dev/$PARTNAME $INPUTFILE
+ logger -t xcat "running partimage$OLD -b -f3 restore /dev/$PARTNAME $INPUTFILE"
+ sleep 5
+ if ! partimage$OLD -b -f3 restore /dev/$PARTNAME $INPUTFILE; then
+ echo partimage exited with a non-zero status, failing
+ logger -t xcat "partimage exited with a non-zero status, failing"
+ return 1
+ fi
+ done
+
+ tput clear
+ tput sgr0
+ tput cnorm
+
+ for i in $(sfdisk -l /dev/$disk | grep "Linux swap" | awk '{print $1}')
+ do
+ echo "Setting up swap on $i"
+ if [ `echo $myimage | grep fc7` ]
+ then
+ label=SWAP-`echo $(basename $i) | sed -e "s/[sh]d/part/"`
+ else
+ label=SWAP-$(basename $i)
+ fi
+ mkswap -L $label $i
+ done
+}
+
+partimagesave () {
+ # based on save.sh from xcat 1.3 by Egan Ford
+ imgpath=$(dirname $1) # needs to be path to image files
+ myimage=$(basename $1 .img) # needs to be image without path or .gz
+ disk=$(basename $2) # needs to be disk - i.e. sda
+
+ logger -t xcat "Getting partitons for $disk"
+ echo "Partitions for $disk"
+ sfdisk -l /dev/$disk
+ echo "==="
+
+ NUMPART=$(sfdisk -l /dev/$disk | grep "^/dev/$disk" | grep -v Win95 | grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v swap | awk '{print $1}' | wc -l)
+ logger -t xcat "number of partitions found: $NUMPART"
+
+ dd if=/dev/$disk of=$imgpath/$myimage-$disk.mbr count=1 bs=512
+ sfdisk /dev/$disk -d >$imgpath/$myimage-$disk.sfdisk.tmp
+ if [ -s $imgpath/$myimage-$disk.sfdisk.tmp ]
+ then
+ mv -f $imgpath/$myimage-$disk.sfdisk.tmp $imgpath/$myimage-$disk.sfdisk
+ else
+ rm -f $imgpath/$myimage-$disk.sfdisk.tmp
+ fi
+ logger -t xcat "saving individual partitions"
+ for i in $(sfdisk -l /dev/$disk | grep "^/dev/$disk" | grep -v Win95 | grep -v Extended | grep -v Empty | grep -v swap | awk '{print $1}')
+ do
+ PARTNAME=$(basename $i)
+ logger -t xcat "working with $PARTNAME"
+ if (("$NUMPART" > "1"))
+ then
+ PARTNAMEIMG=${PARTNAME/#??/part}
+ OUTPUTFILE=$imgpath/$myimage-$PARTNAMEIMG.gz
+ else
+ OUTPUTFILE=$imgpath/$myimage.gz
+ fi
+ echo running partimage -z1 -f3 -odbc save /dev/$PARTNAME $OUTPUTFILE
+ logger -t xcat "running partimage -z1 -f3 -odbc save /dev/$PARTNAME $OUTPUTFILE"
+ sleep 5
+ if ! partimage -z1 -f3 -odbc save /dev/$PARTNAME $OUTPUTFILE; then
+ echo partimage exited with a non-zero status, failing
+ logger -t xcat "partimage exited with a non-zero status, failing"
+ return 1
+ fi
+ done
+ tput clear
+ tput sgr0
+ tput cnorm
+
+ cd $imgpath
+ for i in *.000
+ do
+ mv $i ${i%%.000}
+ done
+ return 0
+}
+
+exec 2>/tmp/partimageng.log
+set -x
+
+depmod -a
+modprobe nfs
+modprobe scsi_transport_sas
+modprobe mptbase
+modprobe mptscsih
+modprobe mptsas
+
+# check for problem of $MASTER being an unknown host
+if ! ping -c 1 $MASTER &> /dev/null; then
+ echo "CRITICAL ERROR: could not ping $MASTER, rebooting"
+ sleep 3
+ /sbin/reboot
+ exit
+fi
+mount -o nfsvers=3,tcp,nolock,rw $MASTER:/install /install
+
+reboot=''
+usepartimageng=0 # this controls what is used to save images
+
+for o in `cat /proc/cmdline` ; do
+ case $o in
+ image=*)
+ image=${o#image=}
+ ;;
+ device=*)
+ device=${o#device=}
+ ;;
+ action=*)
+ action=${o#action=}
+ ;;
+ blocks=*)
+ blocks=${o#blocks=}
+ ;;
+ reboot)
+ reboot=reboot
+ ;;
+ usepartimageng=*)
+ usepartimageng=${o#usepartimageng=}
+ esac
+done
+
+/install/image/x86/installer_files/listener.py &
+
+sleep 3
+
+devices=`ls -l /dev/disk/by-id | awk '{print $11}'`
+logger -t xcat "disks: $devices"
+
+if [ "x$device" == "x" ] ; then
+ device=$(ls /dev/disk/by-id -l | grep -v total | head -1 | awk '{print $11}' | sed 's/[\.\/]//g')
+ if ! echo $device | egrep -q '(sda|hda)'; then
+ device=$(cat /proc/partitions | egrep -v '(ram|major)' | egrep '\w' | head -1 | awk '{print $4}')
+ fi
+ if ! echo $device | egrep -q '(sda|hda)'; then
+ device=$(ls /dev/disk/by-id -l | grep -v total | head -1 | awk '{print $11}' | sed 's/[\.\/]//g')
+ if ! echo $device | egrep -q '(sdb|hdb)'; then
+ device=$(cat /proc/partitions | egrep -v '(ram|major)' | egrep '\w' | head -1 | awk '{print $4}')
+ fi
+ fi
+ if ! echo $device | egrep -q '(sda|hda|sdb|hdb)'; then
+ echo "No device specified and could not guess a valid device"
+ logger -t xcat "partimage failed: no device specified and could not guess a valid device"
+ /xcatpost/updateflag.awk $MASTER 3002
+ /sbin/reboot
+ exit 1
+ else
+ echo "No device specified, trying with guessed device /dev/$device"
+ logger -t xcat "No device specified, trying with guessed device /dev/$device"
+ fi
+ device="/dev/$device"
+fi
+
+if [ "x$action" == "xsave" ] ; then
+ touch /tmp/save
+ if [ "$usepartimageng" = "0" ]; then
+ partimagesave $image $device
+ rc=$?
+ else
+ echo running /sbin/partimage-ng -b $blocks save $device $image
+ logger -t xcat "running /sbin/partimage-ng -p -b $blocks save $device $image"
+ /sbin/partimage-ng -p -b $blocks save $device $image > /tmp/partimageng
+ echo gzipping $image
+ logger -t xcat "gzipping $image"
+ touch /tmp/savegzip
+ if gzip $image; then
+ echo gzipping finished, removing .gz extension from filename
+ logger -t xcat "gzipping finished, removing .gz extension from filename"
+ mv $image.gz $image
+ else
+ echo "gzipping failed"
+ logger -t xcat "gzipping failed"
+ fi
+ rc=$?
+ fi
+ if [ "$rc" = "0" ]; then
+ touch $image.capturedone
+ logger -t xcat "partimage-ng exited normally"
+ else
+ touch $image.capturefailed
+ logger -t xcat "partimage-ng failed with exit code $rc"
+ fi
+elif [ "x$action" == "xrestore" ] ; then
+ touch /tmp/restore
+ testfile=$(echo $image | awk -F '.' '{print $1}')
+ if ls -1 $testfile*.mbr > /dev/null; then
+ partimageinstall $image $device
+ rc=$?
+ if [ "$rc" = "0" ]; then
+ echo "partimage successfully loaded image"
+ logger -t xcat "partimage successfully loaded image"
+ else
+ echo "partimage failed to load image"
+ logger -t xcat "partimage failed to load image"
+ fi
+ else
+ echo "running zcat $image | /sbin/partimage-ng -p -b $blocks restore stdin $device"
+ logger -t xcat "running zcat $image | /sbin/partimage-ng -p -b $blocks restore stdin $device"
+ zcat $image | /sbin/partimage-ng -p -b $blocks restore stdin $device > /tmp/partimageng
+ rc=$?
+ if [ "$rc" = "0" ]; then
+ echo "partimage-ng successfully loaded image"
+ logger -t xcat "partimage-ng successfully loaded image"
+ echo "running /sbin/parted $device set 1 boot on"
+ logger -t xcat "running /sbin/parted $device set 1 boot on"
+ /sbin/parted $device set 1 boot on
+ else
+ echo "partimage-ng failed to load image"
+ logger -t xcat "partimage-ng failed to load image"
+ fi
+ fi
+else
+ echo "unknown action supplied"
+ logger -t xcat "unknown action supplied"
+ exit 1
+fi
+
+touch /tmp/done
+
+if [ "$rc" = "0" ]; then
+ /xcatpost/updateflag.awk $MASTER 3002
+fi
+
+if [ "x$reboot" == "xreboot" ] ; then
+ /sbin/reboot
+fi
Propchange: incubator/vcl/sandbox/xcat2partimageng/partimageng
------------------------------------------------------------------------------
svn:executable = *