mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
modules [lm]*: use f-strings (#10971)
* modules [lm]*: use f-strings * add changelog frag
This commit is contained in:
@@ -109,9 +109,9 @@ def main():
|
||||
|
||||
# Validate device existence
|
||||
if not os.path.exists(source):
|
||||
module.fail_json(msg="Source device %s not found" % source)
|
||||
module.fail_json(msg=f"Source device {source} not found")
|
||||
if not os.path.exists(destination):
|
||||
module.fail_json(msg="Destination device %s not found" % destination)
|
||||
module.fail_json(msg=f"Destination device {destination} not found")
|
||||
if source == destination:
|
||||
module.fail_json(msg="Source and destination devices must be different")
|
||||
|
||||
@@ -120,7 +120,7 @@ def main():
|
||||
rc, out, err = ctx.run(device=device)
|
||||
if rc != 0:
|
||||
module.fail_json(
|
||||
msg="Command failed: %s" % err,
|
||||
msg=f"Command failed: {err}",
|
||||
stdout=out,
|
||||
stderr=err,
|
||||
rc=rc,
|
||||
@@ -136,22 +136,22 @@ def main():
|
||||
return rc == 0
|
||||
|
||||
if not is_pv(source):
|
||||
module.fail_json(msg="Source device %s is not a PV" % source)
|
||||
module.fail_json(msg=f"Source device {source} is not a PV")
|
||||
if not is_pv(destination):
|
||||
module.fail_json(msg="Destination device %s is not a PV" % destination)
|
||||
module.fail_json(msg=f"Destination device {destination} is not a PV")
|
||||
|
||||
vg_src = run_pvs_command("noheadings vg_name device", source)
|
||||
vg_dest = run_pvs_command("noheadings vg_name device", destination)
|
||||
if vg_src != vg_dest:
|
||||
module.fail_json(
|
||||
msg="Source and destination must be in the same VG. Source VG: '%s', Destination VG: '%s'." % (vg_src, vg_dest)
|
||||
msg=f"Source and destination must be in the same VG. Source VG: '{vg_src}', Destination VG: '{vg_dest}'."
|
||||
)
|
||||
|
||||
def get_allocated_pe(device):
|
||||
try:
|
||||
return int(run_pvs_command("noheadings pv_pe_alloc_count device", device))
|
||||
except ValueError:
|
||||
module.fail_json(msg="Invalid allocated PE count for device %s" % device)
|
||||
module.fail_json(msg=f"Invalid allocated PE count for device {device}")
|
||||
|
||||
allocated = get_allocated_pe(source)
|
||||
if allocated == 0:
|
||||
@@ -162,7 +162,7 @@ def main():
|
||||
try:
|
||||
return int(run_pvs_command("noheadings pv_pe_count device", device))
|
||||
except ValueError:
|
||||
module.fail_json(msg="Invalid total PE count for device %s" % device)
|
||||
module.fail_json(msg=f"Invalid total PE count for device {device}")
|
||||
|
||||
def get_free_pe(device):
|
||||
return get_total_pe(device) - get_allocated_pe(device)
|
||||
@@ -170,13 +170,13 @@ def main():
|
||||
free_pe_dest = get_free_pe(destination)
|
||||
if free_pe_dest < allocated:
|
||||
module.fail_json(
|
||||
msg="Destination device %s has only %d free physical extents, but source device %s has %d allocated extents. Not enough space." %
|
||||
(destination, free_pe_dest, source, allocated)
|
||||
msg=(f"Destination device {destination} has only {int(free_pe_dest)} free physical extents, but "
|
||||
f"source device {source} has {int(allocated)} allocated extents. Not enough space.")
|
||||
)
|
||||
|
||||
if module.check_mode:
|
||||
changed = True
|
||||
actions.append('would move data from %s to %s' % (source, destination))
|
||||
actions.append(f'would move data from {source} to {destination}')
|
||||
else:
|
||||
pvmove_runner = CmdRunner(
|
||||
module,
|
||||
@@ -185,7 +185,7 @@ def main():
|
||||
auto_answer=cmd_runner_fmt.as_bool("-y"),
|
||||
atomic=cmd_runner_fmt.as_bool("--atomic"),
|
||||
autobackup=cmd_runner_fmt.as_fixed("--autobackup", "y" if module.params['autobackup'] else "n"),
|
||||
verbosity=cmd_runner_fmt.as_func(lambda v: ['-' + 'v' * v] if v > 0 else []),
|
||||
verbosity=cmd_runner_fmt.as_func(lambda v: [f"-{'v' * v}"] if v > 0 else []),
|
||||
source=cmd_runner_fmt.as_list(),
|
||||
destination=cmd_runner_fmt.as_list(),
|
||||
)
|
||||
@@ -202,14 +202,14 @@ def main():
|
||||
result['stderr'] = err
|
||||
|
||||
changed = True
|
||||
actions.append('moved data from %s to %s' % (source, destination))
|
||||
actions.append(f'moved data from {source} to {destination}')
|
||||
|
||||
result['changed'] = changed
|
||||
result['actions'] = actions
|
||||
if actions:
|
||||
result['msg'] = "PV data move: %s" % ", ".join(actions)
|
||||
result['msg'] = f"PV data move: {', '.join(actions)}"
|
||||
else:
|
||||
result['msg'] = "No data to move from %s" % source
|
||||
result['msg'] = f"No data to move from {source}"
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user