mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow passing negative numbers to specify partition boundary relative to disk end
Fixes: https://github.com/ansible/ansible/issues/43369
This commit is contained in:
parent
c2e37d202a
commit
41a51d88f9
2 changed files with 16 additions and 5 deletions
2
changelogs/fragments/parted_negative_numbers.yml
Normal file
2
changelogs/fragments/parted_negative_numbers.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "parted - accept negative numbers in ``part_start`` and ``part_end``"
|
|
@ -68,15 +68,17 @@ options:
|
|||
part_start:
|
||||
description:
|
||||
- Where the partition will start as offset from the beginning of the disk,
|
||||
that is, the "distance" from the start of the disk.
|
||||
that is, the "distance" from the start of the disk. Negative numbers
|
||||
specify distance from the end of the disk.
|
||||
- The distance can be specified with all the units supported by parted
|
||||
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
||||
type: str
|
||||
default: 0%
|
||||
part_end :
|
||||
part_end:
|
||||
description:
|
||||
- Where the partition will end as offset from the beginning of the disk,
|
||||
that is, the "distance" from the start of the disk.
|
||||
that is, the "distance" from the start of the disk. Negative numbers
|
||||
specify distance from the end of the disk.
|
||||
- The distance can be specified with all the units supported by parted
|
||||
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
||||
type: str
|
||||
|
@ -178,6 +180,13 @@ EXAMPLES = r'''
|
|||
state: present
|
||||
part_start: 1GiB
|
||||
|
||||
- name: Create a new primary partition with a size of 1GiB at disk's end
|
||||
parted:
|
||||
device: /dev/sdb
|
||||
number: 3
|
||||
state: present
|
||||
part_start: -1GiB
|
||||
|
||||
# Example on how to read info and reuse it in subsequent task
|
||||
- name: Read device information (always use unit when probing)
|
||||
parted: device=/dev/sdb unit=MiB
|
||||
|
@ -206,9 +215,9 @@ parted_units = units_si + units_iec + ['s', '%', 'cyl', 'chs', 'compact']
|
|||
|
||||
def parse_unit(size_str, unit=''):
|
||||
"""
|
||||
Parses a string containing a size of information
|
||||
Parses a string containing a size or boundary information
|
||||
"""
|
||||
matches = re.search(r'^([\d.]+)([\w%]+)?$', size_str)
|
||||
matches = re.search(r'^(-?[\d.]+)([\w%]+)?$', size_str)
|
||||
if matches is None:
|
||||
# "<cylinder>,<head>,<sector>" format
|
||||
matches = re.search(r'^(\d+),(\d+),(\d+)$', size_str)
|
||||
|
|
Loading…
Reference in a new issue