Revision af01e887
b/image_creator/dialog_menu.py | ||
---|---|---|
621 | 621 |
image = session['image'] |
622 | 622 |
|
623 | 623 |
available = image.os.sysprep_params |
624 |
needed = image.os.needed_sysprep_params() |
|
624 |
needed = image.os.needed_sysprep_params |
|
625 |
names = needed.keys() |
|
625 | 626 |
|
626 | 627 |
if len(needed) == 0: |
627 | 628 |
return True |
628 | 629 |
|
629 | 630 |
fields = [] |
630 |
for param in needed: |
|
631 |
default = available[param.name] if param.name in available else "" |
|
632 |
fields.append(("%s: " % param.description, default, param.length)) |
|
631 |
for name in names: |
|
632 |
param = needed[name] |
|
633 |
default = available[name] if name in available else "" |
|
634 |
fields.append(("%s: " % param.description, default, param.maxlen)) |
|
633 | 635 |
|
634 | 636 |
txt = "Please provide the following system preparation parameters:" |
635 | 637 |
code, output = d.form(txt, height=13, width=WIDTH, form_height=len(fields), |
... | ... | |
640 | 642 |
|
641 | 643 |
sysprep_params = {} |
642 | 644 |
for i in range(len(fields)): |
643 |
if needed[i].validator(output[i]): |
|
644 |
image.os.sysprep_params[needed[i].name] = output[i] |
|
645 |
param = needed[names[i]] |
|
646 |
if param.validator(output[i]): |
|
647 |
image.os.sysprep_params[names[i]] = output[i] |
|
645 | 648 |
else: |
646 | 649 |
d.msgbox("The value you provided for parameter: %s is not valid" % |
647 | 650 |
name, width=SMALL_WIDTH) |
b/image_creator/dialog_wizard.py | ||
---|---|---|
334 | 334 |
if 'DESCRIPTION' in session['metadata'] else '') |
335 | 335 |
|
336 | 336 |
# Create Sysprep Params Wizard Page |
337 |
needed = image.os.needed_sysprep_params() |
|
337 |
needed = image.os.needed_sysprep_params |
|
338 |
param_names = needed.keys() |
|
338 | 339 |
|
339 | 340 |
def sysprep_params_fields(): |
340 | 341 |
fields = [] |
341 | 342 |
available = image.os.sysprep_params |
342 |
for param in needed:
|
|
343 |
text = param.description
|
|
344 |
default = available[param.name] if param.name in available else ""
|
|
345 |
fields.append(("%s: " % text, default, param.length))
|
|
343 |
for name in param_names:
|
|
344 |
text = needed[name].description
|
|
345 |
default = available[name] if name in available else ""
|
|
346 |
fields.append(("%s: " % text, default, needed[name].maxlen))
|
|
346 | 347 |
return fields |
347 | 348 |
|
348 | 349 |
def sysprep_params_validate(answer): |
349 | 350 |
params = {} |
350 | 351 |
for i in range(len(answer)): |
351 |
if needed[i].validator(answer):
|
|
352 |
params[needed[i].name] = answer[i]
|
|
352 |
if needed[param_names[i]].validator(answer):
|
|
353 |
params[param_names[i]] = answer[i]
|
|
353 | 354 |
else: |
354 | 355 |
session['dialog'].msgbox("Invalid value for parameter `%s'" % |
355 |
needed[i].name)
|
|
356 |
param_names[i])
|
|
356 | 357 |
raise WizardReloadPage |
357 | 358 |
return params |
358 | 359 |
|
b/image_creator/os_type/__init__.py | ||
---|---|---|
70 | 70 |
|
71 | 71 |
def sysprep(message, enabled=True, **kwargs): |
72 | 72 |
"""Decorator for system preparation tasks""" |
73 |
def wrapper1(func):
|
|
73 |
def wrapper(func): |
|
74 | 74 |
func.sysprep = True |
75 | 75 |
func.enabled = enabled |
76 | 76 |
func.executed = False |
... | ... | |
79 | 79 |
setattr(func, key, val) |
80 | 80 |
|
81 | 81 |
@wraps(func) |
82 |
def wrapper2(self, print_message=True):
|
|
82 |
def inner(self, print_message=True):
|
|
83 | 83 |
if print_message: |
84 | 84 |
self.out.output(message) |
85 | 85 |
return func(self) |
86 | 86 |
|
87 |
return wrapper2
|
|
87 |
return inner
|
|
88 | 88 |
|
89 |
return wrapper1 |
|
89 |
return wrapper |
|
90 |
|
|
91 |
|
|
92 |
def add_sysprep_param(name, descr, maxlen, default=None, |
|
93 |
validator=lambda x: True): |
|
94 |
"""Decorator for init that adds the definition for a system preparation |
|
95 |
parameter |
|
96 |
""" |
|
97 |
def wrapper(func): |
|
98 |
|
|
99 |
@wraps(func) |
|
100 |
def inner(self, *args, **kwargs): |
|
101 |
|
|
102 |
func(self, *args, **kwargs) |
|
103 |
|
|
104 |
if not hasattr(self, 'needed_sysprep_params'): |
|
105 |
self.needed_sysprep_params = {} |
|
106 |
getattr(self, 'needed_sysprep_params')[name] = \ |
|
107 |
self.SysprepParam(descr, maxlen, validator) |
|
108 |
return inner |
|
109 |
|
|
110 |
return wrapper |
|
111 |
|
|
112 |
|
|
113 |
def del_sysprep_param(name): |
|
114 |
"""Decorator for init that deletes a previously added sysprep parameter |
|
115 |
definition . |
|
116 |
""" |
|
117 |
def wrapper(func): |
|
118 |
|
|
119 |
@wraps(func) |
|
120 |
def inner(self, *args, **kwargs): |
|
121 |
del self.needed_sysprep_params[nam] |
|
122 |
func(self, *args, **kwargs) |
|
123 |
|
|
124 |
return inner |
|
125 |
|
|
126 |
return wrapper |
|
90 | 127 |
|
91 | 128 |
|
92 | 129 |
class OSBase(object): |
93 | 130 |
"""Basic operating system class""" |
94 | 131 |
|
95 |
SysprepParam = namedtuple('SysprepParam', |
|
96 |
'name description length validator') |
|
132 |
SysprepParam = namedtuple('SysprepParam', 'description maxlen validator') |
|
97 | 133 |
|
98 | 134 |
def __init__(self, image, **kargs): |
99 | 135 |
self.image = image |
... | ... | |
121 | 157 |
|
122 | 158 |
self.out.output() |
123 | 159 |
|
124 |
def needed_sysprep_params(self): |
|
125 |
"""Returns a list of needed sysprep parameters. Each element in the |
|
126 |
list is a SysprepParam object. |
|
127 |
""" |
|
128 |
return [] |
|
129 |
|
|
130 | 160 |
def list_syspreps(self): |
131 | 161 |
"""Returns a list of sysprep objects""" |
132 | 162 |
objs = [getattr(self, name) for name in dir(self) |
b/image_creator/os_type/windows.py | ||
---|---|---|
36 | 36 |
"""This module hosts OS-specific code common for the various Microsoft |
37 | 37 |
Windows OSs.""" |
38 | 38 |
|
39 |
from image_creator.os_type import OSBase, sysprep |
|
39 |
from image_creator.os_type import OSBase, sysprep, add_sysprep_param
|
|
40 | 40 |
from image_creator.util import FatalError, check_guestfs_version, get_command |
41 | 41 |
from image_creator.winexe import WinEXE, WinexeTimeout |
42 | 42 |
|
... | ... | |
107 | 107 |
|
108 | 108 |
class Windows(OSBase): |
109 | 109 |
"""OS class for Windows""" |
110 |
|
|
111 |
@add_sysprep_param('password', 'Image Administrator Password', 20) |
|
110 | 112 |
def __init__(self, image, **kargs): |
111 | 113 |
super(Windows, self).__init__(image, **kargs) |
112 | 114 |
|
... | ... | |
126 | 128 |
|
127 | 129 |
self.product_name = self.g.inspect_get_product_name(self.root) |
128 | 130 |
|
129 |
def needed_sysprep_params(self): |
|
130 |
"""Returns a list of needed sysprep parameters. Each element in the |
|
131 |
list is a SysprepParam object. |
|
132 |
""" |
|
133 |
password = self.SysprepParam( |
|
134 |
'password', 'Image Administrator Password', 20, lambda x: True) |
|
135 |
|
|
136 |
return [password] |
|
137 |
|
|
138 | 131 |
@sysprep('Disabling IPv6 privacy extensions') |
139 | 132 |
def disable_ipv6_privacy_extensions(self): |
140 | 133 |
"""Disable IPv6 privacy extensions""" |
... | ... | |
280 | 273 |
raise FatalError("Image is already syspreped!") |
281 | 274 |
|
282 | 275 |
txt = "System preparation parameter: `%s' is needed but missing!" |
283 |
for param in self.needed_sysprep_params():
|
|
284 |
if param[0] not in self.sysprep_params:
|
|
285 |
raise FatalError(txt % param[0])
|
|
276 |
for param in self.needed_sysprep_params: |
|
277 |
if param not in self.sysprep_params: |
|
278 |
raise FatalError(txt % param) |
|
286 | 279 |
|
287 | 280 |
self.mount(readonly=False) |
288 | 281 |
try: |
Also available in: Unified diff