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

windows: Upload the virtio drivers to the media

Upload the virtio drivers to the media and add the drivers directory to
the DevicePath Registry key
parent 94639eba
No related branches found
No related tags found
No related merge requests found
......@@ -373,6 +373,9 @@ class Windows(OSBase):
"VirtIO drivers from. Further image customization is not "
"possible.")
if virtio_dir:
self._install_virtio_drivers(virtio_dir)
v_val = self.registry.reset_passwd(admin)
disabled_uac = self.registry.update_uac_remote_setting(1)
token = self._add_boot_scripts()
......@@ -615,21 +618,35 @@ class Windows(OSBase):
tip-install-a-device-driver-in-a-windows-vm/
"""
path = "%s/system32/drivers" % self.systemroot
drivers_path = "%s/system32/drivers" % self.systemroot
try:
path = self.image.g.case_sensitive_path(path)
drivers_path = self.image.g.case_sensitive_path(drivers_path)
except RuntimeError as err:
raise FatalError("Unable to browse to directory: %s. Reason: %s" %
(path, str(err)))
localpath = dirname + os.sep + 'viostor.sys'
(drivers_path, str(err)))
viostor = dirname + os.sep + 'viostor.sys'
try:
self.image.g.upload(localpath, path + '/viostor.sys')
self.image.g.upload(viostor, drivers_path + '/viostor.sys')
except RuntimeError as err:
raise FatalError("Unable to upload file %s to %s. Reason: %s" %
(localpath, path, str(err)))
(viostor, drivers_path, str(err)))
self.registry.add_viostor()
def _install_virtio_drivers(self, dirname):
"""Install the virtio drivers to the media"""
virtio_dir = self.image.g.case_sensitive_path("%s/VirtIO" %
self.systemroot)
self.image.g.mkdir_p(virtio_dir)
for fname in os.listdir(dirname):
full_path = os.path.join(dirname, fname)
if os.path.isfile(full_path):
self.image.g.upload(full_path, "%s/%s" % (virtio_dir, fname))
self.registry.update_devices_dirs(r"%SystemRoot%\VirtIO")
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -437,4 +437,34 @@ class Registry(object):
hive.commit(None)
def update_devices_dirs(self, dirname, append=True):
"""Update the value of the DevicePath registry key. If the append flag
is True, the dirname is appended to the list of devices directories,
otherwise the value is overwritten.
This function returns the old value of the registry key
"""
with self.open_hive('SOFTWARE', write=True) as hive:
current_version = hive.root()
for child in ('Microsoft', 'Windows', 'CurrentVersion'):
current_version = hive.node_get_child(current_version, child)
device_path = hive.node_get_value(current_version, 'DevicePath')
regtype, value = hive.value_value(device_path)
assert regtype == 2L, "Type (=%d) is not REG_EXPAND_SZ" % regtype
# Remove the trailing '\x00' character
old_value = value.decode('utf-16le')[:-1]
new_value = "%s;%s" % (old_value, dirname) if append else dirname
hive.node_set_value(current_version,
REG_EXPAND_SZ('DevicePath', new_value))
hive.commit(None)
return old_value
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
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