def get_logical_volumes(self, name=None): def is_snapshot(lv_path): sub_output = Helper.execute(["lvs", lv_path]) if sub_output: for sub_line in sub_output.split("\n"): sub_line = sub_line.strip() if not sub_line or self._vg_name not in sub_line: continue sub_columns = sub_line.split(" ") return True if sub_columns[2].lower().startswith( "s") else False return None output = Helper.execute(["lvdisplay", "-c"]) lvs = [] if output: for line in output.split("\n"): line = line.strip() if not line: continue columns = line.split(":") if name and name not in columns[0]: continue if columns[1] == self._vg_name and not is_snapshot(columns[0]): lvs.append(LogicalVolume(columns[0])) return lvs
def rename_logical_volume(self, lv_name, new_lv_name): if lv_name and new_lv_name: output = Helper.execute( ["lvrename", self._vg_name, lv_name, new_lv_name]) if output and "Renamed \"" + lv_name + "\" to \"" + new_lv_name + "\" in volume group \"" + self._vg_name + "\"": return True return False
def remove_logical_volume(self, lv_name): if lv_name: output = Helper.execute( ["lvremove", "--force", self._vg_name + '/' + lv_name]) if output and 'Logical volume "' + lv_name + '" successfully removed' in output: return True return False
def remove_snapshot(self, snap_name): if snap_name: output = Helper.execute([ "lvremove", "--force", self.get_volume_group().get_name() + '/' + snap_name ]) if output and 'Logical volume "' + snap_name + '" successfully removed' in output: return True return False
def create_logical_volume(self, lv_name, size, unit="GiB"): if lv_name and size: output = Helper.execute([ "lvcreate", "--name", lv_name, "--size", str(size) + unit, "-W", "y", self._vg_name ]) if output and 'Logical volume "' + lv_name + '" created' in output: return True return False
def get_all(cls): output = Helper.execute(["vgdisplay", "-c"]) vgs = [] if output: for line in output.split("\n"): line = line.strip() if not line: continue vgs.append(VolumeGroup(line.split(":")[0])) return vgs
def create(cls, vg_name, pv_list): command = ["vgcreate", vg_name] if pv_list is list: command.extend(pv_list) else: command.append(pv_list) output = Helper.execute(command) if output and 'Volume group "' + vg_name + '" successfully created' in output: return True return False
def rename_snapshot(self, snap_name, new_snap_name): if snap_name and new_snap_name: output = Helper.execute([ "lvrename", self.get_volume_group().get_name(), snap_name, new_snap_name ]) if output and "Renamed \"" + snap_name + "\" to \"" + new_snap_name + "\" in volume group \"" + \ self.get_volume_group().get_name()+"\"": return True return False
def get_all(cls): output = Helper.execute(["pvdisplay", "-c"]) pvs = [] if output: for line in output.split("\n"): line = line.strip() if not line or "is a new physical volume of" in line: continue pvs.append(PhysicalVolume(line.split(":")[0])) return pvs
def create_snapshot(self, snapshot_name, size, unit="GiB"): command = [ "lvcreate", "--name", snapshot_name, "--snapshot", self._device_path, "--size", str(size) + unit ] output = Helper.execute(command) if output and 'Logical volume "' + snapshot_name + '" created' in output: return True return False
def is_snapshot(lv_path): sub_output = Helper.execute(["lvs", lv_path]) if sub_output: for sub_line in sub_output.split("\n"): sub_line = sub_line.strip() if not sub_line or self._vg_name not in sub_line: continue sub_columns = sub_line.split(" ") return True if sub_columns[2].lower().startswith( "s") else False return None
def contains_logical_volume(self, lv_name): output = Helper.execute(["lvdisplay", "-c"]) if output: for line in output.split("\n"): line = line.strip() if not line: continue columns = line.split(":") if lv_name in columns[0] and columns[1] == self._vg_name: return True return False
def get_info(self): output = Helper.execute(["pvdisplay", self._path_id]) if output: is_new = False info = Helper.format(output, "--- Physical volume ---") if not info: info = Helper.format(output, "--- NEW Physical volume ---") if info: is_new = True info["NEW"] = is_new return info return None
def get_physical_volumes(self, name=None): output = Helper.execute(["pvdisplay", "-c"]) pvs = [] if output: for line in output.split("\n"): line = line.strip() if not line: continue columns = line.split(":") if name and name not in columns[0]: continue if columns[1] == self._vg_name: pvs.append(PhysicalVolume(columns[0])) return pvs[0] if len(pvs) == 1 else pvs
def create(cls, disk_partition_path): output = Helper.execute(["pvcreate", disk_partition_path]) if output and 'Physical volume "' + disk_partition_path + '" successfully created.' in output: return True return False
def get_info(self): output = Helper.execute(["lvdisplay", self._device_path]) if output: return Helper.format(output, "--- Logical volume ---") return None
def exclude_physical_volume(self, pv): output = Helper.execute(["vgreduce", self._vg_name, pv.get_name()]) if output: return True return False
def remove(self): output = Helper.execute(["pvremove", self.get_path_id()]) if output and 'Labels on physical volume "' + self.get_path_id( ) + '" successfully wiped.' in output: return True return False
def remove(self): output = Helper.execute(["vgremove", self._vg_name]) if output and 'Volume group "' + self._vg_name + '" successfully removed' in output: self._vg_name = None return True return False