def creatoropts(args): 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 not 'record_pkgs' in creatoropts: creatoropts['record_pkgs'] = [] if creatoropts['release'] is not None: if 'name' not in creatoropts['record_pkgs']: creatoropts['record_pkgs'].append('name') ksconf = misc.normalize_ksfile(ksconf, creatoropts['tokenmap']) 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').items(): if key == creatoropts['pkgmgr']: pkgmgr = pcls break if not pkgmgr: pkgmgrs = list(pluginmgr.get_plugins('backend').keys()) raise errors.CreatorError( "Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) creatoropts['pkgmgr_pcls'] = pkgmgr if creatoropts['runtime']: rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None) # Write the normalized kickstart to outdir # It has to be done this way in case the source ks is same as dest ks mkdir_p(creatoropts['outdir']) dst_ks = "%s/%s.ks" % (creatoropts['outdir'], creatoropts['name']) with open(configmgr._ksconf, 'r') as src_ksf: src_ks = src_ksf.read() with open(dst_ks, 'w') as dst_ksf: dst_ksf.write(src_ks) creatoropts['dst_ks'] = dst_ks return creatoropts
def creatoropts(args): 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 not 'record_pkgs' in creatoropts: creatoropts['record_pkgs'] = [] if creatoropts['release'] is not None: if 'name' not in creatoropts['record_pkgs']: creatoropts['record_pkgs'].append('name') ksconf = misc.normalize_ksfile(ksconf, creatoropts['tokenmap']) 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))) creatoropts['pkgmgr_pcls'] = pkgmgr if creatoropts['runtime']: rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None) # Write the normalized kickstart to outdir # It has to be done this way in case the source ks is same as dest ks mkdir_p(creatoropts['outdir']) dst_ks = "%s/%s.ks" % (creatoropts['outdir'], creatoropts['name']) with open(configmgr._ksconf, 'r') as src_ksf: src_ks = src_ksf.read() with open(dst_ks, 'w') as dst_ksf: dst_ksf.write(src_ks) creatoropts['dst_ks'] = dst_ks return creatoropts
def do_create(self, subcmd, opts, *args): """${cmd_name}: create raw 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) 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 = raw.RawImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs if creatoropts['release'] is None: for item in creator.get_diskinfo(): imagefile = "%s-%s.raw" % (os.path.join( creator.destdir, creator.name), item['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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create fs 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) 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 = fs.FsImageCreator(creatoropts, pkgmgr) creator._include_src = opts.include_src if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs if creatoropts['release'] is None: fsdir = os.path.join(creator.destdir, creator.name) if os.path.exists(fsdir): if msger.ask('The target dir: %s already exists, cleanup and continue?' % fsdir): import shutil shutil.rmtree(fsdir) else: raise errors.Abort('Canceled') try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() #Download the source packages ###private options if opts.include_src: installed_pkgs = creator.get_installed_packages() msger.info('--------------------------------------------------') msger.info('Generating the image with source rpms included ...') if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]): msger.warning("Source packages can't be downloaded") 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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create loop 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) 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.normalize_ksfile(ksconf, creatoropts['release'], creatoropts['arch']) 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 = LoopImageCreator(creatoropts, pkgmgr, opts.compress_image, opts.shrink) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".img"], 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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create raw 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) 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 = raw.RawImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs if creatoropts['release'] is None: for item in creator.get_diskinfo(): imagefile = "%s-%s.raw" % (os.path.join(creator.destdir, creator.name), item['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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create loop 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) 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.normalize_ksfile(ksconf, creatoropts['release'], creatoropts['arch']) 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 = LoopImageCreator(creatoropts, pkgmgr, opts.compress_image, opts.shrink) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".img"], 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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create liveusb 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("liveusb 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.normalize_ksfile(ksconf, creatoropts["release"], creatoropts["arch"]) 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 = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs self.check_image_exists(creator.destdir, creator.pack_to, [creator.name + ".usbimg"], 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
def do_create(self, subcmd, opts, *args): """${cmd_name}: create fs 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) 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 = fs.FsImageCreator(creatoropts, pkgmgr) creator._include_src = opts.include_src if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs if creatoropts['release'] is None: fsdir = os.path.join(creator.destdir, creator.name) if os.path.exists(fsdir): if msger.ask( 'The target dir: %s already exists, cleanup and continue?' % fsdir): import shutil shutil.rmtree(fsdir) else: raise errors.Abort('Canceled') try: creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) creator.install() #Download the source packages ###private options if opts.include_src: installed_pkgs = creator.get_installed_packages() msger.info( '--------------------------------------------------') msger.info( 'Generating the image with source rpms included, The number of source packages is %d.' % (len(installed_pkgs))) if not misc.SrcpkgsDownload( installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]): msger.warning("Source packages can't be downloaded") 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