summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryves <steve.harrison@gmx.net>2011-12-14 00:06:44 +0100
committeryves <steve.harrison@gmx.net>2011-12-14 00:06:44 +0100
commitaeb4f9729b8936405a5435119b9a5a13f5a03922 (patch)
tree4d2e7b321b08aa0694e1aa819c49328fa8228e6a
parentf59666766ad13325aa79014b5c2fc4940692b0c5 (diff)
downloadiscsi-helper-aeb4f9729b8936405a5435119b9a5a13f5a03922.tar.gz
iscsi-helper-aeb4f9729b8936405a5435119b9a5a13f5a03922.tar.bz2
iscsi-helper-aeb4f9729b8936405a5435119b9a5a13f5a03922.zip
added first executor version, error handling must be added
-rwxr-xr-xcreateAndExportDisk.py38
1 files changed, 31 insertions, 7 deletions
diff --git a/createAndExportDisk.py b/createAndExportDisk.py
index 535300e..ffa71ca 100755
--- a/createAndExportDisk.py
+++ b/createAndExportDisk.py
@@ -3,6 +3,28 @@
import optparse
import sys
import re
+import subprocess
+
+class ExecutionPlan:
+
+ def __init__(self, commands):
+ self.commands = commands
+ self.executed = []
+ self.logFile = open("/tmp/log","w")
+ self.todo = len(self.commands)
+
+ def execute_all(self):
+ for i in range(len(self.executed),self.todo):
+ print("[" + str(i+1) + "/" + str(self.todo) + "]: excuting ",end="")
+ self.execute_next()
+ print("\r[" + str(i+1) + "/" + str(self.todo) + "]: excuted ")
+
+ def execute_next(self):
+ cmd = self.commands.pop(0)
+ # safty anker subprocess.call(cmd)
+ subprocess.call(['echo','>>>'] + cmd,stdout=self.logFile)
+ subprocess.call(['echo'] + cmd,stdout=self.logFile,stderr=self.logFile)
+ self.executed.append(cmd)
def logInfo(msg):
print("\033[1;32mINFO\033[0m " + str(msg))
@@ -10,9 +32,6 @@ def logInfo(msg):
def logErr(msg):
print("\033[1;31mERROR\033[0m " + str(msg))
-def execute(command):
- logInfo('would execute: ' + str(command))
-
def parseVmName(rawString):
# valdiate vm-name
if not re.match('^vm-[a-z]+[0-9]?(-[a-z])?$',rawString):
@@ -84,10 +103,15 @@ elif len(args) > 1:
vmName = parseVmName(args[0])
diskSize, diskSizeUnit = parseDiskSize(options.size)
-execute(["lvcreate", "-n", vmName, "-L", str(diskSize) + str(diskSizeUnit)])
-execute(["mkfs", "/dev/" + volumeGroupName + "/" + vmName, "-l",vmName])
-execute(["addIscsiDisk", vmName])
+cmds = [
+ ["lvcreate", "-n", vmName, "-L", str(diskSize) + str(diskSizeUnit)],
+ ["mkfs", "/dev/" + volumeGroupName + "/" + vmName, "-l",vmName],
+ ["addIscsiDisk", vmName]
+]
+
+execPlan = ExecutionPlan(cmds)
+execPlan.execute_all()
-logInfo("all done. Proceed to {pang,peng} an install your vm there!")
+logInfo("all done. SSH to (pang|peng).spline.de an install your vm there!")
sys.exit(0)