logging to network providers
This commit is contained in:
@@ -44,14 +44,16 @@ class Disk(object):
|
||||
if self.devpath == 'auto':
|
||||
self.devpath = '/dev/{0}'.format(blkinfo.BlkDiskInfo().get_disks()[0]['kname'])
|
||||
if not os.path.isfile(self.devpath):
|
||||
raise ValueError('{0} does not exist; please specify an explicit device path'.format(self.devpath))
|
||||
_logger.error('Disk {0} does not exist; please specify an explicit device path'.format(self.devpath))
|
||||
raise ValueError('Disk not found')
|
||||
self.table_type = self.xml.attrib.get('diskFormat', 'gpt').lower()
|
||||
if self.table_type in ('bios', 'mbr', 'dos'):
|
||||
self.table_type = 'msdos'
|
||||
validlabels = parted.getLabels()
|
||||
if self.table_type not in validlabels:
|
||||
raise ValueError(('Disk format {0} is not valid for this architecture;'
|
||||
'must be one of: {1}'.format(self.table_type, ', '.join(list(validlabels)))))
|
||||
_logger.error(('Disk format ({0}) is not valid for this architecture;'
|
||||
'must be one of: {1}'.format(self.table_type, ', '.join(list(validlabels)))))
|
||||
raise ValueError('Invalid disk format')
|
||||
self.device = parted.getDevice(self.devpath)
|
||||
self.disk = parted.freshDisk(self.device, self.table_type)
|
||||
_logger.debug('Configured parted device for {0}.'.format(self.devpath))
|
||||
@@ -152,9 +154,10 @@ class Partition(object):
|
||||
self.part_type = parted.PARTITION_NORMAL
|
||||
self.fs_type = self.xml.attrib['fsType'].lower()
|
||||
if self.fs_type not in aif.constants.PARTED_FSTYPES:
|
||||
raise ValueError(('{0} is not a valid partition filesystem type; '
|
||||
'must be one of: {1}').format(self.xml.attrib['fsType'],
|
||||
', '.join(sorted(aif.constants.PARTED_FSTYPES))))
|
||||
_logger.error(('{0} is not a valid partition filesystem type; must be one of: '
|
||||
'{1}').format(self.xml.attrib['fsType'],
|
||||
', '.join(sorted(aif.constants.PARTED_FSTYPES))))
|
||||
raise ValueError('Invalid partition filesystem type')
|
||||
self.disk = diskobj
|
||||
self.device = self.disk.device
|
||||
self.devpath = '{0}{1}'.format(self.device.path, self.partnum)
|
||||
|
||||
@@ -92,9 +92,8 @@ class Member(object):
|
||||
elif k == 'unused_space':
|
||||
r = _mdblock_unused_re.search(v)
|
||||
if not r:
|
||||
raise ValueError(('Could not parse {0} for '
|
||||
'{1}\'s superblock').format(orig_k,
|
||||
self.devpath))
|
||||
_logger.error('Could not parse {0} for {1}\'s superblock'.format(orig_k, self.devpath))
|
||||
raise RuntimeError('Could not parse unused space in superblock')
|
||||
v = {}
|
||||
for i in ('before', 'after'):
|
||||
v[i] = int(r.group(i)) # in sectors
|
||||
@@ -102,9 +101,8 @@ class Member(object):
|
||||
k = 'badblock_log_entries'
|
||||
r = _mdblock_badblock_re.search(v)
|
||||
if not r:
|
||||
raise ValueError(('Could not parse {0} for '
|
||||
'{1}\'s superblock').format(orig_k,
|
||||
self.devpath))
|
||||
_logger.error('Could not parse {0} for {1}\'s superblock'.format(orig_k, self.devpath))
|
||||
raise RuntimeError('Could not parse badblocks in superblock')
|
||||
v = {}
|
||||
for i in ('entries', 'offset'):
|
||||
v[i] = int(r.group(i)) # offset is in sectors
|
||||
@@ -118,9 +116,8 @@ class Member(object):
|
||||
elif re.search(r'^((avail|used)_dev|array)_size$', k):
|
||||
r = _mdblock_size_re.search(v)
|
||||
if not r:
|
||||
raise ValueError(('Could not parse {0} for '
|
||||
'{1}\'s superblock').format(orig_k,
|
||||
self.devpath))
|
||||
_logger.error('Could not parse {0} for {1}\'s superblock'.format(orig_k, self.devpath))
|
||||
raise RuntimeError('Could not parse size value in superblock')
|
||||
v = {}
|
||||
for i in ('sectors', 'GB', 'GiB'):
|
||||
v[i] = float(r.group(i))
|
||||
@@ -204,7 +201,7 @@ class Array(object):
|
||||
def addMember(self, memberobj):
|
||||
if not isinstance(memberobj, Member):
|
||||
_logger.error('memberobj must be of type aif.disk.mdadm.Member')
|
||||
raise ValueError('Invalid memberobj type')
|
||||
raise TypeError('Invalid memberobj type')
|
||||
memberobj.prepare()
|
||||
self.members.append(memberobj)
|
||||
return(None)
|
||||
|
||||
Reference in New Issue
Block a user