future proofing is good, but...
since print() was made a function in py3, i can predict at some point that return will be made a func as well. sure, good. but "return()" *currently* returns an empty tuple. We want to explicitly return None for testing purposes.
This commit is contained in:
parent
a1bc613979
commit
d7d85c7d9d
@ -26,11 +26,11 @@ class Config(object):
|
|||||||
if validate:
|
if validate:
|
||||||
self.validate()
|
self.validate()
|
||||||
self.pythonize()
|
self.pythonize()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def fetch(self): # Just a fail-safe; this is overridden by specific subclasses.
|
def fetch(self): # Just a fail-safe; this is overridden by specific subclasses.
|
||||||
pass
|
pass
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getXSD(self, xsdpath = None):
|
def getXSD(self, xsdpath = None):
|
||||||
if not xsdpath:
|
if not xsdpath:
|
||||||
@ -62,7 +62,7 @@ class Config(object):
|
|||||||
raw_xsd = req.content
|
raw_xsd = req.content
|
||||||
base_url = os.path.split(req.url)[0] # This makes me feel dirty.
|
base_url = os.path.split(req.url)[0] # This makes me feel dirty.
|
||||||
self.xsd = etree.XMLSchema(etree.XML(raw_xsd, base_url = base_url))
|
self.xsd = etree.XMLSchema(etree.XML(raw_xsd, base_url = base_url))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def parseRaw(self, parser = None):
|
def parseRaw(self, parser = None):
|
||||||
# self.xml = etree.parse(self.raw, parser = parser)
|
# self.xml = etree.parse(self.raw, parser = parser)
|
||||||
@ -74,7 +74,7 @@ class Config(object):
|
|||||||
self.tree.xinclude()
|
self.tree.xinclude()
|
||||||
self.namespaced_tree.xinclude()
|
self.namespaced_tree.xinclude()
|
||||||
self.stripNS()
|
self.stripNS()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def populateDefaults(self):
|
def populateDefaults(self):
|
||||||
if not self.xsd:
|
if not self.xsd:
|
||||||
@ -82,7 +82,7 @@ class Config(object):
|
|||||||
if not self.defaultsParser:
|
if not self.defaultsParser:
|
||||||
self.defaultsParser = etree.XMLParser(schema = self.xsd, attribute_defaults = True)
|
self.defaultsParser = etree.XMLParser(schema = self.xsd, attribute_defaults = True)
|
||||||
self.parseRaw(parser = self.defaultsParser)
|
self.parseRaw(parser = self.defaultsParser)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def pythonize(self, stripped = True, obj = 'tree'):
|
def pythonize(self, stripped = True, obj = 'tree'):
|
||||||
# https://bugs.launchpad.net/lxml/+bug/1850221
|
# https://bugs.launchpad.net/lxml/+bug/1850221
|
||||||
@ -90,11 +90,11 @@ class Config(object):
|
|||||||
self.obj = objectify.fromstring(strobj)
|
self.obj = objectify.fromstring(strobj)
|
||||||
objectify.annotate(self.obj)
|
objectify.annotate(self.obj)
|
||||||
objectify.xsiannotate(self.obj)
|
objectify.xsiannotate(self.obj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def removeDefaults(self):
|
def removeDefaults(self):
|
||||||
self.parseRaw()
|
self.parseRaw()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stripNS(self, obj = None):
|
def stripNS(self, obj = None):
|
||||||
# https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635
|
# https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635
|
||||||
@ -110,7 +110,7 @@ class Config(object):
|
|||||||
return(obj)
|
return(obj)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Did not know how to parse obj parameter')
|
raise ValueError('Did not know how to parse obj parameter')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def toString(self, stripped = False, obj = None):
|
def toString(self, stripped = False, obj = None):
|
||||||
if isinstance(obj, (etree._Element, etree._ElementTree)):
|
if isinstance(obj, (etree._Element, etree._ElementTree)):
|
||||||
@ -142,7 +142,7 @@ class Config(object):
|
|||||||
if not self.xsd:
|
if not self.xsd:
|
||||||
self.getXSD()
|
self.getXSD()
|
||||||
self.xsd.assertValid(self.namespaced_tree)
|
self.xsd.assertValid(self.namespaced_tree)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class LocalFile(Config):
|
class LocalFile(Config):
|
||||||
@ -157,7 +157,7 @@ class LocalFile(Config):
|
|||||||
raise ValueError('{0} does not exist'.format(self.source))
|
raise ValueError('{0} does not exist'.format(self.source))
|
||||||
with open(self.source, 'rb') as fh:
|
with open(self.source, 'rb') as fh:
|
||||||
self.raw = fh.read()
|
self.raw = fh.read()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class RemoteFile(Config):
|
class RemoteFile(Config):
|
||||||
@ -171,7 +171,7 @@ class RemoteFile(Config):
|
|||||||
if not r.ok():
|
if not r.ok():
|
||||||
raise RuntimeError('Could not download XML')
|
raise RuntimeError('Could not download XML')
|
||||||
self.raw = r.content
|
self.raw = r.content
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class ConfigStr(Config):
|
class ConfigStr(Config):
|
||||||
@ -182,7 +182,7 @@ class ConfigStr(Config):
|
|||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
self.raw = self.source.encode('utf-8')
|
self.raw = self.source.encode('utf-8')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class ConfigBin(Config):
|
class ConfigBin(Config):
|
||||||
@ -193,7 +193,7 @@ class ConfigBin(Config):
|
|||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
self.raw = self.source
|
self.raw = self.source
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
detector = {'raw': (re.compile(r'^\s*(?P<xml><(\?xml|aif)\s+.*)\s*$', re.DOTALL | re.MULTILINE), ConfigStr),
|
detector = {'raw': (re.compile(r'^\s*(?P<xml><(\?xml|aif)\s+.*)\s*$', re.DOTALL | re.MULTILINE), ConfigStr),
|
||||||
|
@ -86,7 +86,7 @@ class Partition(object):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
self.flags.append(_BlockDev.PartFlag(flag_id))
|
self.flags.append(_BlockDev.PartFlag(flag_id))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initFstype(self):
|
def _initFstype(self):
|
||||||
_err = ('{0} is not a valid partition filesystem type; '
|
_err = ('{0} is not a valid partition filesystem type; '
|
||||||
@ -102,7 +102,7 @@ class Partition(object):
|
|||||||
raise ValueError(_err)
|
raise ValueError(_err)
|
||||||
if self.fs_type not in aif.constants.GPT_GUID_IDX.keys():
|
if self.fs_type not in aif.constants.GPT_GUID_IDX.keys():
|
||||||
raise ValueError(_err)
|
raise ValueError(_err)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def format(self):
|
def format(self):
|
||||||
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
||||||
@ -119,7 +119,7 @@ class Partition(object):
|
|||||||
if self.flags:
|
if self.flags:
|
||||||
for f in self.flags:
|
for f in self.flags:
|
||||||
_BlockDev.part.set_part_flag(self.device, self.devpath, f, True)
|
_BlockDev.part.set_part_flag(self.device, self.devpath, f, True)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
#
|
#
|
||||||
# def detect(self):
|
# def detect(self):
|
||||||
@ -155,7 +155,7 @@ class Disk(object):
|
|||||||
self.is_hiformatted = False
|
self.is_hiformatted = False
|
||||||
self.is_partitioned = False
|
self.is_partitioned = False
|
||||||
self.partitions = []
|
self.partitions = []
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def diskFormat(self):
|
def diskFormat(self):
|
||||||
if self.is_lowformatted:
|
if self.is_lowformatted:
|
||||||
@ -170,7 +170,7 @@ class Disk(object):
|
|||||||
_BlockDev.part.create_table(self.devpath, self.table_type, True)
|
_BlockDev.part.create_table(self.devpath, self.table_type, True)
|
||||||
self.is_lowformatted = True
|
self.is_lowformatted = True
|
||||||
self.is_partitioned = False
|
self.is_partitioned = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getPartitions(self):
|
def getPartitions(self):
|
||||||
# For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment
|
# For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment
|
||||||
@ -196,11 +196,11 @@ class Disk(object):
|
|||||||
p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype)
|
p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype)
|
||||||
start_sector = p.end + 1
|
start_sector = p.end + 1
|
||||||
self.partitions.append(p)
|
self.partitions.append(p)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def partFormat(self):
|
def partFormat(self):
|
||||||
if self.is_partitioned:
|
if self.is_partitioned:
|
||||||
return()
|
return(None)
|
||||||
if not self.is_lowformatted:
|
if not self.is_lowformatted:
|
||||||
self.diskFormat()
|
self.diskFormat()
|
||||||
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
||||||
@ -208,7 +208,7 @@ class Disk(object):
|
|||||||
if not self.partitions:
|
if not self.partitions:
|
||||||
self.getPartitions()
|
self.getPartitions()
|
||||||
if not self.partitions:
|
if not self.partitions:
|
||||||
return()
|
return(None)
|
||||||
for p in self.partitions:
|
for p in self.partitions:
|
||||||
p.format()
|
p.format()
|
||||||
p.is_hiformatted = True
|
p.is_hiformatted = True
|
||||||
|
@ -144,18 +144,18 @@ class Disk(object):
|
|||||||
self.is_hiformatted = False
|
self.is_hiformatted = False
|
||||||
self.is_partitioned = False
|
self.is_partitioned = False
|
||||||
self.partitions = []
|
self.partitions = []
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def diskFormat(self):
|
def diskFormat(self):
|
||||||
if self.is_lowformatted:
|
if self.is_lowformatted:
|
||||||
return()
|
return(None)
|
||||||
# This is a safeguard. We do *not* want to low-format a disk that is mounted.
|
# This is a safeguard. We do *not* want to low-format a disk that is mounted.
|
||||||
aif.utils.checkMounted(self.devpath)
|
aif.utils.checkMounted(self.devpath)
|
||||||
self.disk.deleteAllPartitions()
|
self.disk.deleteAllPartitions()
|
||||||
self.disk.commit()
|
self.disk.commit()
|
||||||
self.is_lowformatted = True
|
self.is_lowformatted = True
|
||||||
self.is_partitioned = False
|
self.is_partitioned = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getPartitions(self):
|
def getPartitions(self):
|
||||||
# For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment
|
# For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment
|
||||||
@ -181,11 +181,11 @@ class Disk(object):
|
|||||||
p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype)
|
p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype)
|
||||||
start_sector = p.end + 1
|
start_sector = p.end + 1
|
||||||
self.partitions.append(p)
|
self.partitions.append(p)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def partFormat(self):
|
def partFormat(self):
|
||||||
if self.is_partitioned:
|
if self.is_partitioned:
|
||||||
return()
|
return(None)
|
||||||
if not self.is_lowformatted:
|
if not self.is_lowformatted:
|
||||||
self.diskFormat()
|
self.diskFormat()
|
||||||
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
# This is a safeguard. We do *not* want to partition a disk that is mounted.
|
||||||
@ -193,11 +193,11 @@ class Disk(object):
|
|||||||
if not self.partitions:
|
if not self.partitions:
|
||||||
self.getPartitions()
|
self.getPartitions()
|
||||||
if not self.partitions:
|
if not self.partitions:
|
||||||
return()
|
return(None)
|
||||||
for p in self.partitions:
|
for p in self.partitions:
|
||||||
self.disk.addPartition(partition = p, constraint = self.device.optimalAlignedConstraint)
|
self.disk.addPartition(partition = p, constraint = self.device.optimalAlignedConstraint)
|
||||||
self.disk.commit()
|
self.disk.commit()
|
||||||
p.devpath = p.partition.path
|
p.devpath = p.partition.path
|
||||||
p.is_hiformatted = True
|
p.is_hiformatted = True
|
||||||
self.is_partitioned = True
|
self.is_partitioned = True
|
||||||
return()
|
return(None)
|
||||||
|
@ -56,7 +56,7 @@ class FS(object):
|
|||||||
cmd.append(self.devpath)
|
cmd.append(self.devpath)
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.formatted = True
|
self.formatted = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Mount(object):
|
class Mount(object):
|
||||||
@ -86,7 +86,7 @@ class Mount(object):
|
|||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
if self.mounted:
|
if self.mounted:
|
||||||
return()
|
return(None)
|
||||||
os.makedirs(self.target, exist_ok = True)
|
os.makedirs(self.target, exist_ok = True)
|
||||||
opts = self._parseOpts()
|
opts = self._parseOpts()
|
||||||
_BlockDev.fs.mount(self.source,
|
_BlockDev.fs.mount(self.source,
|
||||||
@ -94,21 +94,21 @@ class Mount(object):
|
|||||||
self.fs.fstype,
|
self.fs.fstype,
|
||||||
(','.join(opts) if opts else None))
|
(','.join(opts) if opts else None))
|
||||||
self.mounted = True
|
self.mounted = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def unmount(self, lazy = False, force = False):
|
def unmount(self, lazy = False, force = False):
|
||||||
self.updateMount()
|
self.updateMount()
|
||||||
if not self.mounted and not force:
|
if not self.mounted and not force:
|
||||||
return()
|
return(None)
|
||||||
_BlockDev.fs.unmount(self.target,
|
_BlockDev.fs.unmount(self.target,
|
||||||
lazy,
|
lazy,
|
||||||
force)
|
force)
|
||||||
self.mounted = False
|
self.mounted = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateMount(self):
|
def updateMount(self):
|
||||||
if self.source in [p.device for p in psutil.disk_partitions(all = True)]:
|
if self.source in [p.device for p in psutil.disk_partitions(all = True)]:
|
||||||
self.mounted = True
|
self.mounted = True
|
||||||
else:
|
else:
|
||||||
self.mounted = False
|
self.mounted = False
|
||||||
return()
|
return(None)
|
||||||
|
@ -47,7 +47,7 @@ class FS(object):
|
|||||||
cmd.append(self.devpath)
|
cmd.append(self.devpath)
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.formatted = True
|
self.formatted = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Mount(object):
|
class Mount(object):
|
||||||
@ -76,7 +76,7 @@ class Mount(object):
|
|||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
if self.mounted:
|
if self.mounted:
|
||||||
return()
|
return(None)
|
||||||
os.makedirs(self.target, exist_ok = True)
|
os.makedirs(self.target, exist_ok = True)
|
||||||
opts = self._parseOpts()
|
opts = self._parseOpts()
|
||||||
# TODO: logging
|
# TODO: logging
|
||||||
@ -87,12 +87,12 @@ class Mount(object):
|
|||||||
cmd.extend([self.source, self.target])
|
cmd.extend([self.source, self.target])
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.mounted = True
|
self.mounted = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def unmount(self, lazy = False, force = False):
|
def unmount(self, lazy = False, force = False):
|
||||||
self.updateMount()
|
self.updateMount()
|
||||||
if not self.mounted and not force:
|
if not self.mounted and not force:
|
||||||
return()
|
return(None)
|
||||||
# TODO: logging
|
# TODO: logging
|
||||||
cmd = ['/usr/bin/umount']
|
cmd = ['/usr/bin/umount']
|
||||||
if lazy:
|
if lazy:
|
||||||
@ -102,11 +102,11 @@ class Mount(object):
|
|||||||
cmd.append(self.target)
|
cmd.append(self.target)
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.mounted = False
|
self.mounted = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateMount(self):
|
def updateMount(self):
|
||||||
if self.source in [p.device for p in psutil.disk_partitions(all = True)]:
|
if self.source in [p.device for p in psutil.disk_partitions(all = True)]:
|
||||||
self.mounted = True
|
self.mounted = True
|
||||||
else:
|
else:
|
||||||
self.mounted = False
|
self.mounted = False
|
||||||
return()
|
return(None)
|
||||||
|
@ -40,7 +40,7 @@ class LuksSecretFile(LuksSecret):
|
|||||||
self.passphrase = secrets.token_bytes(self.size)
|
self.passphrase = secrets.token_bytes(self.size)
|
||||||
if not isinstance(self.passphrase, bytes):
|
if not isinstance(self.passphrase, bytes):
|
||||||
self.passphrase = self.passphrase.encode('utf-8')
|
self.passphrase = self.passphrase.encode('utf-8')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class LUKS(object):
|
class LUKS(object):
|
||||||
@ -72,7 +72,7 @@ class LUKS(object):
|
|||||||
'(aif.disk.luks.LuksSecretPassphrase or '
|
'(aif.disk.luks.LuksSecretPassphrase or '
|
||||||
'aif.disk.luks.LuksSecretFile)')
|
'aif.disk.luks.LuksSecretFile)')
|
||||||
self.secrets.append(secretobj)
|
self.secrets.append(secretobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def createSecret(self, secrets_xml = None):
|
def createSecret(self, secrets_xml = None):
|
||||||
if not secrets_xml: # Find all of them from self
|
if not secrets_xml: # Find all of them from self
|
||||||
@ -116,11 +116,11 @@ class LUKS(object):
|
|||||||
passphrase = None,
|
passphrase = None,
|
||||||
bytesize = kf.attrib.get('size', 4096))
|
bytesize = kf.attrib.get('size', 4096))
|
||||||
self.secrets.append(secretobj)
|
self.secrets.append(secretobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if self.created:
|
if self.created:
|
||||||
return()
|
return(None)
|
||||||
if not self.secrets:
|
if not self.secrets:
|
||||||
raise RuntimeError('Cannot create a LUKS volume with no secrets added')
|
raise RuntimeError('Cannot create a LUKS volume with no secrets added')
|
||||||
for idx, secret in enumerate(self.secrets):
|
for idx, secret in enumerate(self.secrets):
|
||||||
@ -138,28 +138,28 @@ class LUKS(object):
|
|||||||
self.secrets[0].passphrase,
|
self.secrets[0].passphrase,
|
||||||
secret.passphrase)
|
secret.passphrase)
|
||||||
self.created = True
|
self.created = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
raise RuntimeError('Cannot lock a LUKS volume before it is created')
|
raise RuntimeError('Cannot lock a LUKS volume before it is created')
|
||||||
if self.locked:
|
if self.locked:
|
||||||
return()
|
return(None)
|
||||||
_BlockDev.crypto.luks_close(self.name)
|
_BlockDev.crypto.luks_close(self.name)
|
||||||
self.locked = True
|
self.locked = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def unlock(self, passphrase = None):
|
def unlock(self, passphrase = None):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
raise RuntimeError('Cannot unlock a LUKS volume before it is created')
|
raise RuntimeError('Cannot unlock a LUKS volume before it is created')
|
||||||
if not self.locked:
|
if not self.locked:
|
||||||
return()
|
return(None)
|
||||||
_BlockDev.crypto.luks_open_blob(self.source,
|
_BlockDev.crypto.luks_open_blob(self.source,
|
||||||
self.name,
|
self.name,
|
||||||
self.secrets[0].passphrase,
|
self.secrets[0].passphrase,
|
||||||
False) # read-only
|
False) # read-only
|
||||||
self.locked = False
|
self.locked = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
if self.locked:
|
if self.locked:
|
||||||
@ -177,7 +177,7 @@ class LUKS(object):
|
|||||||
info[k] = v
|
info[k] = v
|
||||||
info['_cipher'] = '{cipher}-{mode}'.format(**info)
|
info['_cipher'] = '{cipher}-{mode}'.format(**info)
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, conf = '/etc/crypttab'):
|
def writeConf(self, conf = '/etc/crypttab'):
|
||||||
if not self.secrets:
|
if not self.secrets:
|
||||||
@ -204,4 +204,4 @@ class LUKS(object):
|
|||||||
if luksinfo not in conflines:
|
if luksinfo not in conflines:
|
||||||
with open(conf, 'a') as fh:
|
with open(conf, 'a') as fh:
|
||||||
fh.write('{0}\n'.format(luksinfo))
|
fh.write('{0}\n'.format(luksinfo))
|
||||||
return()
|
return(None)
|
||||||
|
@ -40,7 +40,7 @@ class LuksSecretFile(LuksSecret):
|
|||||||
self.passphrase = secrets.token_bytes(self.size)
|
self.passphrase = secrets.token_bytes(self.size)
|
||||||
if not isinstance(self.passphrase, bytes):
|
if not isinstance(self.passphrase, bytes):
|
||||||
self.passphrase = self.passphrase.encode('utf-8')
|
self.passphrase = self.passphrase.encode('utf-8')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class LUKS(object):
|
class LUKS(object):
|
||||||
@ -71,7 +71,7 @@ class LUKS(object):
|
|||||||
'(aif.disk.luks.LuksSecretPassphrase or '
|
'(aif.disk.luks.LuksSecretPassphrase or '
|
||||||
'aif.disk.luks.LuksSecretFile)')
|
'aif.disk.luks.LuksSecretFile)')
|
||||||
self.secrets.append(secretobj)
|
self.secrets.append(secretobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def createSecret(self, secrets_xml = None):
|
def createSecret(self, secrets_xml = None):
|
||||||
if not secrets_xml: # Find all of them from self
|
if not secrets_xml: # Find all of them from self
|
||||||
@ -115,11 +115,11 @@ class LUKS(object):
|
|||||||
passphrase = None,
|
passphrase = None,
|
||||||
bytesize = kf.attrib.get('size', 4096))
|
bytesize = kf.attrib.get('size', 4096))
|
||||||
self.secrets.append(secretobj)
|
self.secrets.append(secretobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if self.created:
|
if self.created:
|
||||||
return()
|
return(None)
|
||||||
if not self.secrets:
|
if not self.secrets:
|
||||||
raise RuntimeError('Cannot create a LUKS volume with no secrets added')
|
raise RuntimeError('Cannot create a LUKS volume with no secrets added')
|
||||||
for idx, secret in enumerate(self.secrets):
|
for idx, secret in enumerate(self.secrets):
|
||||||
@ -147,13 +147,13 @@ class LUKS(object):
|
|||||||
subprocess.run(cmd, input = self.secrets[0].passphrase)
|
subprocess.run(cmd, input = self.secrets[0].passphrase)
|
||||||
os.remove(tmpfile[1])
|
os.remove(tmpfile[1])
|
||||||
self.created = True
|
self.created = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
raise RuntimeError('Cannot lock a LUKS volume before it is created')
|
raise RuntimeError('Cannot lock a LUKS volume before it is created')
|
||||||
if self.locked:
|
if self.locked:
|
||||||
return()
|
return(None)
|
||||||
# TODO: logging
|
# TODO: logging
|
||||||
cmd = ['cryptsetup',
|
cmd = ['cryptsetup',
|
||||||
'--batch-mode',
|
'--batch-mode',
|
||||||
@ -161,13 +161,13 @@ class LUKS(object):
|
|||||||
self.name]
|
self.name]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.locked = True
|
self.locked = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def unlock(self, passphrase = None):
|
def unlock(self, passphrase = None):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
raise RuntimeError('Cannot unlock a LUKS volume before it is created')
|
raise RuntimeError('Cannot unlock a LUKS volume before it is created')
|
||||||
if not self.locked:
|
if not self.locked:
|
||||||
return()
|
return(None)
|
||||||
cmd = ['cryptsetup',
|
cmd = ['cryptsetup',
|
||||||
'--batch-mode',
|
'--batch-mode',
|
||||||
'luksOpen',
|
'luksOpen',
|
||||||
@ -176,7 +176,7 @@ class LUKS(object):
|
|||||||
self.name]
|
self.name]
|
||||||
subprocess.run(cmd, input = self.secrets[0].passphrase)
|
subprocess.run(cmd, input = self.secrets[0].passphrase)
|
||||||
self.locked = False
|
self.locked = False
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
if self.locked:
|
if self.locked:
|
||||||
@ -225,7 +225,7 @@ class LUKS(object):
|
|||||||
elif k == 'uuid':
|
elif k == 'uuid':
|
||||||
v = uuid.UUID(hex = v)
|
v = uuid.UUID(hex = v)
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, conf = '/etc/crypttab'):
|
def writeConf(self, conf = '/etc/crypttab'):
|
||||||
if not self.secrets:
|
if not self.secrets:
|
||||||
@ -252,4 +252,4 @@ class LUKS(object):
|
|||||||
if luksinfo not in conflines:
|
if luksinfo not in conflines:
|
||||||
with open(conf, 'a') as fh:
|
with open(conf, 'a') as fh:
|
||||||
fh.write('{0}\n'.format(luksinfo))
|
fh.write('{0}\n'.format(luksinfo))
|
||||||
return()
|
return(None)
|
||||||
|
@ -42,7 +42,7 @@ class PV(object):
|
|||||||
except _BlockDev.LVMError:
|
except _BlockDev.LVMError:
|
||||||
self.meta = None
|
self.meta = None
|
||||||
self.is_pooled = False
|
self.is_pooled = False
|
||||||
return()
|
return(None)
|
||||||
for k in dir(_meta):
|
for k in dir(_meta):
|
||||||
if k.startswith('_'):
|
if k.startswith('_'):
|
||||||
continue
|
continue
|
||||||
@ -52,7 +52,7 @@ class PV(object):
|
|||||||
meta[k] = v
|
meta[k] = v
|
||||||
self.meta = meta
|
self.meta = meta
|
||||||
self.is_pooled = True
|
self.is_pooled = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
try:
|
try:
|
||||||
@ -97,7 +97,7 @@ class PV(object):
|
|||||||
0,
|
0,
|
||||||
opts)
|
opts)
|
||||||
self._parseMeta()
|
self._parseMeta()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class VG(object):
|
class VG(object):
|
||||||
@ -130,7 +130,7 @@ class VG(object):
|
|||||||
raise ValueError('pvobj must be of type aif.disk.lvm.PV')
|
raise ValueError('pvobj must be of type aif.disk.lvm.PV')
|
||||||
pvobj.prepare()
|
pvobj.prepare()
|
||||||
self.pvs.append(pvobj)
|
self.pvs.append(pvobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.pvs:
|
if not self.pvs:
|
||||||
@ -149,7 +149,7 @@ class VG(object):
|
|||||||
pv._parseMeta()
|
pv._parseMeta()
|
||||||
self.created = True
|
self.created = True
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def createLV(self, lv_xml = None):
|
def createLV(self, lv_xml = None):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
@ -165,21 +165,21 @@ class VG(object):
|
|||||||
lv.create()
|
lv.create()
|
||||||
# self.lvs.append(lv)
|
# self.lvs.append(lv)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
_BlockDev.lvm.vgactivate(self.name)
|
_BlockDev.lvm.vgactivate(self.name)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
_BlockDev.lvm.vgdeactivate(self.name)
|
_BlockDev.lvm.vgdeactivate(self.name)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
return()
|
return(None)
|
||||||
_info = _BlockDev.lvm.vginfo(self.name)
|
_info = _BlockDev.lvm.vginfo(self.name)
|
||||||
# TODO: parity with lvm_fallback.VG.updateInfo
|
# TODO: parity with lvm_fallback.VG.updateInfo
|
||||||
# key names currently (probably) don't match and need to confirm the information's all present
|
# key names currently (probably) don't match and need to confirm the information's all present
|
||||||
@ -192,7 +192,7 @@ class VG(object):
|
|||||||
v = getattr(_info, k)
|
v = getattr(_info, k)
|
||||||
info[k] = v
|
info[k] = v
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class LV(object):
|
class LV(object):
|
||||||
@ -247,7 +247,7 @@ class LV(object):
|
|||||||
target = 'B'))
|
target = 'B'))
|
||||||
if self.size >= _sizes['total']:
|
if self.size >= _sizes['total']:
|
||||||
self.size = 0
|
self.size = 0
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.pvs:
|
if not self.pvs:
|
||||||
@ -268,7 +268,7 @@ class LV(object):
|
|||||||
self.created = True
|
self.created = True
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
self.vg.updateInfo()
|
self.vg.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
_BlockDev.lvm.lvactivate(self.vg.name,
|
_BlockDev.lvm.lvactivate(self.vg.name,
|
||||||
@ -276,18 +276,18 @@ class LV(object):
|
|||||||
True,
|
True,
|
||||||
None)
|
None)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
_BlockDev.lvm.lvdeactivate(self.vg.name,
|
_BlockDev.lvm.lvdeactivate(self.vg.name,
|
||||||
self.name,
|
self.name,
|
||||||
None)
|
None)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
return()
|
return(None)
|
||||||
_info = _BlockDev.lvm.lvinfo(self.vg.name, self.name)
|
_info = _BlockDev.lvm.lvinfo(self.vg.name, self.name)
|
||||||
# TODO: parity with lvm_fallback.LV.updateInfo
|
# TODO: parity with lvm_fallback.LV.updateInfo
|
||||||
# key names currently (probably) don't match and need to confirm the information's all present
|
# key names currently (probably) don't match and need to confirm the information's all present
|
||||||
@ -300,4 +300,4 @@ class LV(object):
|
|||||||
v = getattr(_info, k)
|
v = getattr(_info, k)
|
||||||
info[k] = v
|
info[k] = v
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
@ -43,7 +43,7 @@ class PV(object):
|
|||||||
if _meta.returncode != 0:
|
if _meta.returncode != 0:
|
||||||
self.meta = None
|
self.meta = None
|
||||||
self.is_pooled = False
|
self.is_pooled = False
|
||||||
return()
|
return(None)
|
||||||
_meta = json.loads(_meta.stdout.decode('utf-8'))['report'][0]['pv'][0]
|
_meta = json.loads(_meta.stdout.decode('utf-8'))['report'][0]['pv'][0]
|
||||||
for k, v in _meta.items():
|
for k, v in _meta.items():
|
||||||
# We *could* regex this but the pattern would be a little more complex than idea,
|
# We *could* regex this but the pattern would be a little more complex than idea,
|
||||||
@ -64,7 +64,7 @@ class PV(object):
|
|||||||
meta[k] = v
|
meta[k] = v
|
||||||
self.meta = meta
|
self.meta = meta
|
||||||
self.is_pooled = True
|
self.is_pooled = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
if not self.meta:
|
if not self.meta:
|
||||||
@ -80,7 +80,7 @@ class PV(object):
|
|||||||
self.devpath]
|
self.devpath]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self._parseMeta()
|
self._parseMeta()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class VG(object):
|
class VG(object):
|
||||||
@ -113,7 +113,7 @@ class VG(object):
|
|||||||
raise ValueError('pvobj must be of type aif.disk.lvm.PV')
|
raise ValueError('pvobj must be of type aif.disk.lvm.PV')
|
||||||
pvobj.prepare()
|
pvobj.prepare()
|
||||||
self.pvs.append(pvobj)
|
self.pvs.append(pvobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.pvs:
|
if not self.pvs:
|
||||||
@ -129,7 +129,7 @@ class VG(object):
|
|||||||
pv._parseMeta()
|
pv._parseMeta()
|
||||||
self.created = True
|
self.created = True
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def createLV(self, lv_xml = None):
|
def createLV(self, lv_xml = None):
|
||||||
if not self.created:
|
if not self.created:
|
||||||
@ -145,7 +145,7 @@ class VG(object):
|
|||||||
lv.create()
|
lv.create()
|
||||||
# self.lvs.append(lv)
|
# self.lvs.append(lv)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
cmd = ['vgchange',
|
cmd = ['vgchange',
|
||||||
@ -154,7 +154,7 @@ class VG(object):
|
|||||||
self.name]
|
self.name]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
cmd = ['vgchange',
|
cmd = ['vgchange',
|
||||||
@ -163,7 +163,7 @@ class VG(object):
|
|||||||
self.name]
|
self.name]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
info = {}
|
info = {}
|
||||||
@ -178,7 +178,7 @@ class VG(object):
|
|||||||
if _info.returncode != 0:
|
if _info.returncode != 0:
|
||||||
self.info = None
|
self.info = None
|
||||||
self.created = False
|
self.created = False
|
||||||
return()
|
return(None)
|
||||||
_info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0]
|
_info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0]
|
||||||
for k, v in _info.items():
|
for k, v in _info.items():
|
||||||
# ints
|
# ints
|
||||||
@ -196,7 +196,7 @@ class VG(object):
|
|||||||
v = None
|
v = None
|
||||||
info[k] = v
|
info[k] = v
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class LV(object):
|
class LV(object):
|
||||||
@ -250,7 +250,7 @@ class LV(object):
|
|||||||
target = 'B'))
|
target = 'B'))
|
||||||
if self.size >= _sizes['total']:
|
if self.size >= _sizes['total']:
|
||||||
self.size = 0
|
self.size = 0
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.pvs:
|
if not self.pvs:
|
||||||
@ -267,7 +267,7 @@ class LV(object):
|
|||||||
self.created = True
|
self.created = True
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
self.vg.updateInfo()
|
self.vg.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
cmd = ['lvchange',
|
cmd = ['lvchange',
|
||||||
@ -276,7 +276,7 @@ class LV(object):
|
|||||||
self.qualified_name]
|
self.qualified_name]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
cmd = ['lvchange',
|
cmd = ['lvchange',
|
||||||
@ -285,7 +285,7 @@ class LV(object):
|
|||||||
self.qualified_name]
|
self.qualified_name]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.updateInfo()
|
self.updateInfo()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateInfo(self):
|
def updateInfo(self):
|
||||||
info = {}
|
info = {}
|
||||||
@ -300,7 +300,7 @@ class LV(object):
|
|||||||
if _info.returncode != 0:
|
if _info.returncode != 0:
|
||||||
self.info = None
|
self.info = None
|
||||||
self.created = False
|
self.created = False
|
||||||
return()
|
return(None)
|
||||||
_info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0]
|
_info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0]
|
||||||
for k, v in _info.items():
|
for k, v in _info.items():
|
||||||
# ints
|
# ints
|
||||||
@ -330,4 +330,4 @@ class LV(object):
|
|||||||
v = None
|
v = None
|
||||||
info[k] = v
|
info[k] = v
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
@ -44,7 +44,7 @@ class Member(object):
|
|||||||
except _BlockDev.MDRaidError:
|
except _BlockDev.MDRaidError:
|
||||||
self.is_superblocked = False
|
self.is_superblocked = False
|
||||||
self.superblock = None
|
self.superblock = None
|
||||||
return()
|
return(None)
|
||||||
for k in dir(_block):
|
for k in dir(_block):
|
||||||
if k.startswith('_'):
|
if k.startswith('_'):
|
||||||
continue
|
continue
|
||||||
@ -60,7 +60,7 @@ class Member(object):
|
|||||||
block[k] = v
|
block[k] = v
|
||||||
self.superblock = block
|
self.superblock = block
|
||||||
self.is_superblocked = True
|
self.is_superblocked = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
try:
|
try:
|
||||||
@ -69,7 +69,7 @@ class Member(object):
|
|||||||
pass
|
pass
|
||||||
_BlockDev.md.destroy(self.devpath)
|
_BlockDev.md.destroy(self.devpath)
|
||||||
self._parseDeviceBlock()
|
self._parseDeviceBlock()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Array(object):
|
class Array(object):
|
||||||
@ -121,7 +121,7 @@ class Array(object):
|
|||||||
raise ValueError('memberobj must be of type aif.disk.mdadm.Member')
|
raise ValueError('memberobj must be of type aif.disk.mdadm.Member')
|
||||||
memberobj.prepare()
|
memberobj.prepare()
|
||||||
self.members.append(memberobj)
|
self.members.append(memberobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.members:
|
if not self.members:
|
||||||
@ -147,7 +147,7 @@ class Array(object):
|
|||||||
self.writeConf()
|
self.writeConf()
|
||||||
self.devpath = self.info['device']
|
self.devpath = self.info['device']
|
||||||
self.state = 'new'
|
self.state = 'new'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self, scan = False):
|
def start(self, scan = False):
|
||||||
if not any((self.members, self.devpath)):
|
if not any((self.members, self.devpath)):
|
||||||
@ -162,12 +162,12 @@ class Array(object):
|
|||||||
True,
|
True,
|
||||||
None)
|
None)
|
||||||
self.state = 'assembled'
|
self.state = 'assembled'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
_BlockDev.md.deactivate(self.name)
|
_BlockDev.md.deactivate(self.name)
|
||||||
self.state = 'disassembled'
|
self.state = 'disassembled'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateStatus(self):
|
def updateStatus(self):
|
||||||
_status = _BlockDev.md.detail(self.name)
|
_status = _BlockDev.md.detail(self.name)
|
||||||
@ -189,7 +189,7 @@ class Array(object):
|
|||||||
v = uuid.UUID(hex = v)
|
v = uuid.UUID(hex = v)
|
||||||
info[k] = v
|
info[k] = v
|
||||||
self.info = info
|
self.info = info
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, conf = '/etc/mdadm.conf'):
|
def writeConf(self, conf = '/etc/mdadm.conf'):
|
||||||
conf = os.path.realpath(conf)
|
conf = os.path.realpath(conf)
|
||||||
@ -214,4 +214,4 @@ class Array(object):
|
|||||||
if nodev:
|
if nodev:
|
||||||
with open(conf, 'a') as fh:
|
with open(conf, 'a') as fh:
|
||||||
fh.write('{0}\n'.format(arrayinfo))
|
fh.write('{0}\n'.format(arrayinfo))
|
||||||
return()
|
return(None)
|
||||||
|
@ -49,7 +49,7 @@ class Member(object):
|
|||||||
# TODO: logging?
|
# TODO: logging?
|
||||||
self.is_superblocked = False
|
self.is_superblocked = False
|
||||||
self.superblock = None
|
self.superblock = None
|
||||||
return()
|
return(None)
|
||||||
block = {}
|
block = {}
|
||||||
for idx, line in enumerate(super.stdout.decode('utf-8').splitlines()):
|
for idx, line in enumerate(super.stdout.decode('utf-8').splitlines()):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -116,7 +116,7 @@ class Member(object):
|
|||||||
block[k] = v
|
block[k] = v
|
||||||
self.superblock = block
|
self.superblock = block
|
||||||
self.is_superblocked = True
|
self.is_superblocked = True
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
if self.is_superblocked:
|
if self.is_superblocked:
|
||||||
@ -124,7 +124,7 @@ class Member(object):
|
|||||||
subprocess.run(['mdadm', '--misc', '--zero-superblock', self.devpath])
|
subprocess.run(['mdadm', '--misc', '--zero-superblock', self.devpath])
|
||||||
self.is_superblocked = False
|
self.is_superblocked = False
|
||||||
self._parseDeviceBlock()
|
self._parseDeviceBlock()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Array(object):
|
class Array(object):
|
||||||
@ -174,7 +174,7 @@ class Array(object):
|
|||||||
raise ValueError('memberobj must be of type aif.disk.mdadm.Member')
|
raise ValueError('memberobj must be of type aif.disk.mdadm.Member')
|
||||||
memberobj.prepare()
|
memberobj.prepare()
|
||||||
self.members.append(memberobj)
|
self.members.append(memberobj)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if not self.members:
|
if not self.members:
|
||||||
@ -199,7 +199,7 @@ class Array(object):
|
|||||||
self.updateStatus()
|
self.updateStatus()
|
||||||
self.writeConf()
|
self.writeConf()
|
||||||
self.state = 'new'
|
self.state = 'new'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def start(self, scan = False):
|
def start(self, scan = False):
|
||||||
if not any((self.members, self.devpath)):
|
if not any((self.members, self.devpath)):
|
||||||
@ -214,13 +214,13 @@ class Array(object):
|
|||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
self.updateStatus()
|
self.updateStatus()
|
||||||
self.state = 'assembled'
|
self.state = 'assembled'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# TODO: logging
|
# TODO: logging
|
||||||
subprocess.run(['mdadm', '--stop', self.devpath])
|
subprocess.run(['mdadm', '--stop', self.devpath])
|
||||||
self.state = 'disassembled'
|
self.state = 'disassembled'
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def updateStatus(self):
|
def updateStatus(self):
|
||||||
_info = mdstat.parse()
|
_info = mdstat.parse()
|
||||||
@ -228,7 +228,7 @@ class Array(object):
|
|||||||
if k != self.name:
|
if k != self.name:
|
||||||
del(_info['devices'][k])
|
del(_info['devices'][k])
|
||||||
self.info = copy.deepcopy(_info)
|
self.info = copy.deepcopy(_info)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, conf = '/etc/mdadm.conf'):
|
def writeConf(self, conf = '/etc/mdadm.conf'):
|
||||||
conf = os.path.realpath(conf)
|
conf = os.path.realpath(conf)
|
||||||
@ -250,4 +250,4 @@ class Array(object):
|
|||||||
if nodev:
|
if nodev:
|
||||||
with open(conf, 'a') as fh:
|
with open(conf, 'a') as fh:
|
||||||
fh.write('{0}\n'.format(arrayinfo))
|
fh.write('{0}\n'.format(arrayinfo))
|
||||||
return()
|
return(None)
|
||||||
|
@ -204,19 +204,19 @@ class BaseConnection(object):
|
|||||||
addrset = convertIpTuples(a)
|
addrset = convertIpTuples(a)
|
||||||
if addrset not in self.addrs[addrtype]:
|
if addrset not in self.addrs[addrtype]:
|
||||||
self.addrs[addrtype].append(addrset)
|
self.addrs[addrtype].append(addrset)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initCfg(self):
|
def _initCfg(self):
|
||||||
# A dummy method; this is overridden by the subclasses.
|
# A dummy method; this is overridden by the subclasses.
|
||||||
# It's honestly here to make my IDE stop complaining. :)
|
# It's honestly here to make my IDE stop complaining. :)
|
||||||
pass
|
pass
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initConnCfg(self):
|
def _initConnCfg(self):
|
||||||
# A dummy method; this is overridden by the subclasses.
|
# A dummy method; this is overridden by the subclasses.
|
||||||
# It's honestly here to make my IDE stop complaining. :)
|
# It's honestly here to make my IDE stop complaining. :)
|
||||||
pass
|
pass
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initResolvers(self):
|
def _initResolvers(self):
|
||||||
resolvers_xml = self.xml.find('resolvers')
|
resolvers_xml = self.xml.find('resolvers')
|
||||||
@ -225,7 +225,7 @@ class BaseConnection(object):
|
|||||||
resolver = ipaddress.ip_address(r.text.strip())
|
resolver = ipaddress.ip_address(r.text.strip())
|
||||||
if resolver not in self.resolvers:
|
if resolver not in self.resolvers:
|
||||||
self.resolvers.append(resolver)
|
self.resolvers.append(resolver)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initRoutes(self):
|
def _initRoutes(self):
|
||||||
routes_xml = self.xml.find('routes')
|
routes_xml = self.xml.find('routes')
|
||||||
@ -235,9 +235,9 @@ class BaseConnection(object):
|
|||||||
addrset = convertIpTuples(a)
|
addrset = convertIpTuples(a)
|
||||||
if addrset not in self.routes[addrtype]:
|
if addrset not in self.routes[addrtype]:
|
||||||
self.routes[addrtype].append(addrset)
|
self.routes[addrtype].append(addrset)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _writeConnCfg(self, chroot_base):
|
def _writeConnCfg(self, chroot_base):
|
||||||
# Dummy method.
|
# Dummy method.
|
||||||
pass
|
pass
|
||||||
return()
|
return(None)
|
||||||
|
@ -105,7 +105,7 @@ class Connection(_common.BaseConnection):
|
|||||||
# Weird hack because netctl doesn't natively support assigning add'l addrs to a dhcp/dhcp6/slaac iface.
|
# Weird hack because netctl doesn't natively support assigning add'l addrs to a dhcp/dhcp6/slaac iface.
|
||||||
if 'IPCustom' in self._cfg['BASE'].keys() and isinstance(self._cfg['BASE']['IPCustom'], list):
|
if 'IPCustom' in self._cfg['BASE'].keys() and isinstance(self._cfg['BASE']['IPCustom'], list):
|
||||||
self._cfg['BASE']['IPCustom'] = '({0})'.format(' '.join(self._cfg['BASE']['IPCustom']))
|
self._cfg['BASE']['IPCustom'] = '({0})'.format(' '.join(self._cfg['BASE']['IPCustom']))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, chroot_base):
|
def writeConf(self, chroot_base):
|
||||||
systemd_base = os.path.join(chroot_base, 'etc', 'systemd', 'system')
|
systemd_base = os.path.join(chroot_base, 'etc', 'systemd', 'system')
|
||||||
@ -260,7 +260,7 @@ class Connection(_common.BaseConnection):
|
|||||||
fh.write(line)
|
fh.write(line)
|
||||||
os.chmod(netctl_file, 0o0600)
|
os.chmod(netctl_file, 0o0600)
|
||||||
os.chown(netctl_file, 0, 0)
|
os.chown(netctl_file, 0, 0)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Ethernet(Connection):
|
class Ethernet(Connection):
|
||||||
@ -300,4 +300,4 @@ class Wireless(Connection):
|
|||||||
# if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'):
|
# if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'):
|
||||||
if crypto['type'] in ('wpa', 'wpa2'):
|
if crypto['type'] in ('wpa', 'wpa2'):
|
||||||
self._cfg['BASE']['Key'] = crypto['auth']['psk']
|
self._cfg['BASE']['Key'] = crypto['auth']['psk']
|
||||||
return()
|
return(None)
|
||||||
|
@ -90,13 +90,13 @@ class Connection(_common.BaseConnection):
|
|||||||
if 'IPv6AcceptRA' not in self._cfg.keys():
|
if 'IPv6AcceptRA' not in self._cfg.keys():
|
||||||
self._cfg['IPv6AcceptRA'] = {'UseDNS': ('true' if self.auto['resolvers']['ipv6'] else 'false')}
|
self._cfg['IPv6AcceptRA'] = {'UseDNS': ('true' if self.auto['resolvers']['ipv6'] else 'false')}
|
||||||
self._initConnCfg()
|
self._initConnCfg()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _initJ2(self):
|
def _initJ2(self):
|
||||||
self.j2_env = jinja2.Environment(loader = jinja2.FileSystemLoader(searchpath = './'))
|
self.j2_env = jinja2.Environment(loader = jinja2.FileSystemLoader(searchpath = './'))
|
||||||
self.j2_env.filters.update(aif.utils.j2_filters)
|
self.j2_env.filters.update(aif.utils.j2_filters)
|
||||||
self.j2_tpl = self.j2_env.get_template('networkd.conf.j2')
|
self.j2_tpl = self.j2_env.get_template('networkd.conf.j2')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, chroot_base):
|
def writeConf(self, chroot_base):
|
||||||
cfgroot = os.path.join(chroot_base, 'etc', 'systemd', 'network')
|
cfgroot = os.path.join(chroot_base, 'etc', 'systemd', 'network')
|
||||||
@ -109,7 +109,7 @@ class Connection(_common.BaseConnection):
|
|||||||
os.chmod(cfgfile, 0o0644)
|
os.chmod(cfgfile, 0o0644)
|
||||||
os.chown(cfgfile, 0, 0)
|
os.chown(cfgfile, 0, 0)
|
||||||
self._writeConnCfg(chroot_base)
|
self._writeConnCfg(chroot_base)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Ethernet(Connection):
|
class Ethernet(Connection):
|
||||||
@ -155,7 +155,7 @@ class Wireless(Connection):
|
|||||||
'multi-user.target.wants/'
|
'multi-user.target.wants/'
|
||||||
'wpa_supplicant@'
|
'wpa_supplicant@'
|
||||||
'{0}.service').format(self.device)
|
'{0}.service').format(self.device)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _writeConnCfg(self, chroot_base):
|
def _writeConnCfg(self, chroot_base):
|
||||||
cfgroot = os.path.join(chroot_base, 'etc', 'wpa_supplicant')
|
cfgroot = os.path.join(chroot_base, 'etc', 'wpa_supplicant')
|
||||||
@ -167,4 +167,4 @@ class Wireless(Connection):
|
|||||||
fh.write(self.wpasupp_tpl.render(wpa = self._wpasupp))
|
fh.write(self.wpasupp_tpl.render(wpa = self._wpasupp))
|
||||||
os.chown(cfgfile, 0, 0)
|
os.chown(cfgfile, 0, 0)
|
||||||
os.chmod(cfgfile, 0o0640)
|
os.chmod(cfgfile, 0o0640)
|
||||||
return()
|
return(None)
|
||||||
|
@ -89,7 +89,7 @@ class Connection(_common.BaseConnection):
|
|||||||
str(net.prefixlen),
|
str(net.prefixlen),
|
||||||
str(gw))
|
str(gw))
|
||||||
self._initConnCfg()
|
self._initConnCfg()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self, chroot_base):
|
def writeConf(self, chroot_base):
|
||||||
cfgroot = os.path.join(chroot_base, 'etc', 'NetworkManager')
|
cfgroot = os.path.join(chroot_base, 'etc', 'NetworkManager')
|
||||||
@ -109,7 +109,7 @@ class Connection(_common.BaseConnection):
|
|||||||
os.chmod(cfgroot, 0o0755)
|
os.chmod(cfgroot, 0o0755)
|
||||||
os.chmod(cfgdir, 0o0700)
|
os.chmod(cfgdir, 0o0700)
|
||||||
os.chmod(cfgpath, 0o0600)
|
os.chmod(cfgpath, 0o0600)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Ethernet(Connection):
|
class Ethernet(Connection):
|
||||||
@ -120,7 +120,7 @@ class Ethernet(Connection):
|
|||||||
|
|
||||||
def _initConnCfg(self):
|
def _initConnCfg(self):
|
||||||
self._cfg[self.connection_type] = {'mac-address-blacklist': ''}
|
self._cfg[self.connection_type] = {'mac-address-blacklist': ''}
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Wireless(Connection):
|
class Wireless(Connection):
|
||||||
@ -153,4 +153,4 @@ class Wireless(Connection):
|
|||||||
# if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'):
|
# if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'):
|
||||||
if crypto['type'] in ('wpa', 'wpa2'):
|
if crypto['type'] in ('wpa', 'wpa2'):
|
||||||
self._cfg['wifi-security']['psk'] = crypto['auth']['psk']
|
self._cfg['wifi-security']['psk'] = crypto['auth']['psk']
|
||||||
return()
|
return(None)
|
||||||
|
@ -18,4 +18,4 @@ class Sys(object):
|
|||||||
self.tz.apply()
|
self.tz.apply()
|
||||||
self.user.writeConf()
|
self.user.writeConf()
|
||||||
self.services.apply()
|
self.services.apply()
|
||||||
return()
|
return(None)
|
||||||
|
@ -96,4 +96,4 @@ class Console(object):
|
|||||||
fh.write(line)
|
fh.write(line)
|
||||||
os.chmod(cfg, 0o0644)
|
os.chmod(cfg, 0o0644)
|
||||||
os.chown(cfg, 0, 0)
|
os.chown(cfg, 0, 0)
|
||||||
return()
|
return(None)
|
||||||
|
@ -31,7 +31,7 @@ class Locale(object):
|
|||||||
self.userlocales.append(locale)
|
self.userlocales.append(locale)
|
||||||
if not self.userlocales:
|
if not self.userlocales:
|
||||||
self.userlocales = ['en_US', 'en_US.UTF-8']
|
self.userlocales = ['en_US', 'en_US.UTF-8']
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _verify(self):
|
def _verify(self):
|
||||||
localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') # This *should* be brand new.
|
localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') # This *should* be brand new.
|
||||||
@ -50,7 +50,7 @@ class Locale(object):
|
|||||||
sysl = set(self.syslocales.keys())
|
sysl = set(self.syslocales.keys())
|
||||||
if (userl - sysl):
|
if (userl - sysl):
|
||||||
raise ValueError('non-existent locale specified')
|
raise ValueError('non-existent locale specified')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def writeConf(self):
|
def writeConf(self):
|
||||||
# We basically recreate locale-gen in python here, more or less.
|
# We basically recreate locale-gen in python here, more or less.
|
||||||
@ -106,7 +106,7 @@ class Locale(object):
|
|||||||
fh.write(line)
|
fh.write(line)
|
||||||
os.chmod(cfg, 0o0644)
|
os.chmod(cfg, 0o0644)
|
||||||
os.chown(cfg, 0, 0)
|
os.chown(cfg, 0, 0)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Timezone(object):
|
class Timezone(object):
|
||||||
@ -127,4 +127,4 @@ class Timezone(object):
|
|||||||
if os.path.isfile(tzdestfile):
|
if os.path.isfile(tzdestfile):
|
||||||
os.remove(tzdestfile)
|
os.remove(tzdestfile)
|
||||||
os.symlink(tzsrcfile, tzdestfile)
|
os.symlink(tzsrcfile, tzdestfile)
|
||||||
return()
|
return(None)
|
||||||
|
@ -57,4 +57,4 @@ class ServiceDB(object):
|
|||||||
else:
|
else:
|
||||||
if os.path.exists(dest_path):
|
if os.path.exists(dest_path):
|
||||||
os.remove(dest_path)
|
os.remove(dest_path)
|
||||||
return()
|
return(None)
|
||||||
|
@ -61,7 +61,7 @@ class Group(object):
|
|||||||
(self.password.hash if self.password.hash else '!!'), # Password hash (if it has one)
|
(self.password.hash if self.password.hash else '!!'), # Password hash (if it has one)
|
||||||
','.join(self.admins), # Users with administrative control of group
|
','.join(self.admins), # Users with administrative control of group
|
||||||
','.join(self.members)] # Comma-separated members of group
|
','.join(self.members)] # Comma-separated members of group
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def parseGroupLine(self, line):
|
def parseGroupLine(self, line):
|
||||||
groupdict = dict(zip(['name', 'password', 'gid', 'members'],
|
groupdict = dict(zip(['name', 'password', 'gid', 'members'],
|
||||||
@ -71,7 +71,7 @@ class Group(object):
|
|||||||
self.members = set(members)
|
self.members = set(members)
|
||||||
self.gid = int(groupdict['gid'])
|
self.gid = int(groupdict['gid'])
|
||||||
self.name = groupdict['name']
|
self.name = groupdict['name']
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def parseGshadowLine(self, line):
|
def parseGshadowLine(self, line):
|
||||||
groupdict = dict(zip(['name', 'password', 'admins', 'members'],
|
groupdict = dict(zip(['name', 'password', 'admins', 'members'],
|
||||||
@ -85,7 +85,7 @@ class Group(object):
|
|||||||
self.admins = set(admins)
|
self.admins = set(admins)
|
||||||
if members:
|
if members:
|
||||||
self.members = set(members)
|
self.members = set(members)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class Password(object):
|
class Password(object):
|
||||||
@ -133,7 +133,7 @@ class Password(object):
|
|||||||
self.hash_type = re.sub(r'_crypt$', '', self._pass_context.identify(self.hash))
|
self.hash_type = re.sub(r'_crypt$', '', self._pass_context.identify(self.hash))
|
||||||
if not self.hash_type:
|
if not self.hash_type:
|
||||||
warnings.warn('Could not determine hash type')
|
warnings.warn('Could not determine hash type')
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class User(object):
|
class User(object):
|
||||||
@ -161,7 +161,7 @@ class User(object):
|
|||||||
def _initVals(self):
|
def _initVals(self):
|
||||||
if self.xml is None:
|
if self.xml is None:
|
||||||
# We manually assign these.
|
# We manually assign these.
|
||||||
return()
|
return(None)
|
||||||
self.name = self.xml.attrib['name']
|
self.name = self.xml.attrib['name']
|
||||||
# XML declared users are always new.
|
# XML declared users are always new.
|
||||||
self.new = True
|
self.new = True
|
||||||
@ -206,7 +206,7 @@ class User(object):
|
|||||||
g = Group(group_xml)
|
g = Group(group_xml)
|
||||||
g.members.add(self.name)
|
g.members.add(self.name)
|
||||||
self.groups.append(g)
|
self.groups.append(g)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def genFileLine(self):
|
def genFileLine(self):
|
||||||
if not all((self.uid, self.primary_group.gid)):
|
if not all((self.uid, self.primary_group.gid)):
|
||||||
@ -230,7 +230,7 @@ class User(object):
|
|||||||
(str(self.inactive_period) if self.inactive_period else ''), # Password inactivity period
|
(str(self.inactive_period) if self.inactive_period else ''), # Password inactivity period
|
||||||
(str((self.expire_date - _epoch).days) if self.expire_date else ''), # Expiration date
|
(str((self.expire_date - _epoch).days) if self.expire_date else ''), # Expiration date
|
||||||
''] # "Reserved"
|
''] # "Reserved"
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def parseShadowLine(self, line):
|
def parseShadowLine(self, line):
|
||||||
shadowdict = dict(zip(['name', 'password', 'last_change', 'minimum_age', 'maximum_age', 'warning_period',
|
shadowdict = dict(zip(['name', 'password', 'last_change', 'minimum_age', 'maximum_age', 'warning_period',
|
||||||
@ -260,7 +260,7 @@ class User(object):
|
|||||||
for k in ('home', 'shell'):
|
for k in ('home', 'shell'):
|
||||||
if userdict[k].strip() != '':
|
if userdict[k].strip() != '':
|
||||||
setattr(self, k, userdict[k])
|
setattr(self, k, userdict[k])
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
class UserDB(object):
|
class UserDB(object):
|
||||||
@ -322,7 +322,7 @@ class UserDB(object):
|
|||||||
if k in self.login_defaults.keys():
|
if k in self.login_defaults.keys():
|
||||||
v = self.login_defaults[k].lower()
|
v = self.login_defaults[k].lower()
|
||||||
self.login_defaults[k] = (True if v == 'yes' else False)
|
self.login_defaults[k] = (True if v == 'yes' else False)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _parseShadow(self):
|
def _parseShadow(self):
|
||||||
sys_shadow = {}
|
sys_shadow = {}
|
||||||
@ -364,7 +364,7 @@ class UserDB(object):
|
|||||||
rootuser = users['root']
|
rootuser = users['root']
|
||||||
rootuser.password = self.rootpass
|
rootuser.password = self.rootpass
|
||||||
rootuser.password.detectHashType()
|
rootuser.password.detectHashType()
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def _parseXML(self):
|
def _parseXML(self):
|
||||||
for user_xml in self.xml.findall('user'):
|
for user_xml in self.xml.findall('user'):
|
||||||
@ -393,7 +393,7 @@ class UserDB(object):
|
|||||||
if not g.create:
|
if not g.create:
|
||||||
u.groups[idx] = new_group[0]
|
u.groups[idx] = new_group[0]
|
||||||
self.new_users.append(u)
|
self.new_users.append(u)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getAvailUID(self, system = False):
|
def getAvailUID(self, system = False):
|
||||||
if not self.login_defaults:
|
if not self.login_defaults:
|
||||||
@ -490,4 +490,4 @@ class UserDB(object):
|
|||||||
('NOPASSWD: ' if not u.sudoPassword else '')))
|
('NOPASSWD: ' if not u.sudoPassword else '')))
|
||||||
os.chown(sudo_file, 0, 0)
|
os.chown(sudo_file, 0, 0)
|
||||||
os.chmod(sudo_file, 0o0440)
|
os.chmod(sudo_file, 0o0440)
|
||||||
return()
|
return(None)
|
||||||
|
@ -15,7 +15,7 @@ from . import hash_handler
|
|||||||
def checkMounted(devpath):
|
def checkMounted(devpath):
|
||||||
if devpath in [p.device for p in psutil.disk_partitions(all = True)]:
|
if devpath in [p.device for p in psutil.disk_partitions(all = True)]:
|
||||||
raise RuntimeError('{0} is mounted; we are cowardly refusing to destructive operations on it'.format(devpath))
|
raise RuntimeError('{0} is mounted; we are cowardly refusing to destructive operations on it'.format(devpath))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
def collapseKeys(d, keylist = None):
|
def collapseKeys(d, keylist = None):
|
||||||
|
@ -40,4 +40,4 @@ class Directory(object):
|
|||||||
self.dirs.append(dirs)
|
self.dirs.append(dirs)
|
||||||
self.dirs.sort()
|
self.dirs.sort()
|
||||||
self.files.sort()
|
self.files.sort()
|
||||||
return()
|
return(None)
|
||||||
|
@ -30,7 +30,7 @@ class GPG(object):
|
|||||||
self.primary_key = self.createKey('AIF-NG File Verification Key', sign = True, force = True)
|
self.primary_key = self.createKey('AIF-NG File Verification Key', sign = True, force = True)
|
||||||
else:
|
else:
|
||||||
self.primary_key = self.getKey(self.primary_key, secret = True)
|
self.primary_key = self.getKey(self.primary_key, secret = True)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# This is mostly just to cleanup the stuff we did before.
|
# This is mostly just to cleanup the stuff we did before.
|
||||||
@ -39,7 +39,7 @@ class GPG(object):
|
|||||||
self.primary_key = None
|
self.primary_key = None
|
||||||
shutil.rmtree(self.homedir)
|
shutil.rmtree(self.homedir)
|
||||||
self.gpg = None
|
self.gpg = None
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def createKey(self, userid, *args, **kwargs):
|
def createKey(self, userid, *args, **kwargs):
|
||||||
# algorithm=None, expires_in=0, expires=True, sign=False, encrypt=False, certify=False,
|
# algorithm=None, expires_in=0, expires=True, sign=False, encrypt=False, certify=False,
|
||||||
@ -85,7 +85,7 @@ class GPG(object):
|
|||||||
except gpg.errors.KeyNotFound:
|
except gpg.errors.KeyNotFound:
|
||||||
key = None
|
key = None
|
||||||
return(key)
|
return(key)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getKeyFile(self, keyfile, keyring_import = False):
|
def getKeyFile(self, keyfile, keyring_import = False):
|
||||||
keyfile = os.path.abspath(os.path.expanduser(keyfile))
|
keyfile = os.path.abspath(os.path.expanduser(keyfile))
|
||||||
@ -115,7 +115,7 @@ class GPG(object):
|
|||||||
if not isinstance(keydata, list):
|
if not isinstance(keydata, list):
|
||||||
keydata = [keydata]
|
keydata = [keydata]
|
||||||
self.gpg.op_import_keys(keydata)
|
self.gpg.op_import_keys(keydata)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def verifyData(self, data, keys = None, strict = False, detached = None, *args, **kwargs):
|
def verifyData(self, data, keys = None, strict = False, detached = None, *args, **kwargs):
|
||||||
results = {}
|
results = {}
|
||||||
|
@ -75,7 +75,7 @@ def main():
|
|||||||
'Please ensure you have provided the correct passphrase.'))
|
'Please ensure you have provided the correct passphrase.'))
|
||||||
psk = pskGen(args.ssid, args.passphrase)
|
psk = pskGen(args.ssid, args.passphrase)
|
||||||
print('PSK for network "{0}": {1}'.format(args.ssid, psk))
|
print('PSK for network "{0}": {1}'.format(args.ssid, psk))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user