New Question

Revision history [back]

cloudbase version: 1.1.4 windows server 2022 When I open configdrive.py, the code is different from yours. I will post the modified code. If you encounter the same problem as me, maybe you can try this.

from oslo_log import log as oslo_logging
from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit.metadata.services import baseconfigdrive
from cloudbaseinit.metadata.services import baseopenstackservice
import os
import shutil
import ctypes

CONF = cloudbaseinit_conf.CONF
LOG = oslo_logging.getLogger(__name__)


class ConfigDriveService(baseconfigdrive.BaseConfigDriveService,
                         baseopenstackservice.BaseOpenStackService):

    def __init__(self):
        super(ConfigDriveService, self).__init__(
            'config-2', 'openstack\\latest\\meta_data.json')

    def cleanup(self):
        LOG.debug('Deleting metadata folder: %r', self._mgr.target_path)
        shutil.rmtree(self._mgr.target_path, ignore_errors=True)
        self._metadata_path = None
        drive_letter = os.popen('wmic logicaldisk where VolumeName="config-2" get Caption | findstr /I ":"').read().strip()
        if drive_letter:
            LOG.debug('Ejecting metadata drive: %s', drive_letter)
            ctypes.windll.WINMM.mciSendStringW(f"open {drive_letter} type cdaudio alias d_drive", None, 0, None)
            ctypes.windll.WINMM.mciSendStringW("set d_drive door open", None, 0, None)