Revision 670ea7e3 image_creator/os_type/windows.py
b/image_creator/os_type/windows.py | ||
---|---|---|
55 | 55 |
|
56 | 56 |
class Windows(OSBase): |
57 | 57 |
"""OS class for Windows""" |
58 |
def __init__(self, image, **kargs): |
|
59 |
super(Windows, self).__init__(image, **kargs) |
|
60 |
|
|
61 |
device = self.g.part_to_dev(self.root) |
|
62 |
|
|
63 |
self.last_part_num = self.g.part_list(device)[-1]['part_num'] |
|
64 |
self.last_drive = None |
|
65 |
self.system_drive = None |
|
66 |
|
|
67 |
for drive, partition in self.g.inspect_get_drive_mappings(self.root): |
|
68 |
if partition == "%s%d" % (device, self.last_part_num): |
|
69 |
self.last_drive = drive |
|
70 |
if partition == self.root: |
|
71 |
self.system_drive = drive |
|
72 |
|
|
73 |
assert self.system_drive |
|
58 | 74 |
|
59 | 75 |
def needed_sysprep_params(self): |
60 | 76 |
"""Returns a list of needed sysprep parameters. Each element in the |
... | ... | |
122 | 138 |
r'/quiet /generalize /oobe /shutdown') |
123 | 139 |
self.syspreped = True |
124 | 140 |
|
141 |
@sysprep('Shrinking the last filesystem') |
|
142 |
def shrink(self): |
|
143 |
"""Shrink the last filesystem. Make sure the filesystem is defragged""" |
|
144 |
pass |
|
145 |
|
|
125 | 146 |
def do_sysprep(self): |
126 | 147 |
"""Prepare system for image creation.""" |
127 | 148 |
|
... | ... | |
175 | 196 |
else: |
176 | 197 |
self.out.success('done') |
177 | 198 |
|
199 |
time.sleep(5) # Just to be sure everything is up |
|
200 |
|
|
178 | 201 |
self.out.output("Disabling automatic logon ...", False) |
179 | 202 |
self._disable_autologon() |
180 | 203 |
self.out.success('done') |
... | ... | |
185 | 208 |
enabled = filter(lambda x: x.enabled, tasks) |
186 | 209 |
size = len(enabled) |
187 | 210 |
|
211 |
# Make sure shrink runs in the end, before ms sysprep |
|
212 |
enabled = filter(lambda x: self.sysprep_info(x).name != 'shrink', |
|
213 |
enabled) |
|
214 |
|
|
215 |
shrink_enabled = False |
|
216 |
if len(enabled) != size: |
|
217 |
enabled.append(self.shrink) |
|
218 |
shrink_enabled = True |
|
219 |
|
|
188 | 220 |
# Make sure the ms sysprep is the last task to run if it is enabled |
189 | 221 |
enabled = filter( |
190 |
lambda x: x.im_func.func_name != 'microsoft_sysprep', enabled) |
|
222 |
lambda x: self.sysprep_info(x).name != 'microsoft-sysprep', |
|
223 |
enabled) |
|
191 | 224 |
|
192 | 225 |
ms_sysprep_enabled = False |
193 | 226 |
if len(enabled) != size: |
... | ... | |
248 | 281 |
vnc_port = random.randint(11000, 14999) |
249 | 282 |
display = vnc_port - 5900 |
250 | 283 |
|
251 |
vm = kvm('-smp', '1', '-m', '1024', '-drive',
|
|
252 |
'file=%s,format=raw,cache=none,if=virtio' % self.image.device,
|
|
253 |
'-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
|
|
254 |
'-device', 'virtio-net-pci,mac=%s,netdev=netdev0' %
|
|
255 |
random_mac(), '-vnc', ':%d' % display, '-serial',
|
|
256 |
'file:%s' % monitor, _bg=True)
|
|
284 |
vm = kvm( |
|
285 |
'-smp', '1', '-m', '1024', '-drive',
|
|
286 |
'file=%s,format=raw,cache=unsafe,if=virtio' % self.image.device,
|
|
287 |
'-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
|
|
288 |
'-device', 'virtio-net-pci,mac=%s,netdev=netdev0' % random_mac(),
|
|
289 |
'-vnc', ':%d' % display, '-serial', 'file:%s' % monitor, _bg=True)
|
|
257 | 290 |
|
258 | 291 |
return vm, display |
259 | 292 |
|
... | ... | |
531 | 564 |
addr = 'localhost' |
532 | 565 |
runas = '--runas=%s' % user |
533 | 566 |
winexe = subprocess.Popen( |
534 |
['winexe', '-U', user, "//%s" % addr, runas, command],
|
|
567 |
['winexe', '-U', user, runas, "//%s" % addr, command],
|
|
535 | 568 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
536 | 569 |
|
537 | 570 |
stdout, stderr = winexe.communicate() |
Also available in: Unified diff