def cleanup(self): # Remove all volumes of volume group try: lvm2.vgs(vg_name) except lvm2.NotFound: pass else: lvm2.vgremove(vg_name)
def _destroy(self, force, **kwds): try: lvm2.lvremove(self.device) except lvm2.NotFound: pass if force: try: vg_info = lvm2.vgs(self.vg).values()[0] except lvm2.NotFound: pass else: if not (int(vg_info.snap_count) and not int(vg_info.lv_count)): pv_disks = [device for device, pv_info in lvm2.pvs().items() if pv_info.vg_name == self.vg] lvm2.vgremove(self.vg) for device in pv_disks: lvm2.pvremove(device) for pv in self.pvs: pv.destroy(force=True)
def _destroy(self, force, **kwds): try: lvm2.lvremove(self.device) except lvm2.NotFound: pass if force: try: vg_info = lvm2.vgs(self.vg).values()[0] except lvm2.NotFound: pass else: if not (int(vg_info.snap_count) and not int(vg_info.lv_count)): pv_disks = [ device for device, pv_info in lvm2.pvs().items() if pv_info.vg_name == self.vg ] lvm2.vgremove(self.vg) for device in pv_disks: lvm2.pvremove(device) for pv in self.pvs: pv.destroy(force=True)
def _ensure(self): def get_lv_size_kwarg(size): kwd = dict() if '%' in str(size): kwd['extents'] = size else: try: int(size) kwd['size'] = '%sG' % size except: kwd['size'] = size return kwd if self.snap: pvs = [] try: for snap in self.snap['pv_snaps']: snap = storage2.snapshot(snap) vol = storage2.volume(type=snap.type, snap=snap) vol.ensure() pvs.append(vol) except: for pv in pvs: pv.destroy() raise self.pvs = pvs self.vg = self.snap['vg'] self.name = self.snap['name'] pv_volumes = [] for pv_volume in self.pvs: pv_volume = storage2.volume(pv_volume) pv_volume.ensure() pvs = lvm2.pvs() if pv_volume.device not in pvs: if pv_volume.mounted_to(): pv_volume.umount() lvm2.pvcreate(pv_volume.device) pv_volumes.append(pv_volume) self.pvs = pv_volumes self._check_attr('vg') try: lv_info = self._lvinfo() except lvm2.NotFound: self._check_attr('size') try: lvm2.vgs(self.vg) except lvm2.NotFound: lvm2.vgcreate(self.vg, *[disk.device for disk in self.pvs]) kwds = {'name': self.name} kwds.update(get_lv_size_kwarg(self.size)) lvm2.lvcreate(self.vg, **kwds) lv_info = self._lvinfo() self._config.update({'device': lv_info.lv_path, 'snap': None}) pvs_to_extend_vg = [] for pv in self.pvs: pv_info = lvm2.pvs(pv.device).popitem()[1] if not pv_info.vg_name: pvs_to_extend_vg.append(pv_info.pv_name) continue if os.path.basename(self.vg) != pv_info.vg_name: raise storage2.StorageError( 'Can not add physical volume %s to volume group %s: already' ' in volume group %s' % (pv_info.pv_name, self.vg, pv_info.vg_name)) if pvs_to_extend_vg: lvm2.vgextend(self.vg, *pvs_to_extend_vg) lvm2.lvextend(self.device, **get_lv_size_kwarg(self.size)) if self.is_fs_created(): fs = storage2.filesystem(self.fstype) if fs.features.get('resizable'): fs.resize(self.device) if lv_info.lv_attr[4] == '-': lvm2.lvchange(self.device, available='y') util.wait_until(lambda: os.path.exists(self.device), sleep=1, timeout=30, start_text='Waiting for device %s' % self.device, error_text='Device %s not available' % self.device)
def lvm_layer_created(step): vol = world.eph_vol assert lvm2.vgs(world.eph_vol.vg), 'Volume group not found' assert os.path.exists(vol.device), 'LVM volume device not found' assert vol.mounted_to() == vol.mpoint
def _ensure(self): def get_lv_size_kwarg(size): kwd = dict() if '%' in str(size): kwd['extents'] = size else: try: int(size) kwd['size'] = '%sG' % size except: kwd['size'] = size return kwd if self.snap: pvs = [] try: for snap in self.snap['pv_snaps']: snap = storage2.snapshot(snap) vol = storage2.volume(type=snap.type, snap=snap) vol.ensure() pvs.append(vol) except: for pv in pvs: pv.destroy() raise self.pvs = pvs self.vg = self.snap['vg'] self.name = self.snap['name'] pv_volumes = [] for pv_volume in self.pvs: pv_volume = storage2.volume(pv_volume) pv_volume.ensure() pvs = lvm2.pvs() if pv_volume.device not in pvs: pv_volume.umount() lvm2.pvcreate(pv_volume.device) pv_volumes.append(pv_volume) self.pvs = pv_volumes self._check_attr('vg') try: lv_info = self._lvinfo() except lvm2.NotFound: self._check_attr('size') try: lvm2.vgs(self.vg) except lvm2.NotFound: lvm2.vgcreate(self.vg, *[disk.device for disk in self.pvs]) kwds = {'name': self.name} kwds.update(get_lv_size_kwarg(self.size)) lvm2.lvcreate(self.vg, **kwds) lv_info = self._lvinfo() self._config.update({ 'device': lv_info.lv_path, 'snap': None }) pvs_to_extend_vg = [] for pv in self.pvs: pv_info = lvm2.pvs(pv.device)[pv.device] if not pv_info.vg_name: pvs_to_extend_vg.append(pv.device) continue if os.path.basename(self.vg) != pv_info.vg_name: raise storage2.StorageError( 'Can not add physical volume %s to volume group %s: already' ' in volume group %s' % (pv.device, self.vg, pv_info.vg_name)) if pvs_to_extend_vg: lvm2.vgextend(self.vg, *pvs_to_extend_vg) lvm2.lvextend(self.device, **get_lv_size_kwarg(self.size)) if self.is_fs_created(): self.fscreated = True fs = storage2.filesystem(self.fstype) if fs.features.get('resizable'): fs.resize(self.device) if lv_info.lv_attr[4] == '-': lvm2.lvchange(self.device, available='y')