From 4cdd61da7bf96429358cc84ffb91b6c144484370 Mon Sep 17 00:00:00 2001 From: brent s Date: Tue, 29 Oct 2019 15:42:09 -0400 Subject: [PATCH] adding partition flags --- aif.xsd | 1 + aif/disk/block.py | 16 +++++++++++++++- aif/disk/mdadm.py | 4 ++-- examples/aif.xml | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/aif.xsd b/aif.xsd index fdc1b91..2a01ea0 100644 --- a/aif.xsd +++ b/aif.xsd @@ -224,6 +224,7 @@ + diff --git a/aif/disk/block.py b/aif/disk/block.py index 76db82f..e6f680f 100644 --- a/aif/disk/block.py +++ b/aif/disk/block.py @@ -21,7 +21,10 @@ import psutil from aif.aif_util import xmlBool -PARTED_FSTYPES = list(dict(vars(parted.filesystem))['fileSystemType'].keys()) +PARTED_FSTYPES = sorted(list(dict(vars(parted.filesystem))['fileSystemType'].keys())) +PARTED_FLAGS = sorted(list(parted.partition.partitionFlag.values())) +IDX_FLAG = dict(parted.partition.partitionFlag) +FLAG_IDX = {v: k for k, v in IDX_FLAG.items()} # parted lib can do SI or IEC (see table to right at https://en.wikipedia.org/wiki/Binary_prefix) # We bit-shift to do conversions: @@ -70,6 +73,11 @@ class Partition(object): 'primary, extended, or logical partition for msdos partition tables')) self.xml = part_xml self.id = part_xml.attrib['id'] + self.flags = set() + for f in self.xml.findall('partitionFlag'): + if f.text in PARTED_FLAGS: + self.flags.add(f.text) + self.flags = sorted(list(self.flags)) self.partnum = partnum if tbltype == 'msdos': if partnum > 4: @@ -126,6 +134,12 @@ class Partition(object): type = self.part_type, geometry = self.geometry, fs = self.filesystem) + for f in self.flags[:]: + flag_id = FLAG_IDX[f] + if self.partition.isFlagAvailable(flag_id): + self.partition.setFlag(flag_id) + else: + self.flags.remove(f) if tbltype == 'gpt' and self.xml.attrib.get('name'): # The name attribute setting is b0rk3n, so we operate on the underlying PedPartition object. # https://github.com/dcantrell/pyparted/issues/49#issuecomment-540096687 diff --git a/aif/disk/mdadm.py b/aif/disk/mdadm.py index 4c60c22..c852d04 100644 --- a/aif/disk/mdadm.py +++ b/aif/disk/mdadm.py @@ -87,8 +87,8 @@ class Array(object): def addMember(self, memberobj): if not isinstance(memberobj, Member): raise ValueError('memberobj must be of type aif.disk.mdadm.Member') - - pass + memberobj.prepare() + self.members.append(memberobj) return() def assemble(self, scan = False): diff --git a/examples/aif.xml b/examples/aif.xml index 27f62dd..11b08e3 100644 --- a/examples/aif.xml +++ b/examples/aif.xml @@ -60,7 +60,7 @@ - +