Skip to content
Snippets Groups Projects
Commit 9ca717c4 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add basic support for customizing windows images

Add do_sysprep method for windows that shuts down the guestfs backend
process and starts a new kvm process with the snapshot disk attached to
it.
parent 797e0df7
No related branches found
No related tags found
No related merge requests found
...@@ -37,21 +37,25 @@ ...@@ -37,21 +37,25 @@
Windows OSs.""" Windows OSs."""
from image_creator.os_type import OSBase, sysprep from image_creator.os_type import OSBase, sysprep
from image_creator.util import FatalError, check_guestfs_version from image_creator.util import FatalError, check_guestfs_version, get_command
import hivex import hivex
import tempfile import tempfile
import os import os
import time
import random
kvm = get_command('kvm')
class Windows(OSBase): class Windows(OSBase):
"""OS class for Windows""" """OS class for Windows"""
@sysprep(enabled=False) @sysprep(enabled=False)
def remove_user_accounts(self, print_header=True): def test(self, print_header=True):
"""Remove all user accounts with id greater than 1000""" """test sysprep"""
pass pass
def do_sysprep(self): def do_sysprep(self):
"""Prepare system for image creation.""" """Prepare system for image creation."""
...@@ -74,10 +78,25 @@ class Windows(OSBase): ...@@ -74,10 +78,25 @@ class Windows(OSBase):
ret = self.g.kill_subprocess() ret = self.g.kill_subprocess()
self.out.success('done') self.out.success('done')
self.out.output("Starting windows VM ...", False)
try: try:
pass self.out.output("Starting windows VM ...", False)
def random_mac():
mac = [0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff)]
return ':'.join(map(lambda x: "%02x" % x, mac))
vm = kvm('-smp', '1', '-m', '1024', '-drive',
'file=%s,format=raw,cache=none,if=virtio' %
self.image.device,
'-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
'-device', 'virtio-net-pci,mac=%s,netdev=netdev0' %
random_mac(), '-vnc', ':0', _bg=True)
time.sleep(30)
self.out.success('done')
vm.wait()
finally: finally:
self.out.output("Relaunching helper VM (may take a while) ...", self.out.output("Relaunching helper VM (may take a while) ...",
False) False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment