Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 def get_partitions(self):
     metadata = Helper.execute_fdisk(self.get_path())
     partitions = []
     if metadata:
         partition_section_columns = 0
         for line in metadata.split("\n"):
             line = line.strip()
             if not line:
                 continue
             match = re.search("Sector size .*?: (\d+) bytes", line)
             if match:
                 self.set_sector_size(int(match.group(1)))
                 continue
             if re.search(r"Device\s+Boot\s+Start\s+End", line):
                 partition_section_columns = len(line.split())
                 continue
             if partition_section_columns > 0:
                 splits = line.split()
                 if re.search(r"\d+", splits[1]):
                     splits.insert(1, False)
                 else:
                     splits[1] = True
                 if len(splits) > 7:
                     extra_splits = splits[8:]
                     splits[7] += ' ' + ' '.join(extra_splits)
                     for extra_split in extra_splits:
                         splits.remove(extra_split)
                 partitions.append(Partition(splits[0], splits[1:]))
     return partitions
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 def mount(self, mount_location):
     for partition in self.get_partitions():
         if partition.compute_size() <= 1:  # self.get_sector_size(), "gb"
             continue
         offset = partition.get_sector_start() * self.get_sector_size()
         output = Helper.execute_mount(self.get_path(), offset,
                                       mount_location)
         if not output:
             return True
     return False
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 def get_all():
     fd_output = Helper.execute_fdisk()
     disks = []
     if fd_output:
         for line in fd_output.split("\n"):
             line = line.strip()
             if not line:
                 continue
             match = re.search(r"^Disk\s+(\\dev\\sd[a-z]):", line)
             if match:
                 disks.append(match.group(1))
     return disks
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 def restore_from_image(self, source_path):
     return Helper.execute_dd(source_path, self.get_path())
Exemplo n.º 19
0
 def dump_to_image(self, destination_path):
     return Helper.execute_dd(self.get_path(), destination_path)
Exemplo n.º 20
0
 def get_info(self):
     output = Helper.execute(["lvdisplay", self._device_path])
     if output:
         return Helper.format(output, "--- Logical volume ---")
     return None
Exemplo n.º 21
0
 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
Exemplo n.º 22
0
 def exclude_physical_volume(self, pv):
     output = Helper.execute(["vgreduce", self._vg_name, pv.get_name()])
     if output:
         return True
     return False
Exemplo n.º 23
0
 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
Exemplo n.º 24
0
 def unmount(self, mount_location):
     output = Helper.execute_umount(mount_location)
     if not output:
         return True
     return False
Exemplo n.º 25
0
 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