def select_bootstrap(repomd, cachedir, bootstrapdir): cfgmgr = configmgr lvl = msger.get_loglevel() msger.set_loglevel('quiet') repo_rpmver = misc.get_rpmver_in_repo(repomd) if not repo_rpmver: msger.set_loglevel(lvl) return (None, None) # Check avaliable bootstrap bootstrap_env = bootstrap.Bootstrap(homedir=bootstrapdir) for bs in bootstrap_env.list(): if compare_rpmversion(repo_rpmver, bs['rpm']): return (bs['name'], {}) for bsname, bsrepo in list(cfgmgr.bootstraps.items()): repolist = [] for repo in list(bsrepo.keys()): repolist.append(bsrepo[repo]) rpmver = None try: repomd = misc.get_metadata_from_repos(repolist, cachedir) rpmver = misc.get_rpmver_in_repo(repomd) except errors.CreatorError as e: msger.set_loglevel(lvl) raise if not rpmver: continue if compare_rpmversion(repo_rpmver, rpmver): msger.set_loglevel(lvl) return (bsname, bsrepo) msger.set_loglevel(lvl) return (None, None)
def runmic_in_bootstrap(name, argv, opts, ksfile, repolist): bootstrap_env = bootstrap.Bootstrap(homedir=opts['bootstrapdir']) bootstrap_lst = bootstrap_env.bootstraps setattr(bootstrap_env, 'rootdir', name) if not bootstrap_lst or not name in bootstrap_lst: msger.info("Creating bootstrap %s under %s" % (name, bootstrap_env.homedir)) bootstrap_env.create(name, repolist) msger.info("Use bootstrap: %s" % bootstrap_env.rootdir) # copy mic msger.info("Sync native mic to bootstrap") copy_mic(bootstrap_env.rootdir) # bind mounts , opts['cachedir'], opts['tmpdir'] cwd = os.getcwd() lst = [cwd, opts['outdir']] if ksfile: ksfp = os.path.abspath(os.path.expanduser(ksfile)) lst.append(os.path.dirname(ksfp)) if opts['logfile']: logfile = os.path.abspath(os.path.expanduser(opts['logfile'])) lst.append(os.path.dirname(logfile)) # TBD local package path # TBD local repo # make unique lst = list(set(lst)) # FIXME: wo need the original order here bindmounts = ';'.join( map(lambda p: os.path.abspath(os.path.expanduser(p)), lst)) msger.info("Start mic command in bootstrap") bootstrap_env.run(name, argv, cwd, bindmounts)
def bootstrap_mic(argv=None): def mychroot(): os.chroot(rootdir) os.chdir(cwd) # by default, sys.argv is used to run mic in bootstrap if not argv: argv = sys.argv if argv[0] not in ('/usr/bin/mic', 'mic'): argv[0] = '/usr/bin/mic' cropts = configmgr.create bsopts = configmgr.bootstrap distro = bsopts['distro_name'].lower() rootdir = bsopts['rootdir'] pkglist = bsopts['packages'] cwd = os.getcwd() # create bootstrap and run mic in bootstrap bsenv = bootstrap.Bootstrap(rootdir, distro, cropts['arch']) bsenv.logfile = cropts['logfile'] # rootdir is regenerated as a temp dir rootdir = bsenv.rootdir if 'optional' in bsopts: optlist = bsopts['optional'] else: optlist = [] try: msger.info("Creating %s bootstrap ..." % distro) bsenv.create(cropts['repomd'], pkglist, optlist) # bootstrap is relocated under "bootstrap" if os.path.exists(os.path.join(rootdir, "bootstrap")): rootdir = os.path.join(rootdir, "bootstrap") bsenv.dirsetup(rootdir) if cropts['use_mic_in_bootstrap']: msger.info("No copy host mic") else: msger.info("Copy host mic to bootstrap") sync_mic(rootdir, plugin=cropts['plugin_dir']) #FIXME: sync the ks file to bootstrap if "/" == os.path.dirname(os.path.abspath(configmgr._ksconf)): safecopy(configmgr._ksconf, rootdir) msger.info("Start mic in bootstrap: %s\n" % rootdir) bsarch = ELF_arch(rootdir) if bsarch in personality_defs: condPersonality(bsarch) bindmounts = get_bindmounts(cropts) ret = bsenv.run(argv, cwd, rootdir, bindmounts) except errors.BootstrapError, err: raise errors.CreatorError("Failed to download/install bootstrap package " \ "or the package is in bad format: %s" % err)
def bootstrap_mic(argv=None): def mychroot(): os.chroot(rootdir) os.chdir(cwd) # by default, sys.argv is used to run mic in bootstrap if not argv: argv = sys.argv if argv[0] not in ('/usr/bin/mic', 'mic'): argv[0] = '/usr/bin/mic' cropts = configmgr.create bsopts = configmgr.bootstrap distro = bsopts['distro_name'].lower() rootdir = bsopts['rootdir'] pkglist = bsopts['packages'] cwd = os.getcwd() # create bootstrap and run mic in bootstrap bsenv = bootstrap.Bootstrap(rootdir, distro, cropts['arch']) bsenv.logfile = cropts['logfile'] # rootdir is regenerated as a temp dir rootdir = bsenv.rootdir if 'optional' in bsopts: optlist = bsopts['optional'] else: optlist = [] try: msger.info("Creating %s bootstrap ..." % distro) bsenv.create(cropts['repomd'], pkglist, optlist) # bootstrap is relocated under "bootstrap" if os.path.exists(os.path.join(rootdir, "bootstrap")): rootdir = os.path.join(rootdir, "bootstrap") bsenv.dirsetup(rootdir) sync_mic(rootdir) #FIXME: sync the ks file to bootstrap if "/" == os.path.dirname(os.path.abspath(configmgr._ksconf)): safecopy(configmgr._ksconf, rootdir) msger.info("Start mic in bootstrap: %s\n" % rootdir) bindmounts = get_bindmounts(cropts) ret = bsenv.run(argv, cwd, rootdir, bindmounts) except errors.BootstrapError, err: msger.warning('\n%s' % err) if msger.ask("Switch to native mode and continue?"): return raise
def runmic_in_bootstrap(name, argv, opts, ksfile, repolist): bootstrap_env = bootstrap.Bootstrap(homedir=opts['bootstrapdir']) bootstrap_lst = bootstrap_env.bootstraps setattr(bootstrap_env, 'rootdir', name) if not bootstrap_lst or not name in bootstrap_lst: msger.info("Creating bootstrap %s under %s" % \ (name, bootstrap_env.homedir)) bootstrap_env.create(name, repolist) msger.info("Use bootstrap: %s" % bootstrap_env.rootdir) # copy mic msger.info("Sync native mic to bootstrap") copy_mic(bootstrap_env.rootdir) # bind mounts , opts['cachedir'], opts['tmpdir'] cwd = os.getcwd() lst = [cwd, opts['outdir']] if ksfile: ksfp = os.path.abspath(os.path.expanduser(ksfile)) lst.append(os.path.dirname(ksfp)) if opts['logfile']: logfile = os.path.abspath(os.path.expanduser(opts['logfile'])) lst.append(os.path.dirname(logfile)) if opts['local_pkgs_path']: lppdir = os.path.abspath(os.path.expanduser(opts['local_pkgs_path'])) lst.append(lppdir) # TBD local repo # make unique and remain the original order lst = sorted(set(lst), key=lst.index) bindmounts = ';'.join( [os.path.abspath(os.path.expanduser(p)) for p in lst]) msger.info("Start mic command in bootstrap") bootstrap_env.run(name, argv, cwd, bindmounts)