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

1 answer

Sort by » oldest newest most voted
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: 101 times

Last updated: Jan 31