Exemplo n.º 1
0
    def _make_vfat(self, path):
        # NOTE(mikal): This is a little horrible, but I couldn't find an
        # equivalent to genisoimage for vfat filesystems.
        with open(path, 'w') as f:
            f.truncate(CONFIGDRIVESIZE_BYTES)

        utils.mkfs('vfat', path, label='config-2')

        mounted = False
        try:
            mountdir = tempfile.mkdtemp(dir=CONF.config_drive_tempdir,
                                        prefix='cd_mnt_')
            _out, err = utils.trycmd('mount',
                                     '-o',
                                     'loop,uid=%d,gid=%d' %
                                     (os.getuid(), os.getgid()),
                                     path,
                                     mountdir,
                                     run_as_root=True)
            if err:
                raise exception.ConfigDriveMountFailed(operation='mount',
                                                       error=err)
            mounted = True

            # NOTE(mikal): I can't just use shutils.copytree here, because the
            # destination directory already exists. This is annoying.
            for ent in os.listdir(self.tempdir):
                shutil.copytree(os.path.join(self.tempdir, ent),
                                os.path.join(mountdir, ent))

        finally:
            if mounted:
                utils.execute('umount', mountdir, run_as_root=True)
            shutil.rmtree(mountdir)
    def _make_vfat(self, path, tmpdir):
        # NOTE(mikal): This is a little horrible, but I couldn't find an
        # equivalent to genisoimage for vfat filesystems.
        with open(path, 'wb') as f:
            f.truncate(CONFIGDRIVESIZE_BYTES)

        utils.mkfs('vfat', path, label='config-2')

        with utils.tempdir() as mountdir:
            mounted = False
            try:
                _, err = nova.privsep.fs.mount(
                    None, path, mountdir,
                    ['-o',
                     'loop,uid=%d,gid=%d' % (os.getuid(), os.getgid())])
                if err:
                    raise exception.ConfigDriveMountFailed(operation='mount',
                                                           error=err)
                mounted = True

                # NOTE(mikal): I can't just use shutils.copytree here,
                # because the destination directory already
                # exists. This is annoying.
                for ent in os.listdir(tmpdir):
                    shutil.copytree(os.path.join(tmpdir, ent),
                                    os.path.join(mountdir, ent))

            finally:
                if mounted:
                    nova.privsep.fs.umount(mountdir)