mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Pep8 fixes for parted (#24713)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
036ba7eeec
commit
ad41d0e88f
2 changed files with 44 additions and 46 deletions
|
@ -192,14 +192,13 @@ EXAMPLES = """
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
import locale
|
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
# Reference prefixes (International System of Units and IEC)
|
# Reference prefixes (International System of Units and IEC)
|
||||||
units_si = ['B', 'KB', 'MB', 'GB', 'TB']
|
units_si = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
units_iec = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
units_iec = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
parted_units = units_si + units_iec + ['s', '%', 'cyl', 'chs', 'compact']
|
parted_units = units_si + units_iec + ['s', '%', 'cyl', 'chs', 'compact']
|
||||||
|
|
||||||
|
@ -219,8 +218,8 @@ def parse_unit(size_str, unit=''):
|
||||||
|
|
||||||
size = {
|
size = {
|
||||||
'cylinder': int(matches.group(1)),
|
'cylinder': int(matches.group(1)),
|
||||||
'head': int(matches.group(2)),
|
'head': int(matches.group(2)),
|
||||||
'sector': int(matches.group(3))
|
'sector': int(matches.group(3))
|
||||||
}
|
}
|
||||||
unit = 'chs'
|
unit = 'chs'
|
||||||
|
|
||||||
|
@ -266,12 +265,12 @@ def parse_partition_info(parted_output, unit):
|
||||||
size, unit = parse_unit(generic_params[1], unit)
|
size, unit = parse_unit(generic_params[1], unit)
|
||||||
|
|
||||||
generic = {
|
generic = {
|
||||||
'dev': generic_params[0],
|
'dev': generic_params[0],
|
||||||
'size': size,
|
'size': size,
|
||||||
'unit': unit.lower(),
|
'unit': unit.lower(),
|
||||||
'table': generic_params[5],
|
'table': generic_params[5],
|
||||||
'model': generic_params[6],
|
'model': generic_params[6],
|
||||||
'logical_block': int(generic_params[3]),
|
'logical_block': int(generic_params[3]),
|
||||||
'physical_block': int(generic_params[4])
|
'physical_block': int(generic_params[4])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,9 +280,9 @@ def parse_partition_info(parted_output, unit):
|
||||||
cyl_size, cyl_unit = parse_unit(chs_info[3])
|
cyl_size, cyl_unit = parse_unit(chs_info[3])
|
||||||
generic['chs_info'] = {
|
generic['chs_info'] = {
|
||||||
'cylinders': int(chs_info[0]),
|
'cylinders': int(chs_info[0]),
|
||||||
'heads': int(chs_info[1]),
|
'heads': int(chs_info[1]),
|
||||||
'sectors': int(chs_info[2]),
|
'sectors': int(chs_info[2]),
|
||||||
'cyl_size': cyl_size,
|
'cyl_size': cyl_size,
|
||||||
'cyl_size_unit': cyl_unit.lower()
|
'cyl_size_unit': cyl_unit.lower()
|
||||||
}
|
}
|
||||||
lines = lines[1:]
|
lines = lines[1:]
|
||||||
|
@ -297,23 +296,23 @@ def parse_partition_info(parted_output, unit):
|
||||||
# behaviour down to parted version 1.8.3, which is the first version
|
# behaviour down to parted version 1.8.3, which is the first version
|
||||||
# that supports the machine parseable output.
|
# that supports the machine parseable output.
|
||||||
if unit != 'chs':
|
if unit != 'chs':
|
||||||
size = parse_unit(part_params[3])[0]
|
size = parse_unit(part_params[3])[0]
|
||||||
fstype = part_params[4]
|
fstype = part_params[4]
|
||||||
flags = part_params[6]
|
flags = part_params[6]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
size = ""
|
size = ""
|
||||||
fstype = part_params[3]
|
fstype = part_params[3]
|
||||||
flags = part_params[5]
|
flags = part_params[5]
|
||||||
|
|
||||||
parts.append({
|
parts.append({
|
||||||
'num': int(part_params[0]),
|
'num': int(part_params[0]),
|
||||||
'begin': parse_unit(part_params[1])[0],
|
'begin': parse_unit(part_params[1])[0],
|
||||||
'end': parse_unit(part_params[2])[0],
|
'end': parse_unit(part_params[2])[0],
|
||||||
'size': size,
|
'size': size,
|
||||||
'fstype': fstype,
|
'fstype': fstype,
|
||||||
'flags': [f.strip() for f in flags.split(', ') if f != ''],
|
'flags': [f.strip() for f in flags.split(', ') if f != ''],
|
||||||
'unit': unit.lower(),
|
'unit': unit.lower(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return {'generic': generic, 'partitions': parts}
|
return {'generic': generic, 'partitions': parts}
|
||||||
|
@ -380,23 +379,23 @@ def get_unlabeled_device_info(device, unit):
|
||||||
device_name = os.path.basename(device)
|
device_name = os.path.basename(device)
|
||||||
base = "/sys/block/%s" % device_name
|
base = "/sys/block/%s" % device_name
|
||||||
|
|
||||||
vendor = read_record(base + "/device/vendor", "Unknown")
|
vendor = read_record(base + "/device/vendor", "Unknown")
|
||||||
model = read_record(base + "/device/model", "model")
|
model = read_record(base + "/device/model", "model")
|
||||||
logic_block = int(read_record(base + "/queue/logical_block_size", 0))
|
logic_block = int(read_record(base + "/queue/logical_block_size", 0))
|
||||||
phys_block = int(read_record(base + "/queue/physical_block_size", 0))
|
phys_block = int(read_record(base + "/queue/physical_block_size", 0))
|
||||||
size_bytes = int(read_record(base + "/size", 0)) * logic_block
|
size_bytes = int(read_record(base + "/size", 0)) * logic_block
|
||||||
|
|
||||||
size, unit = format_disk_size(size_bytes, unit)
|
size, unit = format_disk_size(size_bytes, unit)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'generic': {
|
'generic': {
|
||||||
'dev': device,
|
'dev': device,
|
||||||
'table': "unknown",
|
'table': "unknown",
|
||||||
'size': size,
|
'size': size,
|
||||||
'unit': unit,
|
'unit': unit,
|
||||||
'logical_block': logic_block,
|
'logical_block': logic_block,
|
||||||
'physical_block': phys_block,
|
'physical_block': phys_block,
|
||||||
'model': "%s %s" % (vendor, model),
|
'model': "%s %s" % (vendor, model),
|
||||||
},
|
},
|
||||||
'partitions': []
|
'partitions': []
|
||||||
}
|
}
|
||||||
|
@ -472,7 +471,7 @@ def parted_version():
|
||||||
# Convert version to numbers
|
# Convert version to numbers
|
||||||
major = int(matches.group(1))
|
major = int(matches.group(1))
|
||||||
minor = int(matches.group(2))
|
minor = int(matches.group(2))
|
||||||
rev = 0
|
rev = 0
|
||||||
if matches.group(3) is not None:
|
if matches.group(3) is not None:
|
||||||
rev = int(matches.group(3))
|
rev = int(matches.group(3))
|
||||||
|
|
||||||
|
@ -587,17 +586,17 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
# Data extraction
|
# Data extraction
|
||||||
device = module.params['device']
|
device = module.params['device']
|
||||||
align = module.params['align']
|
align = module.params['align']
|
||||||
number = module.params['number']
|
number = module.params['number']
|
||||||
unit = module.params['unit']
|
unit = module.params['unit']
|
||||||
label = module.params['label']
|
label = module.params['label']
|
||||||
part_type = module.params['part_type']
|
part_type = module.params['part_type']
|
||||||
part_start = module.params['part_start']
|
part_start = module.params['part_start']
|
||||||
part_end = module.params['part_end']
|
part_end = module.params['part_end']
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
flags = module.params['flags']
|
flags = module.params['flags']
|
||||||
|
|
||||||
# Parted executable
|
# Parted executable
|
||||||
parted_exec = module.get_bin_path('parted', True)
|
parted_exec = module.get_bin_path('parted', True)
|
||||||
|
@ -668,7 +667,7 @@ def main():
|
||||||
if flags:
|
if flags:
|
||||||
# Compute only the changes in flags status
|
# Compute only the changes in flags status
|
||||||
flags_off = list(set(partition['flags']) - set(flags))
|
flags_off = list(set(partition['flags']) - set(flags))
|
||||||
flags_on = list(set(flags) - set(partition['flags']))
|
flags_on = list(set(flags) - set(partition['flags']))
|
||||||
|
|
||||||
for f in flags_on:
|
for f in flags_on:
|
||||||
script += "set %s %s on " % (number, f)
|
script += "set %s %s on " % (number, f)
|
||||||
|
|
|
@ -669,7 +669,6 @@ lib/ansible/modules/system/openwrt_init.py
|
||||||
lib/ansible/modules/system/osx_defaults.py
|
lib/ansible/modules/system/osx_defaults.py
|
||||||
lib/ansible/modules/system/pam_limits.py
|
lib/ansible/modules/system/pam_limits.py
|
||||||
lib/ansible/modules/system/pamd.py
|
lib/ansible/modules/system/pamd.py
|
||||||
lib/ansible/modules/system/parted.py
|
|
||||||
lib/ansible/modules/system/puppet.py
|
lib/ansible/modules/system/puppet.py
|
||||||
lib/ansible/modules/system/runit.py
|
lib/ansible/modules/system/runit.py
|
||||||
lib/ansible/modules/system/seboolean.py
|
lib/ansible/modules/system/seboolean.py
|
||||||
|
|
Loading…
Reference in a new issue