def _set_lvm_membership(self): if self._is_lvm_member is None: # this is contentious, if a PV is recognized by LVM but has no # VGs, should we consider it as part of LVM? We choose not to # here, because most likely, we need to use VGs from this PV. self._is_lvm_member = False for path in self._get_pv_paths(): # check if there was a pv created with the # name of device pvs = lvm.PVolumes() pvs.filter(pv_name=path) has_vgs = [pv.vg_name for pv in pvs if pv.vg_name] if has_vgs: self.vgs = list(set(has_vgs)) # a pv can only be in one vg, so this should be safe self.vg_name = has_vgs[0] self._is_lvm_member = True self.pvs_api = pvs for pv in pvs: if pv.vg_name and pv.lv_uuid: lv = lvm.get_lv(vg_name=pv.vg_name, lv_uuid=pv.lv_uuid) if lv: self.lvs.append(lv) else: self.vgs = [] return self._is_lvm_member
def zap(self, args): for device in args.devices: if disk.is_mapper_device(device): terminal.error( "Refusing to zap the mapper device: {}".format(device)) raise SystemExit(1) lv = api.get_lv_from_argument(device) if lv: # we are zapping a logical volume path = lv.lv_path self.unmount_lv(lv) else: # we are zapping a partition #TODO: ensure device is a partition path = device # check to if it is encrypted to close partuuid = disk.get_partuuid(device) if encryption.status("/dev/mapper/{}".format(partuuid)): dmcrypt_uuid = partuuid self.dmcrypt_close(dmcrypt_uuid) mlogger.info("Zapping: %s", path) # check if there was a pv created with the # name of device pvs = api.PVolumes() pvs.filter(pv_name=device) vgs = set([pv.vg_name for pv in pvs]) for pv in pvs: vg_name = pv.vg_name lv = None if pv.lv_uuid: lv = api.get_lv(vg_name=vg_name, lv_uuid=pv.lv_uuid) if lv: self.unmount_lv(lv) if args.destroy: for vg_name in vgs: mlogger.info( "Destroying volume group %s because --destroy was given", vg_name) api.remove_vg(vg_name) mlogger.info( "Destroying physical volume %s because --destroy was given", device) api.remove_pv(device) wipefs(path) zap_data(path) if lv and not pvs: # remove all lvm metadata lv.clear_tags() terminal.success("Zapping successful for: %s" % ", ".join(args.devices))
def zap(self, args): device = args.device lv = api.get_lv_from_argument(device) if lv: # we are zapping a logical volume path = lv.lv_path else: # we are zapping a partition #TODO: ensure device is a partition path = device logger.info("Zapping: %s", path) terminal.write("Zapping: %s" % path) if args.destroy and not lv: # check if there was a pv created with the # name of device pv = api.PVolumes().get(pv_name=device) if pv: logger.info( "Found a physical volume created from %s, will destroy all it's vgs and lvs", device) vg_name = pv.vg_name logger.info( "Destroying volume group %s because --destroy was given", vg_name) terminal.write( "Destroying volume group %s because --destroy was given" % vg_name) api.remove_vg(vg_name) logger.info( "Destroying physical volume %s because --destroy was given", device) terminal.write( "Destroying physical volume %s because --destroy was given" % device) api.remove_pv(device) else: logger.info( "Skipping --destroy because no associated physical volumes are found for %s", device) terminal.write( "Skipping --destroy because no associated physical volumes are found for %s" % device) wipefs(path) zap_data(path) if lv: # remove all lvm metadata lv.clear_tags() terminal.success("Zapping successful for: %s" % path)
def _set_lvm_membership(self): if self._is_lvm_member is None: # check if there was a pv created with the # name of device pvs = lvm.PVolumes() pvs.filter(pv_name=self.abspath) if not pvs: self._is_lvm_member = False return self._is_lvm_member has_vgs = [pv.vg_name for pv in pvs if pv.vg_name] if has_vgs: self._is_lvm_member = True self.pvs_api = pvs else: # this is contentious, if a PV is recognized by LVM but has no # VGs, should we consider it as part of LVM? We choose not to # here, because most likely, we need to use VGs from this PV. self._is_lvm_member = False return self._is_lvm_member
def pvolumes(monkeypatch): monkeypatch.setattr(process, 'call', lambda x: ('', '', 0)) pvolumes = api.PVolumes() pvolumes._purge() return pvolumes
def pvolumes(monkeypatch): monkeypatch.setattr('ceph_volume.process.call', lambda x: ('', '', 0)) pvolumes = lvm_api.PVolumes() pvolumes._purge() return pvolumes
def pvolumes_empty(monkeypatch): monkeypatch.setattr('ceph_volume.process.call', lambda x, **kw: ('', '', 0)) pvolumes = lvm_api.PVolumes(populate=False) return pvolumes