def get_os_type_id(self, conn): default_desc = "Other Ubuntu (%d-bit)" % disttool.arch_bits() desc = "%s %s (%d-bit)" % (disttool.linux_dist()[0], disttool.linux_dist()[1], disttool.arch_bits()) default = 0 for ostype in conn.listOsTypes(): if ostype.description == default_desc: default = ostype.id elif ostype.description == desc: return ostype.id return default
def get_os_type_id(self, conn): default_desc = 'Other Ubuntu (%d-bit)' % disttool.arch_bits() desc = '%s %s (%d-bit)' % (disttool.linux_dist()[0], disttool.linux_dist()[1], disttool.arch_bits()) default = 0 for ostype in conn.listOsTypes(): if ostype.description == default_desc: default = ostype.id elif ostype.description == desc: return ostype.id return default
def __init__(self, manifest=None): mgr_name = "apt" if disttool.is_debian_based() else "yum" self.mgr = AptPackageMgr() if disttool.is_debian_based() else YumPackageMgr() self.manifest = os.path.abspath(manifest or self.DEFAULT_MANIFEST) self.conf = configparser.ConfigParser() self.conf.read(self.manifest) dist_id, release = disttool.linux_dist()[0:2] if disttool.is_redhat_based() and not disttool.is_fedora(): dist_id = "el" dist_id = dist_id.lower() major_release = release.split(".")[0] self.sections = [ s % locals() for s in ( "%(mgr_name)s", "%(mgr_name)s:%(dist_id)s", "%(mgr_name)s:%(dist_id)s%(major_release)s", "%(mgr_name)s:%(dist_id)s%(release)s", ) ] self.sections.reverse() LOG.debug( "Initialized ImpLoader with such settings\n" " manifest: %s\n" " sections: %s\n", self.manifest, self.sections, )
def __init__(self, manifest=None): mgr_name = 'apt' if disttool.is_debian_based() else 'yum' self.mgr = AptPackageMgr() if disttool.is_debian_based( ) else YumPackageMgr() self.manifest = os.path.abspath(manifest or self.DEFAULT_MANIFEST) self.conf = configparser.ConfigParser() self.conf.read(self.manifest) dist_id, release = disttool.linux_dist()[0:2] if disttool.is_redhat_based() and not disttool.is_fedora(): dist_id = 'el' dist_id = dist_id.lower() major_release = release.split('.')[0] self.sections = [ s % locals() for s in ('%(mgr_name)s', '%(mgr_name)s:%(dist_id)s', '%(mgr_name)s:%(dist_id)s%(major_release)s', '%(mgr_name)s:%(dist_id)s%(release)s') ] self.sections.reverse() LOG.debug( 'Initialized ImpLoader with such settings\n' ' manifest: %s\n' ' sections: %s\n', self.manifest, self.sections)
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'] = ' '.join(disttool.linux_dist()) ret['os']['string_version'] = ' '.join(disttool.uname()).strip() ret['dist'] = { 'distributor': linux.os['name'].lower(), 'release': str(linux.os['release']), 'codename': linux.os['codename'] } ret['storage'] = {} ret['storage']['fstypes'] = [] for fstype in ['xfs', 'ext3', 'ext4']: try: retcode = coreutils.modprobe(fstype, dry_run=True)[1] except: retcode = 1 exe = whereis('mkfs.%s' % fstype) if not retcode and exe: ret['storage']['fstypes'].append(fstype) # Raid levels support detection if whereis('mdadm'): for module in ('raid0', 'raid1', 'raid456'): ret['storage'][module] = 1 if check_module(module) else 0 # Lvm2 support detection if whereis('dmsetup') and all(map(check_module, ('dm_mod', 'dm_snapshot'))): ret['storage']['lvm'] = 1 else: ret['storage']['lvm'] = 0 return ret
def is_running(name): if not _services.has_key(name): raise InitdError("Unknown service '%s'" % (name,)) cmd = [_services[name]["initd_script"], "status"] out, err = system2(cmd)[0:2] out += err if name == "mysql" and disttool.is_ubuntu() and disttool.linux_dist()[1] == '8.04': return out.lower().find("Uptime:") != -1 else: return out.lower().find("running") != -1 or out.lower().find("[ ok ]") != -1 or out.lower().find("done.") != -1
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'] = ' '.join(disttool.linux_dist()) ret['os']['string_version'] = ' '.join(disttool.uname()).strip() ret['dist'] = { 'distributor': linux.os['name'].lower(), 'release': str(linux.os['release']), 'codename': linux.os['codename'] } ret['storage'] = {} ret['storage']['fstypes'] = [] for fstype in ['xfs', 'ext3', 'ext4']: try: retcode = coreutils.modprobe(fstype, dry_run=True)[1] except: retcode = 1 exe = whereis('mkfs.%s' % fstype) if not retcode and exe: ret['storage']['fstypes'].append(fstype) # Raid levels support detection if whereis('mdadm'): for module in ('raid0', 'raid1', 'raid456'): ret['storage'][module] = 1 if check_module(module) else 0 # Lvm2 support detection if whereis('dmsetup') and all(map(check_module, ('dm_mod', 'dm_snapshot'))): ret['storage']['lvm'] = 1 else: ret['storage']['lvm'] = 0 return ret
def is_running(name): if not _services.has_key(name): raise InitdError("Unknown service '%s'" % (name, )) cmd = [_services[name]["initd_script"], "status"] out, err = system2(cmd)[0:2] out += err if name == "mysql" and disttool.is_ubuntu() and disttool.linux_dist( )[1] == '8.04': return out.lower().find("Uptime:") != -1 else: return out.lower().find("running") != -1 or out.lower().find( "[ ok ]") != -1 or out.lower().find("done.") != -1
def update(self, workdir): if not os.access(self.executable, os.X_OK): self._logger.info('Installing Git SCM...') if disttool.is_debian_based(): system2(('apt-get', '-y', 'install', 'git-core')) elif disttool.is_redhat_based(): system2(('yum', '-y', 'install', 'git')) else: raise SourceError('Cannot install Git. Unknown distribution %s' % str(disttool.linux_dist())) #if not os.path.exists(workdir): # self._logger.info('Creating destination directory') # os.makedirs(workdir) tmpdir = tempfile.mkdtemp() env = {} try: if self.private_key: pk_path = os.path.join(tmpdir, 'pk.pem') filetool.write_file(pk_path, self.private_key) os.chmod(pk_path, 0400) git_ssh_path = os.path.join(tmpdir, 'git_ssh.sh') filetool.write_file(git_ssh_path, self.ssh_tpl % pk_path) os.chmod(git_ssh_path, 0755) env.update(dict(GIT_SSH=git_ssh_path)) if os.path.exists(os.path.join(workdir, '.git')): origin_url = system2(('git', 'config', '--get', 'remote.origin.url'), cwd=workdir, raise_exc=False)[0] if origin_url.strip() != self.url.strip(): self._logger.info('%s is not origin of %s (%s is)', self.url, workdir, origin_url) self._logger.info('Remove all files in %s and checkout from %s', workdir, self.url ) shutil.rmtree(workdir) os.mkdir(workdir) out, err, ret_code = system2(('git', 'clone', self.url, workdir), env=env) else: self._logger.info('Updating directory %s (git-pull)', workdir) out, err, ret_code = system2(('git', 'pull'), env=env, cwd=workdir) else: self._logger.info('Checkout from %s', self.url) out, err, ret_code = system2(('git', 'clone', self.url, workdir), env=env) if ret_code: raise Exception('Git failed to clone repository. %s' % out) self._logger.info('Successfully deployed %s from %s', workdir, self.url) finally: shutil.rmtree(tmpdir)
def main(): init_script() logger = logging.getLogger("scalarizr.scripts.update") logger.info("Starting update script...") if disttool.is_debian_based(): logger.info("Updating scalarizr with Apt") system2("apt-get -y install scalarizr", shell=True) elif disttool.is_redhat_based(): logger.info("Updating scalarizr with Yum") system2("yum -y update scalarizr", shell=True) else: logger.error("Don't know how to update scalarizr on %s", " ".join(disttool.linux_dist()))
def update(self, workdir): if not os.access(self.executable, os.X_OK): self._logger.info('Installing Subversion SCM...') if disttool.is_debian_based(): system2(('apt-get', '-y', '--force-yes', 'install', 'subversion')) elif disttool.is_redhat_based(): system2(('yum', '-y', 'install', 'subversion')) else: raise SourceError('Cannot install Subversion. Unknown distribution %s' % str(disttool.linux_dist())) do_update = False if os.path.exists(os.path.join(workdir, '.svn')): out = system2(('svn', 'info', workdir))[0] try: svn_url = filter(lambda line: line.startswith('URL:'), out.split('\n'))[0].split(':', 1)[1].strip() except IndexError: raise SourceError('Cannot extract Subversion URL. Text:\n %s', out) if svn_url != self.url: #raise SourceError('Working copy %s is checkouted from different repository %s' % (workdir, svn_url)) self._logger.info('%s is not origin of %s (%s is)', self.url, workdir, svn_url) self._logger.info('Remove all files in %s and checkout from %s', workdir, self.url) shutil.rmtree(workdir) os.mkdir(workdir) else: do_update = True args = [ 'svn' , 'update' if do_update else 'co' ] if self.login and self.password: args += [ '--username', self.login, '--password', self.password, '--non-interactive' ] if self.client_version >= (1, 5, 0): args += ['--trust-server-cert'] if args[1] == 'co': args += [self.url] args += [workdir] self._logger.info('Updating source from %s into working dir %s', self.url, workdir) out = system2(args)[0] self._logger.info(out) self._logger.info('Deploying %s to %s has been completed successfully.' % (self.url,workdir))
def __init__(self): self._logger = logging.getLogger(__name__) self._handlers_chain = None cnf = bus.cnf platform = bus.platform LOG.debug("Initializing message listener") self._accept_kwargs = dict(behaviour=config.split( cnf.rawini.get(config.SECT_GENERAL, config.OPT_BEHAVIOUR)), platform=platform.name, os=disttool.uname(), dist=disttool.linux_dist()) LOG.debug("Keywords for each Handler::accept\n%s", pprint.pformat(self._accept_kwargs)) self.get_handlers_chain()
def dist(self): ''' Return Linux distribution information @rtype: dict Sample: {'id': 'Fedora', 'release': '15', 'codename': 'Lovelock', 'description': 'Fedora release 15 (Lovelock)'} ''' linux_dist = disttool.linux_dist() return { 'id': linux_dist[0], 'release': linux_dist[1], 'codename': linux_dist[2], 'description': '%s %s (%s)' % (linux_dist[0], linux_dist[1], linux_dist[2]) }