def do_pack(cls, base_on): import subprocess def __mkinitrd(instance): kernelver = list(instance._get_kernel_versions().values())[0][0] args = [ "/usr/libexec/mkliveinitrd", "/boot/initrd-%s.img" % kernelver, "%s" % kernelver ] try: subprocess.call(args, preexec_fn=instance._chroot) except OSError as xxx_todo_changeme: (err, msg) = xxx_todo_changeme.args raise errors.CreatorError( "Failed to execute /usr/libexec/mkliveinitrd: %s" % msg) def __run_post_cleanups(instance): kernelver = list(instance._get_kernel_versions().values())[0][0] args = ["rm", "-f", "/boot/initrd-%s.img" % kernelver] try: subprocess.call(args, preexec_fn=instance._chroot) except OSError as xxx_todo_changeme1: (err, msg) = xxx_todo_changeme1.args raise errors.CreatorError("Failed to run post cleanups: %s" % msg) convertoropts = configmgr.convert convertoropts['name'] = os.path.splitext(os.path.basename(base_on))[0] convertor = livecd.LiveCDImageCreator(convertoropts) imgtype = misc.get_image_type(base_on) if imgtype == "btrfsimg": fstype = "btrfs" elif imgtype in ("ext3fsimg", "ext4fsimg"): fstype = imgtype[:4] else: raise errors.CreatorError("Unsupported filesystem type: %s" % fstype) convertor._set_fstype(fstype) try: convertor.mount(base_on) __mkinitrd(convertor) convertor._create_bootconfig() __run_post_cleanups(convertor) convertor.launch_shell(convertoropts['shell']) convertor.unmount() convertor.package() convertor.print_outimage_info() finally: shutil.rmtree(os.path.dirname(base_on), ignore_errors=True)
def do_create(self, subcmd, opts, *args): """${cmd_name}: create livecd image Usage: ${name} ${cmd_name} <ksfile> [OPTS] ${cmd_option_list} """ creatoropts = common.creatoropts(args) if creatoropts['arch'] and creatoropts['arch'].startswith('arm'): msger.warning('livecd cannot support arm images, Quit') return creator = livecd.LiveCDImageCreator(creatoropts, creatoropts['pkgmgr_pcls']) creator._recording_pkgs = creatoropts['record_pkgs'] self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".iso"], creatoropts['release']) try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release']) else: creator.outimage.append(creatoropts['dst_ks']) creator.print_outimage_info() except errors.CreatorError: raise finally: creator.cleanup() msger.info("Finished.") return 0
def do_create(self, subcmd, opts, *args): """${cmd_name}: create livecd image Usage: ${name} ${cmd_name} <ksfile> [OPTS] ${cmd_option_list} """ if not args: raise errors.Usage("need one argument as the path of ks file") if len(args) != 1: raise errors.Usage("Extra arguments given") creatoropts = configmgr.create ksconf = args[0] if not os.path.exists(ksconf): raise errors.CreatorError("Can't find the file: %s" % ksconf) if creatoropts['arch'] and creatoropts['arch'].startswith('arm'): msger.warning('livecd cannot support arm images, Quit') return recording_pkgs = [] if len(creatoropts['record_pkgs']) > 0: recording_pkgs = creatoropts['record_pkgs'] if creatoropts['release'] is not None: if 'name' not in recording_pkgs: recording_pkgs.append('name') ksconf = misc.save_ksconf_file(ksconf, creatoropts['release']) configmgr._ksconf = ksconf # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there. if creatoropts['release'] is not None: creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name']) # try to find the pkgmgr pkgmgr = None for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): if key == creatoropts['pkgmgr']: pkgmgr = pcls break if not pkgmgr: pkgmgrs = pluginmgr.get_plugins('backend').keys() raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) if creatoropts['runtime']: rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None) creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs if creatoropts['release'] is None: imagefile = "%s.iso" % os.path.join(creator.destdir, creator.name) if os.path.exists(imagefile): if msger.ask('The target image: %s already exists, cleanup and continue?' % imagefile): os.unlink(imagefile) else: raise errors.Abort('Canceled') try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release']) creator.print_outimage_info() except errors.CreatorError: raise finally: creator.cleanup() msger.info("Finished.") return 0
try: subprocess.call(args, preexec_fn = instance._chroot) except OSError, (err, msg): raise errors.CreatorError("Failed to execute /usr/libexec/mkliveinitrd: %s" % msg) def __run_post_cleanups(instance): kernelver = instance._get_kernel_versions().values()[0][0] args = ["rm", "-f", "/boot/initrd-%s.img" % kernelver] try: subprocess.call(args, preexec_fn = instance._chroot) except OSError, (err, msg): raise errors.CreatorError("Failed to run post cleanups: %s" % msg) convertoropts = configmgr.convert convertor = livecd.LiveCDImageCreator(convertoropts) convertor.name = os.path.splitext(os.path.basename(base_on))[0] imgtype = misc.get_image_type(base_on) if imgtype == "btrfsimg": fstype = "btrfs" elif imgtype in ("ext3fsimg", "ext4fsimg"): fstype = imgtype[:4] else: raise errors.CreatorError("Unsupported filesystem type: %s" % fstype) convertor._set_fstype(fstype) try: convertor.mount(base_on) __mkinitrd(convertor) convertor._create_bootconfig() __run_post_cleanups(convertor) convertor.unmount()
def do_create(self, subcmd, opts, *args): """${cmd_name}: create livecd image Usage: ${name} ${cmd_name} <ksfile> [OPTS] ${cmd_option_list} """ if len(args) != 1: raise errors.Usage("Extra arguments given") creatoropts = configmgr.create ksconf = args[0] if creatoropts['runtime'] == 'bootstrap': configmgr._ksconf = ksconf rt_util.bootstrap_mic() elif not rt_util.inbootstrap(): try: fs_related.find_binary_path('mic-native') except errors.CreatorError: if not msger.ask( "Subpackage \"mic-native\" has not been " "installed in your host system, still " "continue with \"native\" running mode?", False): raise errors.Abort("Abort because subpackage 'mic-native' " "has not been installed") if creatoropts['arch'] and creatoropts['arch'].startswith('arm'): msger.warning('livecd cannot support arm images, Quit') return recording_pkgs = [] if len(creatoropts['record_pkgs']) > 0: recording_pkgs = creatoropts['record_pkgs'] if creatoropts['release'] is not None: if 'name' not in recording_pkgs: recording_pkgs.append('name') if 'vcs' not in recording_pkgs: recording_pkgs.append('vcs') configmgr._ksconf = ksconf # try to find the pkgmgr pkgmgr = None backends = pluginmgr.get_plugins('backend') if 'auto' == creatoropts['pkgmgr']: for key in configmgr.prefer_backends: if key in backends: pkgmgr = backends[key] break else: for key in backends.keys(): if key == creatoropts['pkgmgr']: pkgmgr = backends[key] break if not pkgmgr: raise errors.CreatorError( "Can't find backend: %s, " "available choices: %s" % (creatoropts['pkgmgr'], ','.join(backends.keys()))) creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".iso"], creatoropts['release']) try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) creator.copy_kernel() creator.unmount() creator.package(creatoropts["destdir"]) creator.create_manifest() if creatoropts['release'] is not None: creator.release_output(ksconf, creatoropts['destdir'], creatoropts['release']) creator.print_outimage_info() except errors.CreatorError: raise finally: creator.cleanup() msger.info("Finished.") return 0
def do_create(self, subcmd, opts, *args): """${cmd_name}: create livecd image Usage: ${name} ${cmd_name} <ksfile> [OPTS] ${cmd_option_list} """ if len(args) != 1: raise errors.Usage("Extra arguments given") creatoropts = configmgr.create ksconf = args[0] if creatoropts['runtime'] == 'bootstrap': configmgr._ksconf = ksconf rt_util.bootstrap_mic() if creatoropts['arch'] and creatoropts['arch'].startswith('arm'): msger.warning('livecd cannot support arm images, Quit') return recording_pkgs = [] if len(creatoropts['record_pkgs']) > 0: recording_pkgs = creatoropts['record_pkgs'] if creatoropts['release'] is not None: if 'name' not in recording_pkgs: recording_pkgs.append('name') if 'vcs' not in recording_pkgs: recording_pkgs.append('vcs') configmgr._ksconf = ksconf # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there. if creatoropts['release'] is not None: creatoropts['outdir'] = "%s/%s/images/%s/" % ( creatoropts['outdir'], creatoropts['release'], creatoropts['name']) # try to find the pkgmgr pkgmgr = None backends = pluginmgr.get_plugins('backend') if 'auto' == creatoropts['pkgmgr']: for key in configmgr.prefer_backends: if key in backends: pkgmgr = backends[key] break else: for key in backends.keys(): if key == creatoropts['pkgmgr']: pkgmgr = backends[key] break if not pkgmgr: raise errors.CreatorError( "Can't find backend: %s, " "available choices: %s" % (creatoropts['pkgmgr'], ','.join(backends.keys()))) creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".iso"], creatoropts['release']) try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release']) creator.print_outimage_info() except errors.CreatorError: raise finally: creator.cleanup() msger.info("Finished.") return 0