Repository URL to install this package:
| 
      
        
        
        Version: 
        
         
          
          5.0.1  ▾
        
         | 
| 
    
    python3-tvault-contego
  
    /
        
    usr
  
        /
        
    lib
  
        /
        
    python3
  
        /
        
    dist-packages
  
        /
        
    contego
  
        /
        
    nova
  
        /
        
    extension
  
        /
        
    driver
  
        /
        diskfilesdrive.py
   | 
|---|
# Copyright 2015 TrilioData, Inc
# All Rights Reserved.
#
"""Disklist Drive helper."""
import os
try:
    from oslo_config import cfg
except BaseException:
    from oslo.config import cfg
try:
    from oslo_utils import fileutils
except BaseException:
    from nova.openstack.common import fileutils
from nova import utils
diskfiles_drive_format = "iso9660"
mkisofs_cmd = "genisoimage"
# Diskfiles drives are 64mb, if we can't size to the exact size of the data
DISKFILESDRIVESIZE_BYTES = 64 * 1024
diskfilesdrive_opts = [
    cfg.StrOpt(
        "diskfiles_drive_format",
        default="iso9660",
        help="Disk files drive format. One of iso9660 (default) or vfat",
    ),
    # cfg.StrOpt('mkisofs_cmd',
    # default='genisoimage',
    # help='Name and optionally path of the tool used for '
    #'ISO image creation')
]
CONF = cfg.CONF
CONF.register_opts(diskfilesdrive_opts)
class DiskfilesDriveBuilder(object):
    def __init__(self, diskfiles):
        self.diskfiles = diskfiles
    def __enter__(self):
        return self
    def __exit__(self, exctype, excval, exctb):
        if exctype is not None:
            return False
        self.cleanup()
    def _add_file(self, basedir, path, data):
        filepath = os.path.join(basedir, path)
        dirname = os.path.dirname(filepath)
        fileutils.ensure_tree(dirname)
        with open(filepath, "wb") as f:
            f.write(data)
    def _write_disk_files(self, basedir):
        self._add_file(basedir, "diskfiles", self.diskfiles)
    def _make_iso9660(self, path, tmpdir):
        publisher = "%(product)s %(version)s" % {
            "product": "TrilioVault",
            "version": "1.0.",
        }
        utils.execute(
            CONF.mkisofs_cmd,
            "-o",
            path,
            "-ldots",
            "-allow-lowercase",
            "-allow-multidot",
            "-l",
            "-publisher",
            publisher,
            "-quiet",
            "-J",
            "-r",
            "-V",
            "diskdrives-1",
            tmpdir,
            attempts=1,
            run_as_root=False,
        )
    def make_drive(self, path):
        """Make the diskfiles drive.
        :param path: the path to place the diskfiles drive image at
        :raises ProcessExecuteError if a helper process has failed.
        """
        with utils.tempdir() as tmpdir:
            self._write_disk_files(tmpdir)
            if os.path.exists(path):
                os.remove(path)
            self._make_iso9660(path, tmpdir)
    def cleanup(self):
        pass
    def __repr__(self):
        return "<DiskfilesDriveBuilder: " + str(self.mdfiles) + ">"