def __init__(self): if not os.path.exists(MDADM_EXEC): if linux.os.redhat_family: system2(('/usr/bin/yum', '-d0', '-y', 'install', 'mdadm', '-x', 'exim'), raise_exc=False) else: pkgmgr.installed('mdadm') if not os.path.exists('/proc/mdstat'): coreutils.modprobe('md_mod') for location in ['/etc ', '/lib']: path = os.path.join(location, 'udev/rules.d/85-mdadm.rules') if os.path.exists(path): rule = None with open(path, 'r') as fp: rule = fp.read() if rule: rule = re.sub(re.compile('^([^#])', re.M), '#\\1', rule) with open(path, 'w') as fp: fp.write(rule) self._raid_devices_re = re.compile('Raid\s+Devices\s+:\s+(?P<count>\d+)') self._total_devices_re = re.compile('Total\s+Devices\s+:\s+(?P<count>\d+)') self._state_re = re.compile('State\s+:\s+(?P<state>.+)') self._rebuild_re = re.compile('Rebuild\s+Status\s+:\s+(?P<percent>\d+)%') self._level_re = re.compile('Raid Level : (?P<level>.+)')
def __init__(self, size=None, snapshot_id=None, avail_zone=None, tags=None, volume_type=None, **kwds): base.Volume.__init__(self, size=size and int(size) or None, snapshot_id=snapshot_id, avail_zone=avail_zone, tags=tags, volume_type=volume_type, **kwds) self.error_messages.update({ 'no_id_or_conn': 'Volume has no ID or Cinder volume connection ' 'required for volume construction'}) self.error_messages.update({ 'no_connection': 'Cinder connection should be available ' 'to perform this operation'}) self._cinder = __openstack__['new_cinder_connection'] self._nova = __openstack__['new_nova_connection'] # http://www.linux-kvm.org/page/Hotadd_pci_devices for mod in ('acpiphp', 'pci_hotplug'): try: coreutils.modprobe(mod) except: # Ignore errors like FATAL: Module acpiphp not found pass
def usable(): if Lvm2._usable is None: Lvm2._usable = False try: coreutils.modprobe('dm_snapshot') coreutils.modprobe('dm_mod') Lvm2._usable = True except: try: import platform release = platform.release() kernel_config_path = "/boot/config-" + release if os.path.isfile(kernel_config_path): with open(kernel_config_path) as f: kernel_config = f.readlines() drivers_compiled = dict(CONFIG_BLK_DEV_DM=False, CONFIG_DM_SNAPSHOT=False) for line in kernel_config: for driver_name in drivers_compiled.keys(): if line.startswith(driver_name): drivers_compiled[driver_name] = line.strip( ).split('=')[1] == 'y' if all(drivers_compiled.values()): Lvm2._usable = True except: pass return Lvm2._usable
def __init__(self): if not os.path.exists(MDADM_EXEC): if disttool.is_redhat_based(): system2(('/usr/bin/yum', '-d0', '-y', 'install', 'mdadm', '-x', 'exim'), raise_exc=False) else: mgr = dynimp.package_mgr() mgr.install('mdadm', mgr.candidates('mdadm')[-1]) if not os.path.exists('/proc/mdstat'): coreutils.modprobe('md_mod') for location in ['/etc ', '/lib']: path = os.path.join(location, 'udev/rules.d/85-mdadm.rules') if os.path.exists(path): rule = None with open(path, 'r') as fp: rule = fp.read() if rule: rule = re.sub(re.compile('^([^#])', re.M), '#\\1', rule) with open(path, 'w') as fp: fp.write(rule) self._raid_devices_re = re.compile('Raid\s+Devices\s+:\s+(?P<count>\d+)') self._total_devices_re = re.compile('Total\s+Devices\s+:\s+(?P<count>\d+)') self._state_re = re.compile('State\s+:\s+(?P<state>.+)') self._rebuild_re = re.compile('Rebuild\s+Status\s+:\s+(?P<percent>\d+)%') self._level_re = re.compile('Raid Level : (?P<level>.+)')
def __init__(self, size=None, snapshot_id=None, avail_zone=None, tags=None, volume_type=None, **kwds): base.Volume.__init__(self, size=size and int(size) or None, snapshot_id=snapshot_id, avail_zone=avail_zone, tags=tags, volume_type=volume_type, **kwds) self.error_messages.update({ 'no_id_or_conn': 'Volume has no ID or Cinder volume connection ' 'required for volume construction' }) self.error_messages.update({ 'no_connection': 'Cinder connection should be available ' 'to perform this operation' }) self._cinder = self._nova = None # http://www.linux-kvm.org/page/Hotadd_pci_devices for mod in ('acpiphp', 'pci_hotplug'): try: coreutils.modprobe(mod) except: # Ignore errors like FATAL: Module acpiphp not found pass
def usable(): if Lvm2._usable is None: Lvm2._usable = False try: coreutils.modprobe('dm_snapshot') coreutils.modprobe('dm_mod') Lvm2._usable = True except: try: import platform release = platform.release() kernel_config_path = "/boot/config-" + release if os.path.isfile(kernel_config_path): with open(kernel_config_path) as f: kernel_config = f.readlines() drivers_compiled = dict(CONFIG_BLK_DEV_DM=False, CONFIG_DM_SNAPSHOT=False) for line in kernel_config: for driver_name in drivers_compiled.keys(): if line.startswith(driver_name): drivers_compiled[driver_name] = line.strip().split('=')[1] == 'y' if all(drivers_compiled.values()): Lvm2._usable = True except: pass return Lvm2._usable
def __init__(self): if not os.path.exists('/sbin/mkfs.%s' % self.type): coreutils.modprobe(self.type) if self.os_packages: LOG.debug('Installing OS packages') for package in self.os_packages: pkgmgr.installed(package)
def __init__(self): if not os.path.exists("/sbin/mkfs.%s" % self.name): try: coreutils.modprobe(self.name) except: e = sys.exc_info()[1] error_text = "Cannot load '%s' kernel module: %s" % (self.name, e) raise Exception(error_text) if self.os_packages: for package in self.os_packages: pkgmgr.installed(package)
def __init__(self): if not os.path.exists('/sbin/mkfs.%s' % self.name): try: coreutils.modprobe(self.name) except: e = sys.exc_info()[1] error_text="Cannot load '%s' kernel module: %s" % (self.name, e) raise Exception(error_text) if self.os_packages: for package in self.os_packages: pkgmgr.installed(package)
def __init__(self): if not os.path.exists('/sbin/mkfs.%s' % self.name): try: coreutils.modprobe(self.name) except: e = sys.exc_info()[1] error_text="Cannot load '%s' kernel module: %s" % (self.name, e) raise Exception(error_text) mgr = dynimp.package_mgr() if self.os_packages: for package in self.os_packages: candidates = mgr.candidates(package) if candidates: mgr.install(package, candidates[-1]) else: raise Exception("No installation candidates for package '%s'", package)
def system_info(verbose=False): def check_module(module): try: return not coreutils.modprobe(module, dry_run=True)[2] except: return False ret = {} ret['software'] = [] installed_list = all_installed() for software_inf in installed_list: v = dict( name=software_inf.name, version='.'.join([str(x) for x in software_inf.version]) ) if verbose: v['string_version'] = software_inf.string_version ret['software'].append(v) ret['os'] = {} ret['os']['version'] = '{0} {1} {2}'.format(linux.os['name'], linux.os['release'], linux.os['codename']).strip() ret['os']['string_version'] = ' '.join(platform.uname()).strip() ret['dist'] = { 'distributor': linux.os['name'].lower(), 'release': str(linux.os['release']), 'codename': linux.os['codename'] } ret['os']['arch'] = linux.os['arch'] ret['storage'] = {} ret['storage']['fstypes'] = [] for fstype in ['xfs', 'ext3', 'ext4']: try: retcode = coreutils.modprobe(fstype, dry_run=True)[1] except: retcode = 1 exe = which('mkfs.%s' % fstype) if not retcode and exe: ret['storage']['fstypes'].append(fstype) # Raid levels support detection if which('mdadm'): for module in ('raid0', 'raid1', 'raid456'): ret['storage'][module] = 1 if check_module(module) else 0 # Lvm2 support detection if which('dmsetup') and all(map(check_module, ('dm_mod', 'dm_snapshot'))): ret['storage']['lvm'] = 1 else: ret['storage']['lvm'] = 0 return ret
def system_info(verbose=False): def check_module(module): try: return not coreutils.modprobe(module, dry_run=True)[2] except: return False ret = {} ret['software'] = [] installed_list = all_installed() for software_inf in installed_list: v = dict(name=software_inf.name, version='.'.join([str(x) for x in software_inf.version])) if verbose: v['string_version'] = software_inf.string_version ret['software'].append(v) ret['os'] = {} ret['os']['version'] = '{0} {1} {2}'.format(linux.os['name'], linux.os['release'], linux.os['codename']).strip() ret['os']['string_version'] = ' '.join(platform.uname()).strip() ret['dist'] = { 'distributor': linux.os['name'].lower(), 'release': str(linux.os['release']), 'codename': linux.os['codename'] } ret['os']['arch'] = linux.os['arch'] ret['storage'] = {} ret['storage']['fstypes'] = [] for fstype in ['xfs', 'ext3', 'ext4']: try: retcode = coreutils.modprobe(fstype, dry_run=True)[1] except: retcode = 1 exe = which('mkfs.%s' % fstype) if not retcode and exe: ret['storage']['fstypes'].append(fstype) # Raid levels support detection if which('mdadm'): for module in ('raid0', 'raid1', 'raid456'): ret['storage'][module] = 1 if check_module(module) else 0 # Lvm2 support detection if which('dmsetup') and all(map(check_module, ('dm_mod', 'dm_snapshot'))): ret['storage']['lvm'] = 1 else: ret['storage']['lvm'] = 0 return ret
def check_module(module): try: return not coreutils.modprobe(module, dry_run=True)[2] except: return False
import logging import re import os from scalarizr import linux from scalarizr.linux import coreutils from scalarizr.storage2 import StorageError if not linux.which('mdadm'): from scalarizr.linux import pkgmgr pkgmgr.installed('mdadm', updatedb=True) mdadm_binary = linux.which('mdadm') if not os.path.exists('/proc/mdstat'): coreutils.modprobe('md_mod') LOG = logging.getLogger(__name__) def mdadm(mode, md_device=None, *devices, **long_kwds): """ Example: mdadm.mdadm('create', '/dev/md0', '/dev/loop0', '/dev/loop1', level=0, metadata='default', assume_clean=True, raid_devices=2) """ raise_exc = long_kwds.pop('raise_exc', True) return linux.system(linux.build_cmd_args( mdadm_binary, ['--%s' % mode] + ([md_device] if md_device else []), long_kwds, devices), raise_exc=raise_exc)
import logging import re import os from scalarizr import linux from scalarizr.linux import coreutils from scalarizr.storage2 import StorageError if not linux.which('mdadm'): from scalarizr.linux import pkgmgr pkgmgr.installed('mdadm', updatedb=True) mdadm_binary = linux.which('mdadm') if not os.path.exists('/proc/mdstat'): coreutils.modprobe('md_mod') LOG = logging.getLogger(__name__) def mdadm(mode, md_device=None, *devices, **long_kwds): """ Example: mdadm.mdadm('create', '/dev/md0', '/dev/loop0', '/dev/loop1', level=0, metadata='default', assume_clean=True, raid_devices=2) """ raise_exc = long_kwds.pop('raise_exc', True) return linux.system(linux.build_cmd_args( mdadm_binary, ['--%s' % mode] + ([md_device] if md_device else []), long_kwds, devices),