Adds ConfigDrive support for Windows XP

Windows XP does not support the WMI class Win32_Volume. This patch
replaces is with a call to the GetVolumeInformationW WIn32 API.
This commit is contained in:
Alessandro Pilotti 2013-08-13 00:21:55 +03:00
parent c04254a0aa
commit 4bd0489427
3 changed files with 20 additions and 9 deletions

View File

@ -30,6 +30,7 @@ from cloudbaseinit.metadata.services.configdrive.windows.disk \
import physical_disk import physical_disk
from cloudbaseinit.metadata.services.configdrive.windows.disk \ from cloudbaseinit.metadata.services.configdrive.windows.disk \
import virtual_disk import virtual_disk
from cloudbaseinit.osutils import factory as osutils_factory
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -44,19 +45,18 @@ class ConfigDriveManager(object):
return l return l
def _get_config_drive_cdrom_mount_point(self): def _get_config_drive_cdrom_mount_point(self):
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
conn = wmi.WMI(moniker='//./root/cimv2') conn = wmi.WMI(moniker='//./root/cimv2')
q = conn.query('SELECT Drive FROM Win32_CDROMDrive WHERE ' q = conn.query('SELECT Drive FROM Win32_CDROMDrive WHERE '
'MediaLoaded = True') 'MediaLoaded = True')
for r in q: for r in q:
drive = r.Drive + '\\' label = osutils.get_volume_label(r.Drive)
q1 = conn.query('SELECT Label FROM Win32_Volume WHERE ' if label == "config-2" and \
'Name = \'%(drive)s\'' % locals()) os.path.exists(os.path.join(r.Drive,
for r1 in q1: 'openstack\\latest\\'
if r1.Label == "config-2" and \ 'meta_data.json')):
os.path.exists(os.path.join(drive, return r.Drive + "\\"
'openstack\\latest\\'
'meta_data.json')):
return drive
return None return None
def _c_char_array_to_c_ushort(self, buf, offset): def _c_char_array_to_c_ushort(self, buf, offset):

View File

@ -90,3 +90,6 @@ class BaseOSUtils(object):
def get_os_version(self): def get_os_version(self):
pass pass
def get_volume_label(self, drive):
pass

View File

@ -374,3 +374,11 @@ class WindowsUtils(base.BaseOSUtils):
def get_os_version(self): def get_os_version(self):
conn = wmi.WMI(moniker='//./root/cimv2') conn = wmi.WMI(moniker='//./root/cimv2')
return conn.Win32_OperatingSystem()[0].Version return conn.Win32_OperatingSystem()[0].Version
def get_volume_label(self, drive):
max_label_size = 261
label = ctypes.create_unicode_buffer(max_label_size)
ret_val = kernel32.GetVolumeInformationW(unicode(drive), label,
max_label_size, 0, 0, 0, 0, 0)
if ret_val:
return label.value