def __call__(self, context: CommandContext) -> Iterator[Command]: file_path = context.graph.resolve_path(self.specification.name) if not file_path: raise ValueError("Failed to find file path {}".format( self.specification.name)) media_file_path = context.config.media_path(file_path) yield mkdir(os.path.dirname(media_file_path)) if self.specification.size: yield Command([ "fallocate", "--length", self.specification.size, quote_argument(media_file_path), ]) else: yield Command(["touch", quote_argument(media_file_path)]) if self.specification.owner or self.specification.group: yield chown( self.specification.owner, self.specification.group, media_file_path, ) if self.specification.mode: yield chmod(self.specification.mode, media_file_path)
def _format_crypt( context: CommandContext, device: str, keyfile: str, type: str, password: Optional[str], ) -> Iterator[Command]: yield Command( _cryptsetup( f"--key-file={quote_argument(keyfile)}", "luksFormat", f"--type={type}", quote_argument(device), )) if password: add_key_cmd = " ".join( _cryptsetup( f"--key-file={quote_argument(keyfile)}", "luksAddKey", quote_argument(device), )) yield Command([ quote_argument(context.config.shell), "-c", quote_subcommand(f"echo {password} | {add_key_cmd}"), ])
def __call__(self, context: CommandContext) -> Iterator[Command]: yield from super().__call__(context) identify_path = None if self.specification.device: device_path = _device_path(self.specification.device, context) command = f"# {self.specification.name} (originally {device_path})" identify_path = identify_device_path(self.specification.identify, device_path) else: command = f"# {self.specification.name}" identify_path = self.specification.type mountpoint_path = _mountpoint_path(self.specification.mountpoint, context) fstab_entry = [ "", command, "\\t".join([ quote_argument(identify_path), quote_argument(mountpoint_path), quote_argument(self.specification.type), quote_argument(",".join(self.specification.options)), str(self.specification.dump_frequency or 0), str(self.specification.fsck_order or 0), ]), ] yield fstab_append(context, "\\n".join(fstab_entry))
def __call__(self, context: CommandContext) -> Iterator[Command]: device_paths = [ _device_path(device, context) for device in self.specification.devices ] cmd = [ "mdadm", "--assemble", quote_argument(_raid_device(self.specification.name)), ] yield Command(cmd + [quote_argument(path) for path in device_paths])
def __call__(self, context: CommandContext) -> Iterator[Command]: device_path = context.graph.resolve_device(self.specification.device) if not device_path: raise ValueError("Failed to find device path {}".format( self.specification.device)) yield Command(["pvcreate", quote_argument(device_path)])
def __call__(self, context: CommandContext) -> Iterator[Command]: lvm_physical_volume_paths = [ _lvm_physical_volume_path(lvm_physical_volume, context) for lvm_physical_volume in self.specification.lvm_physical_volumes ] cmd = [ "lvcreate", f"--name={self.specification.name}", ] if self.specification.size: cmd.append(f"--size={self.specification.size}") if self.specification.extents: cmd.append(f"--extents={self.specification.extents}") if self.specification.type: cmd.append(f"--type={self.specification.type}") if self.specification.lvm_poolmetadata_volume: cmd.append( f"--poolmetadata={self.specification.lvm_poolmetadata_volume}", ) if self.specification.lvm_cachepool_volume: cmd.append(f"--cachepool={self.specification.lvm_cachepool_volume}") if self.specification.lvm_thinpool_volume: cmd.append(f"--thinpool={self.specification.lvm_thinpool_volume}") cmd += self.specification.args cmd.append(self.specification.lvm_volume_group) cmd += [quote_argument(path) for path in lvm_physical_volume_paths] yield Command(cmd)
def __call__(self, context: CommandContext) -> Iterator[Command]: partition_table_path = context.graph.resolve_device( self.specification.partition_table) if not partition_table_path: raise ValueError("Failed to find partition table path {}".format( self.specification.partition_table)) cmd = [ quote_argument(partition_table_path), "mkpart", self.specification.type, self.specification.start, self.specification.end, ] if self.specification.label: cmd += [ "name", str(self.specification.number), self.specification.label, ] if self.specification.unit: cmd += ["unit", self.specification.unit] for flag in self.specification.flags: cmd += ["set", str(self.specification.number), flag, "on"] yield parted(*cmd, align=self.specification.align)
def __call__(self, context: CommandContext) -> Iterator[Command]: device_path = context.graph.resolve_device(self.specification.device) if not device_path: raise ValueError( "Failed to find device path {}".format(self.specification.device) ) yield parted(quote_argument(device_path), "mklabel", self.specification.type)
def __call__(self, context: CommandContext) -> Iterator[Command]: device_paths = [ _device_path(device, context) for device in self.specification.devices ] cmd = [ "mdadm", "--create", f"--name={self.specification.name}", f"--level={self.specification.level}", f"--metadata={self.specification.metadata}", f"--raid-devices={len(self.specification.devices)}", quote_argument(_raid_device(self.specification.name)), ] yield Command(cmd + [quote_argument(path) for path in device_paths])
def __call__(self, context: CommandContext) -> Iterator[Command]: lvm_physical_volume_paths = [ _lvm_physical_volume_path(lvm_physical_volume, context) for lvm_physical_volume in self.specification.lvm_physical_volumes ] yield Command( ["vgcreate", self.specification.name] + [quote_argument(path) for path in lvm_physical_volume_paths])
def __call__(self, context: CommandContext) -> Iterator[Command]: mount_cmd = ["mount"] if self.specification.type: mount_cmd += ["--types", quote_argument(self.specification.type)] if self.specification.options: mount_cmd += [ "-o", quote_argument(",".join(self.specification.options)) ] if self.specification.device: device_path = _device_path(self.specification.device, context) mount_cmd.append(quote_argument(device_path)) else: mount_cmd.append(quote_argument(self.specification.type)) mountpoint_path = _mountpoint_path(self.specification.mountpoint, context) media_mountpoint_path = context.config.media_path(mountpoint_path) mount_cmd.append(quote_argument(media_mountpoint_path)) yield Command(mount_cmd)
def __call__(self, context: CommandContext) -> Iterator[Command]: file_path = _file_path(self.specification.file, context) media_file_path = context.config.media_path(file_path) cmd = [ "losetup", *self.specification.args, "--find", "--show", quote_argument(media_file_path), ] yield Command(cmd, capture=self.specification.capture)
def _open_crypt( name: str, device: str, keyfile: str, type: Optional[str], ) -> List[str]: return _cryptsetup( f"--key-file={quote_argument(keyfile)}", "open", quote_argument(device), name, *([f"--type={type}"] if type is not None else []), )
def __call__(self, context: CommandContext) -> Iterator[Command]: device_path = _device_path(self.specification.device, context) cmd = ["mkswap", quote_argument(device_path)] if self.specification.label: cmd.append(f"--label={self.specification.label}") if self.specification.pagesize: cmd.append(f"--pagesize={self.specification.pagesize}") if self.specification.uuid: cmd.append(f"--uuid={self.specification.uuid}") yield Command(cmd) yield from super().__call__(context) identify_path = identify_device_path(self.specification.identify, device_path) fstab_entry = [ "", f"# {self.specification.name} (originally {device_path})", "\\t".join([identify_path, "none", "swap", "defaults", "0", "0"]), ] yield fstab_append(context, "\\n".join(fstab_entry))
def __call__(self, context: CommandContext) -> Iterator[Command]: device_path = _device_path(self.specification.device, context) yield Command(["mkfs", "--type", self.specification.type] + list(self.specification.options) + [quote_argument(device_path)])
def __call__(self, context: CommandContext) -> Iterator[Command]: mountpoint_path = _mountpoint_path(self.specification.mountpoint, context) media_mountpoint_path = context.config.media_path(mountpoint_path) yield Command(["umount", quote_argument(media_mountpoint_path)])
def __call__(self, context: CommandContext) -> Iterator[Command]: device_path = _device_path(self.specification.device, context) yield Command(["swapoff", quote_argument(device_path)])
def __call__(self, context: CommandContext) -> Iterator[Command]: yield Command([ "mdadm", "--stop", quote_argument(_raid_device(self.specification.name)), ])
def _find_loop_device(file_path: str) -> str: quoted_file_path = quote_argument(file_path) quoted_expression = quote_argument("s#:.*##") return f"losetup --associated {quoted_file_path} | sed {quoted_expression}"
def __call__(self, context: CommandContext) -> Iterator[Command]: yield Command( ["losetup", "--detach", quote_argument(f"${self.specification.capture}")] )