コード例 #1
0
ファイル: lvm_root.py プロジェクト: schnoebe/fedora-mock
    def __init__(self, plugins, lvm_conf, buildroot):
        if not util.original_ipc_ns or not util.have_setns:
            raise LvmError("Cannot initialize setns support, which is "
                           "needed by LVM plugin")
        self.buildroot = buildroot
        self.lvm_conf = lvm_conf
        self.vg_name = lvm_conf.get('volume_group')
        self.conf_id = '{0}.{1}'.format(self.prefix,
                                        buildroot.shared_root_name)
        self.pool_name = lvm_conf.get('pool_name', self.conf_id)
        self.ext = self.buildroot.config.get('unique-ext', 'head')
        self.head_lv = '+{0}.{1}'.format(self.conf_id, self.ext)
        self.fs_type = lvm_conf.get('filesystem', 'ext4')
        self.root_path = os.path.realpath(self.buildroot.make_chroot_path())
        if not self.vg_name:
            raise LvmError("Volume group must be specified")

        snapinfo_name = '.snapinfo-{0}.{1}'.format(self.conf_id, self.ext)
        self.basepath = buildroot.mockdir
        self.snap_info = os.path.join(self.basepath, snapinfo_name)
        self.lock = self.create_lock('lvm')
        self.pool_lock = self.create_lock('lmv-pool')
        self.mount = None

        prefix = 'hook_'
        for member in dir(self):
            if member.startswith(prefix):
                method = getattr(self, member)
                hook_name = member[len(prefix):]
                plugins.add_hook(hook_name, method)
コード例 #2
0
ファイル: lvm_root.py プロジェクト: remicollet/mock
 def hook_remove_snapshot(self, name):
     if name == self.postinit_name:
         raise LvmError(dedent("""\
                 Won't remove postinit snapshot. To remove all logical
                 volumes associated with this buildroot, use --scrub lvm"""))
     lv_name = self.prefix_name(name)
     if not self.lv_is_our(lv_name):
         raise LvmError("Snapshot {0} doesn't exist".format(name))
     self.umount()
     if lv_name == self.get_current_snapshot():
         self.set_current_snapshot(self.prefix_name(self.postinit_name))
     lvm_do(['lvremove', '-f', self.vg_name + '/' + lv_name])
     self.buildroot.root_log.info("deleted {name} snapshot".format(name=name))
コード例 #3
0
ファイル: lvm_root.py プロジェクト: remicollet/mock
 def make_snapshot(self, name):
     if self.lv_exists(name):
         raise LvmError(
             "Snapshot {name} already exists".format(name=self.remove_prefix(name)))
     lvcreate = ['lvcreate', '-s', self.vg_name + '/' + self.head_lv, '-n', name]
     lvm_do(lvcreate)
     self.set_current_snapshot(name)
コード例 #4
0
 def check_pool_size(self):
     size_data = self.allocated_pool_data()
     size_metadata = self.allocated_pool_metadata()
     self.buildroot.root_log.info("LVM plugin enabled. Allocated pool data: {0}%. Allocated metadata: {1}%.".format(size_data, size_metadata))
     if (('check_size' not in self.lvm_conf) or (('check_size' in self.lvm_conf) and (self.lvm_conf['check_size']))) and \
        ((size_metadata and size_metadata > 90) or (size_data and size_data > 90)):
         raise LvmError("Thin pool {0}/{1} is over 90%. Please enlarge it.".format(self.vg_name, self.pool_name))
     else:
         if size_metadata and size_metadata > 75:
             self.buildroot.root_log.warning("LVM Thin pool metadata are nearly filled up ({0}%). You may experience weird errors. Consider growing up your thin pool.".format(size_data))
         if size_data and size_data > 75:
             self.buildroot.root_log.warning("LVM Thin pool is nearly filled up ({0}%). You may experience weird errors. Consider growing up your thin pool.".format(size_data))
コード例 #5
0
ファイル: lvm_root.py プロジェクト: scvenema/mock
 def set_current_snapshot(self, name):
     if not self.lv_is_our(name):
         raise LvmError("Snapshot {0} doesn't exist".format(
             self.remove_prefix(name)))
     with open(self.snap_info, 'w') as ac_record:
         ac_record.write(name)