SYSPREP_PARAM_MAXLEN = 20
+
class MetadataMonitor(object):
"""Monitors image metadata chages"""
def __init__(self, session, meta):
if len(needed) == 0:
return True
- fields = []
- for name in names:
- param = needed[name]
- default = available[name] if name in available else ""
- fields.append(("%s: " % param.description, default,
- SYSPREP_PARAM_MAXLEN))
+ while 1:
+ fields = []
+ for name in names:
+ param = needed[name]
+ default = str(available[name]) if name in available else ""
+ fields.append(("%s: " % param.description, default,
+ SYSPREP_PARAM_MAXLEN))
- txt = "Please provide the following system preparation parameters:"
- code, output = d.form(txt, height=13, width=WIDTH, form_height=len(fields),
- fields=fields)
+ txt = "Please provide the following system preparation parameters:"
+ code, output = d.form(txt, height=13, width=WIDTH,
+ form_height=len(fields), fields=fields)
- if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
- return False
+ if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+ return False
- for i in range(len(fields)):
- param = needed[names[i]]
- try:
- value = param.type(output[i])
- if param.validate(value):
- image.os.sysprep_params[names[i]] = value
- continue
- except ValueError:
- pass
+ def check_params():
+ for i in range(len(fields)):
+ param = needed[names[i]]
+ try:
+ value = param.type(output[i])
+ if param.validate(value):
+ image.os.sysprep_params[names[i]] = value
+ continue
+ except ValueError:
+ pass
+
+ d.msgbox("Invalid value for parameter: `%s'" % names[i],
+ width=SMALL_WIDTH)
+ return False
+ return True
- d.msgbox("The value you provided for parameter: `%s' is not valid" %
- names[i], width=SMALL_WIDTH)
- return False
+ if check_params():
+ break
return True
import subprocess
import struct
-BOOT_TIMEOUT = 300
-SHUTDOWN_TIMEOUT = 120
-CONNECTION_RETRIES = 5
-
# For more info see: http://technet.microsoft.com/en-us/library/jj612867.aspx
KMS_CLIENT_SETUP_KEYS = {
"Windows 8 Professional": "NG4HW-VH26C-733KW-K6F98-J8CK4",
"Windows Server 2008 for Itanium-Based Systems":
"4DWFP-JF3DJ-B7DTH-78FJB-PDRHK"}
+_POSINT = lambda x: type(x) == int and x >= 0
+
class Windows(OSBase):
"""OS class for Windows"""
-
+ @add_sysprep_param(
+ 'shutdown_timeout', int, 120, "Shutdown Timeout (seconds)", _POSINT)
+ @add_sysprep_param(
+ 'boot_timeout', int, 300, "Boot Timeout (seconds)", _POSINT)
+ @add_sysprep_param(
+ 'connection_retries', int, 5, "Connection Retries", _POSINT)
@add_sysprep_param('password', str, None, 'Image Administrator Password')
def __init__(self, image, **kargs):
super(Windows, self).__init__(image, **kargs)
self.out.output("Starting windows VM ...", False)
monitorfd, monitor = tempfile.mkstemp()
os.close(monitorfd)
- vm = _VM(self.image.device, monitor)
+ vm = _VM(self.image.device, monitor, self.sysprep_params)
self.out.success("started (console on vnc display: %d)." %
vm.display)
self.out.success("done")
self.out.output("Waiting for windows to shut down ...", False)
- vm.wait(SHUTDOWN_TIMEOUT)
+ vm.wait(self.sysprep_params['shutdown_timeout'])
self.out.success("done")
finally:
if monitor is not None:
def _wait_vm_boot(self, vm, fname, msg):
"""Wait until a message appears on a file or the vm process dies"""
- for _ in range(BOOT_TIMEOUT):
+ for _ in range(self.sysprep_params['boot_timeout']):
time.sleep(1)
with open(fname) as f:
for line in f:
def _check_connectivity(self):
"""Check if winexe works on the Windows VM"""
+ retries = self.sysprep_params['connection_retries']
+ # If the connection_retries parameter is set to 0 disable the
+ # connectivity check
+ if retries == 0:
+ return True
+
passwd = self.sysprep_params['password']
winexe = WinEXE('Administrator', passwd, 'localhost')
winexe.uninstall().debug(9)
- for i in range(CONNECTION_RETRIES):
+ for i in range(retries):
(stdout, stderr, rc) = winexe.run('cmd /C')
if rc == 0:
return True
finally:
log.close()
self.out.output("failed! See: `%s' for the full output" % log.name)
- if i < CONNECTION_RETRIES - 1:
- self.out.output("Retrying ...", False)
- raise FatalError("Connection to the VM failed after %d retries" %
- CONNECTION_RETRIES)
+ if i < retries - 1:
+ self.out.output("retrying ...", False)
+
+ raise FatalError("Connection to the Windows VM failed after %d retries"
+ % retries)
def _guest_exec(self, command, fatal=True):
"""Execute a command on a windows VM"""
class _VM(object):
"""Windows Virtual Machine"""
- def __init__(self, disk, serial):
+ def __init__(self, disk, serial, params):
"""Create _VM instance
disk: VM's hard disk
self.disk = disk
self.serial = serial
+ self.params = params
def random_mac():
"""creates a random mac address"""
signal.signal(signal.SIGALRM, handler)
- signal.alarm(SHUTDOWN_TIMEOUT)
+ signal.alarm(self.params['shutdown_timeout'])
self.process.communicate(input="system_powerdown\n")
signal.alarm(0)