checking in before i restructure some stuff
This commit is contained in:
parent
af2cd9dd0e
commit
f96c815d8d
@ -1,3 +1,13 @@
|
|||||||
|
from . import disk
|
||||||
|
from . import system
|
||||||
|
from . import config
|
||||||
|
from . import constants
|
||||||
|
from . import envsetup
|
||||||
|
from . import log
|
||||||
|
from . import network
|
||||||
|
from . import pacman
|
||||||
|
from . import utils
|
||||||
|
|
||||||
class AIF(object):
|
class AIF(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
def xmlBool(xmlobj):
|
|
||||||
if isinstance(xmlobj, bool):
|
|
||||||
return (xmlobj)
|
|
||||||
if xmlobj.lower() in ('1', 'true'):
|
|
||||||
return(True)
|
|
||||||
elif xmlobj.lower() in ('0', 'false'):
|
|
||||||
return(False)
|
|
||||||
else:
|
|
||||||
return(None)
|
|
@ -5,10 +5,6 @@ import re
|
|||||||
import requests
|
import requests
|
||||||
from lxml import etree, objectify
|
from lxml import etree, objectify
|
||||||
|
|
||||||
_patterns = {'raw': re.compile(r'^\s*(?P<xml><(\?xml|aif)\s+.*)\s*$', re.DOTALL|re.MULTILINE),
|
|
||||||
'remote': re.compile(r'^(?P<uri>(?P<proto>(https?|ftps?)://)(?P<path>.*))\s*$'),
|
|
||||||
'local': re.compile(r'^(file://)?(?P<path>(/?[^/]+)+/?)$')}
|
|
||||||
|
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
def __init__(self, xsd_path = None, *args, **kwargs):
|
def __init__(self, xsd_path = None, *args, **kwargs):
|
||||||
@ -197,22 +193,21 @@ class ConfigBin(Config):
|
|||||||
return()
|
return()
|
||||||
|
|
||||||
|
|
||||||
|
detector = {'raw': (re.compile(r'^\s*(?P<xml><(\?xml|aif)\s+.*)\s*$', re.DOTALL | re.MULTILINE), ConfigStr),
|
||||||
|
'remote': (re.compile(r'^(?P<uri>(?P<proto>(https?|ftps?)://)(?P<path>.*))\s*$'), RemoteFile),
|
||||||
|
'local': (re.compile(r'^(file://)?(?P<path>(/?[^/]+)+/?)$'), LocalFile)}
|
||||||
|
|
||||||
|
|
||||||
def getConfig(cfg_ref, validate = True, populate_defaults = True, xsd_path = None):
|
def getConfig(cfg_ref, validate = True, populate_defaults = True, xsd_path = None):
|
||||||
cfgobj = None
|
cfgobj = None
|
||||||
# This is kind of gross.
|
# This is kind of gross.
|
||||||
for configtype, pattern in _patterns.items():
|
for configtype, (pattern, configClass) in detector.items():
|
||||||
try:
|
try:
|
||||||
if pattern.search(cfg_ref):
|
if pattern.search(cfg_ref):
|
||||||
if configtype == 'raw':
|
cfgobj = configClass(cfg_ref, xsd_path = xsd_path)
|
||||||
cfgobj = ConfigStr(cfg_ref, xsd_path = xsd_path)
|
break
|
||||||
elif configtype == 'remote':
|
|
||||||
cfgobj = RemoteFile(cfg_ref, xsd_path = xsd_path)
|
|
||||||
elif configtype == 'local':
|
|
||||||
cfgobj = LocalFile(cfg_ref, xsd_path = xsd_path)
|
|
||||||
if cfgobj:
|
|
||||||
break
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
ptrn = re.compile(_patterns['raw'].pattern.encode('utf-8'))
|
ptrn = re.compile(detector['raw'][0].pattern.encode('utf-8'))
|
||||||
if not ptrn.search(cfg_ref):
|
if not ptrn.search(cfg_ref):
|
||||||
raise ValueError('Received junk data for cfg_ref')
|
raise ValueError('Received junk data for cfg_ref')
|
||||||
else:
|
else:
|
||||||
|
@ -18,7 +18,7 @@ import blkinfo
|
|||||||
import parted # https://www.gnu.org/software/parted/api/index.html
|
import parted # https://www.gnu.org/software/parted/api/index.html
|
||||||
import psutil
|
import psutil
|
||||||
##
|
##
|
||||||
from aif.aif_util import xmlBool
|
from aif.utils import xmlBool
|
||||||
|
|
||||||
|
|
||||||
PARTED_FSTYPES = sorted(list(dict(vars(parted.filesystem))['fileSystemType'].keys()))
|
PARTED_FSTYPES = sorted(list(dict(vars(parted.filesystem))['fileSystemType'].keys()))
|
||||||
@ -148,6 +148,9 @@ class Partition(object):
|
|||||||
_pedpart = self.partition.getPedPartition()
|
_pedpart = self.partition.getPedPartition()
|
||||||
_pedpart.set_name(self.xml.attrib.get('name'))
|
_pedpart.set_name(self.xml.attrib.get('name'))
|
||||||
|
|
||||||
|
def detect(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Disk(object):
|
class Disk(object):
|
||||||
def __init__(self, disk_xml):
|
def __init__(self, disk_xml):
|
||||||
|
@ -3,6 +3,7 @@ import datetime
|
|||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import uuid
|
||||||
##
|
##
|
||||||
import mdstat
|
import mdstat
|
||||||
##
|
##
|
||||||
@ -88,7 +89,7 @@ class Member(object):
|
|||||||
v = re.sub(r'^raid', '', v)
|
v = re.sub(r'^raid', '', v)
|
||||||
elif k == 'checksum':
|
elif k == 'checksum':
|
||||||
cksum, status = [i.strip() for i in v.split('-')]
|
cksum, status = [i.strip() for i in v.split('-')]
|
||||||
v = (int(cksum), status)
|
v = (bytes.fromhex(cksum), status)
|
||||||
elif k == 'unused_space':
|
elif k == 'unused_space':
|
||||||
r = _mdblock_unused_re.search(v)
|
r = _mdblock_unused_re.search(v)
|
||||||
if not r:
|
if not r:
|
||||||
@ -108,6 +109,10 @@ class Member(object):
|
|||||||
v = {}
|
v = {}
|
||||||
for i in ('entries', 'offset'):
|
for i in ('entries', 'offset'):
|
||||||
v[i] = int(r.group(i)) # offset is in sectors
|
v[i] = int(r.group(i)) # offset is in sectors
|
||||||
|
elif k == 'array_state':
|
||||||
|
v = [i.strip() for i in v.split(None, 1)][0].split()
|
||||||
|
elif k == 'device_uuid':
|
||||||
|
v = uuid.UUID(hex = v.replace(':', '-'))
|
||||||
elif re.search((r'^(creation|update)_time$'), k):
|
elif re.search((r'^(creation|update)_time$'), k):
|
||||||
# TODO: Is this portable/correct? Or do I need to do '%a %b %d %H:%M:%s %Y'?
|
# TODO: Is this portable/correct? Or do I need to do '%a %b %d %H:%M:%s %Y'?
|
||||||
v = datetime.datetime.strptime(v, '%c')
|
v = datetime.datetime.strptime(v, '%c')
|
||||||
@ -119,7 +124,9 @@ class Member(object):
|
|||||||
self.devpath))
|
self.devpath))
|
||||||
v = {}
|
v = {}
|
||||||
for i in ('sectors', 'GB', 'GiB'):
|
for i in ('sectors', 'GB', 'GiB'):
|
||||||
v[i] = int(r.group(i))
|
v[i] = float(r.group(i))
|
||||||
|
if i == 'sectors':
|
||||||
|
v[i] = int(v[i])
|
||||||
elif re.search(r'^(data|super)_offset$', k):
|
elif re.search(r'^(data|super)_offset$', k):
|
||||||
v = int(v.split(None, 1)[0])
|
v = int(v.split(None, 1)[0])
|
||||||
block[k] = v
|
block[k] = v
|
||||||
|
75
aif/utils.py
Normal file
75
aif/utils.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
def xmlBool(xmlobj):
|
||||||
|
# https://bugs.launchpad.net/lxml/+bug/1850221
|
||||||
|
if isinstance(xmlobj, bool):
|
||||||
|
return (xmlobj)
|
||||||
|
if xmlobj.lower() in ('1', 'true'):
|
||||||
|
return(True)
|
||||||
|
elif xmlobj.lower() in ('0', 'false'):
|
||||||
|
return(False)
|
||||||
|
else:
|
||||||
|
return(None)
|
||||||
|
|
||||||
|
class _Sizer(object):
|
||||||
|
def __init__(self):
|
||||||
|
def _getKeys(d, keylist = None):
|
||||||
|
if not keylist:
|
||||||
|
keylist = []
|
||||||
|
for k, v in d.items():
|
||||||
|
if isinstance(v, dict):
|
||||||
|
keylist.append(k)
|
||||||
|
keylist = _getKeys(v, keylist = keylist)
|
||||||
|
else:
|
||||||
|
keylist.append(k)
|
||||||
|
return (keylist)
|
||||||
|
# We use different methods for converting between storage and BW, and different multipliers for each subtype.
|
||||||
|
# https://stackoverflow.com/questions/5194057/better-way-to-convert-file-sizes-in-python
|
||||||
|
# https://en.wikipedia.org/wiki/Orders_of_magnitude_(data)
|
||||||
|
# https://en.wikipedia.org/wiki/Binary_prefix
|
||||||
|
self.storageUnits = {'decimal': {'B': 0,
|
||||||
|
'kB': 7, # Kilobyte
|
||||||
|
'MB': 17, # Megabyte...
|
||||||
|
'GB': 27,
|
||||||
|
'TB': 37},
|
||||||
|
'binary': {'KiB': 10, # Kibibyte
|
||||||
|
'MiB': 20, # Mebibyte...
|
||||||
|
'GiB': 30,
|
||||||
|
'TiB': 40}}
|
||||||
|
# https://en.wikipedia.org/wiki/Bit#Multiple_bits
|
||||||
|
self.bwUnits = {'b': None,
|
||||||
|
'bit': None,
|
||||||
|
'k': }
|
||||||
|
self.valid_storage = list(self.storageUnits.keys())
|
||||||
|
self.valid_storage.insert('nibble')
|
||||||
|
self.valid_bw = _getKeys(self.bwUnits)
|
||||||
|
|
||||||
|
def convert(self, n, suffix, target = None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def convertBW(self, n, suffix, target = None):
|
||||||
|
inBits = n
|
||||||
|
if suffix not in self.valid_bw:
|
||||||
|
raise ValueError('suffix must be one of {0}'.format(', '.format(self.valid_bw)))
|
||||||
|
if suffix != 'b':
|
||||||
|
if self.bwUnits[suffix]:
|
||||||
|
inBits = n * (10 ** self.bwUnits[suffix])
|
||||||
|
else:
|
||||||
|
inBits = None
|
||||||
|
|
||||||
|
def convertStorage(self, n, suffix, target = None):
|
||||||
|
inBytes = n
|
||||||
|
if suffix not in self.valid_storage:
|
||||||
|
raise ValueError('suffix must be one of {0}'.format(', '.format(self.valid_storage)))
|
||||||
|
if suffix == 'nibble':
|
||||||
|
inBytes = n * 0.5
|
||||||
|
elif suffix != 'B':
|
||||||
|
inBytes = float(n << self.storageUnits[suffix])
|
||||||
|
if target:
|
||||||
|
conversion = float(inBytes / float(1 << self.storageUnits[target]))
|
||||||
|
else:
|
||||||
|
conversion = {}
|
||||||
|
for unit, shifter in self.storageUnits.items():
|
||||||
|
conversion[unit] = float(inBytes / float(1 << self.storageUnits[unit]))
|
||||||
|
return(conversion)
|
||||||
|
|
||||||
|
|
||||||
|
size = _Sizer()
|
@ -23,9 +23,11 @@
|
|||||||
<part id="raid1_d2" start="55%" stop="80%" fsType="ext4">
|
<part id="raid1_d2" start="55%" stop="80%" fsType="ext4">
|
||||||
<partitionFlag>raid</partitionFlag>
|
<partitionFlag>raid</partitionFlag>
|
||||||
</part>
|
</part>
|
||||||
<part id="swap" start="80%" stop="100%" fsType="linux-swap(v1)">
|
<part id="swap" start="80%" stop="90%" fsType="linux-swap(v1)">
|
||||||
<partitionFlag>swap</partitionFlag>
|
<partitionFlag>swap</partitionFlag>
|
||||||
</part>
|
</part>
|
||||||
|
<!-- You can also create a partition with no flags (and not use). -->
|
||||||
|
<part id="grow" start="90%" stop="100%" fsType="ext4"/>
|
||||||
</disk>
|
</disk>
|
||||||
</blockDevices>
|
</blockDevices>
|
||||||
<!-- "Special" devices are processed *in the order they are specified*. This is important if you wish to
|
<!-- "Special" devices are processed *in the order they are specified*. This is important if you wish to
|
||||||
|
Loading…
Reference in New Issue
Block a user