New Question
0

how to umount CD drive after cloudbase-init completed ?

asked 2019-01-22 08:44:27 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi, everyone, I am using cloudbaseinit.metadata.services.configdrive.ConfigDriveService, the metadata mount as CD drive after windows boot. I want to umount the metadata CD drive after Cloudbase-Init completed, so the end user will unable to see the content of metadata, is this possible ? Thanks.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2024-01-17 03:25:03 +0300

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)
edit flag offensive delete link more
0

answered 2019-01-24 05:57:03 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Finally, I modify configdrive.py to dismount CDROM, and tested in windows 2016 Std server.

Update: just tested windows 2012 R2, also work.

C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\Lib\site-packages\cloudbaseinit\metadata\services\configdrive.py

 import os
 import shutil
+import ctypes
 ... ...
        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()
    +       if drive_letter:
    +           LOG.debug('Eject metadata drive: %s', str(drive_letter).rstrip())
    +           ctypes.windll.WINMM.mciSendStringW(u"open " + str(drive_letter).rstrip() + " type cdaudio alias d_drive", None, 0, None)
    +           ctypes.windll.WINMM.mciSendStringW(u"set d_drive door open", None, 0, None)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-22 08:44:27 +0300

Seen: 2,064 times

Last updated: Jan 17