def execute(self, initvmdir, opt, args): # pylint: disable=too-many-branches # pylint: disable=too-many-statements if self.initvm is not None: print("Initvm is already defined for the libvirt domain '%s'.\n" % cfg['initvm_domain']) print("If you want to build in your old initvm, " "use `elbe initvm submit <xml>`.") print("If you want to remove your old initvm from libvirt " "run `virsh --connect qemu:///system undefine %s`.\n" % cfg['initvm_domain']) print( "You can specify another libvirt domain by setting the " "ELBE_INITVM_DOMAIN environment variable to an unused domain name.\n" ) print("Note:") print("\t1) You can reimport your old initvm via " "`virsh --connect qemu:///system define <file>`") print("\t where <file> is the corresponding libvirt.xml") print( "\t2) virsh --connect qemu:///system undefine does not delete the image " "of your old initvm.") sys.exit(20) # Upgrade from older versions which used tmux try: system("tmux has-session -t ElbeInitVMSession 2>/dev/null") print( "ElbeInitVMSession exists in tmux. " "It may belong to an old elbe version. " "Please stop it to prevent interfering with this version.", file=sys.stderr) sys.exit(20) except CommandError: pass # Init cdrom to None, if we detect it, we set it cdrom = None if len(args) == 1: if args[0].endswith('.xml'): # We have an xml file, use that for elbe init xmlfile = args[0] try: xml = etree(xmlfile) except ValidationError as e: print("XML file is invalid: %s" % str(e)) # Use default XML if no initvm was specified if not xml.has("initvm"): xmlfile = os.path.join(elbepack.__path__[0], "init/default-init.xml") elif args[0].endswith('.iso'): # We have an iso image, extract xml from there. tmp = extract_cdrom(args[0]) xmlfile = tmp.fname('source.xml') cdrom = args[0] else: print("Unknown file ending (use either xml or iso)", file=sys.stderr) sys.exit(20) else: # No xml File was specified, build the default elbe-init-with-ssh xmlfile = os.path.join(elbepack.__path__[0], "init/default-init.xml") try: init_opts = '' if opt.devel: init_opts += ' --devel' if opt.nesting: init_opts += ' --nesting' if not opt.build_bin: init_opts += ' --skip-build-bin' if not opt.build_sources: init_opts += ' --skip-build-source' with PreprocessWrapper(xmlfile, opt) as ppw: if cdrom: system( '%s init %s --directory "%s" --cdrom "%s" "%s"' % (elbe_exe, init_opts, initvmdir, cdrom, ppw.preproc)) else: system('%s init %s --directory "%s" "%s"' % (elbe_exe, init_opts, initvmdir, ppw.preproc)) except CommandError: print("'elbe init' Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) # Read xml file for libvirt with open(os.path.join(initvmdir, 'libvirt.xml')) as f: xml = f.read() # Register initvm in libvirt try: self.conn.defineXML(xml) except CommandError: print('Registering initvm in libvirt failed', file=sys.stderr) print( 'Try `virsh --connect qemu:///system undefine %s` to delete existing initvm' % cfg['initvm_domain'], file=sys.stderr) sys.exit(20) # Build initvm try: system('cd "%s"; make' % (initvmdir)) except CommandError: print("Building the initvm Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) try: system('%s initvm start' % elbe_exe) except CommandError: print("Starting the initvm Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) if len(args) == 1: # if provided xml file has no initvm section xmlfile is set to a # default initvm XML file. But we need the original file here if args[0].endswith('.xml'): # stop here if no project node was specified try: x = etree(args[0]) except ValidationError as e: print("XML file is invalid: %s" % str(e)) sys.exit(20) if not x.has('project'): print("elbe initvm ready: use 'elbe initvm submit " "myproject.xml' to build a project") sys.exit(0) xmlfile = args[0] elif cdrom is not None: xmlfile = tmp.fname('source.xml') submit_and_dl_result(xmlfile, cdrom, opt)
def run_command(argv): oparser = OptionParser(usage="usage: elbe initvm [options] <command>") oparser.add_option( "--directory", dest="directory", default=None, help="directory, where the initvm resides, default is ./initvm") oparser.add_option("--cdrom", dest="cdrom", default=None, help="iso image of Binary cdrom") oparser.add_option( "--devel", action="store_true", dest="devel", default=False, help="Install elbe Version from the current working into initvm") oparser.add_option("--skip-download", action="store_true", dest="skip_download", default=False, help="Skip downloading generated Files") oparser.add_option("--output", dest="outdir", default=None, help="directory where to save downloaded Files") oparser.add_option( "--skip-build-bin", action="store_false", dest="build_bin", default=True, help="Skip building Binary Repository CDROM, for exact Reproduction") oparser.add_option("--skip-build-sources", action="store_false", dest="build_sources", default=True, help="Skip building Source CDROM") oparser.add_option("--keep-files", action="store_true", dest="keep_files", default=False, help="don't delete elbe project files in initvm") oparser.add_option("--writeproject", dest="writeproject", default=None, help="write project name to file") oparser.add_option( "--nesting", dest="nesting", action="store_true", default=False, help="allow initvm to support nested kvm. " "This makes /proc/cpuinfo inside initvm differ per host.") oparser.add_option( "--build-sdk", dest="build_sdk", action="store_true", default=False, help="Also make 'initvm submit' build an SDK.") PreprocessWrapper.add_options(oparser) (opt, args) = oparser.parse_args(argv) if len(args) < 1: print("elbe initvm - no subcommand given", file=sys.stderr) InitVMAction.print_actions() sys.exit(20) directory = opt.directory or os.getcwd() + '/initvm' # Use absolute Path directory = os.path.abspath(directory) try: action = InitVMAction(args[0]) except KeyError: print("elbe initvm - unknown subcommand", file=sys.stderr) InitVMAction.print_actions() sys.exit(20) try: action.execute(directory, opt, args[1:]) except InitVMError as e: print("InitVM Exception", file=sys.stderr) print(e, file=sys.stderr) sys.exit(5)
def submit_and_dl_result(xmlfile, cdrom, opt): # pylint: disable=too-many-statements # pylint: disable=too-many-branches try: with PreprocessWrapper(xmlfile, opt) as ppw: xmlfile = ppw.preproc ret, prjdir, err = command_out_stderr('%s control create_project' % (elbe_exe)) if ret != 0: print("elbe control create_project failed.", file=sys.stderr) print(err, file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) prjdir = prjdir.strip() cmd = '%s control set_xml %s %s' % (elbe_exe, prjdir, xmlfile) ret, _, err = command_out_stderr(cmd) if ret != 0: print("elbe control set_xml failed2", file=sys.stderr) print(err, file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) except CommandError: # this is the failure from PreprocessWrapper # it already printed the error message from # elbe preprocess print("Giving up", file=sys.stderr) sys.exit(20) if opt.writeproject: with open(opt.writeproject, "w") as wpf: wpf.write(prjdir) if cdrom is not None: print("Uploading CDROM. This might take a while") try: system('%s control set_cdrom "%s" "%s"' % (elbe_exe, prjdir, cdrom)) except CommandError: print("elbe control set_cdrom Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) print("Upload finished") build_opts = '' if opt.build_bin: build_opts += '--build-bin ' if opt.build_sources: build_opts += '--build-sources ' if cdrom: build_opts += '--skip-pbuilder ' try: system('%s control build "%s" %s' % (elbe_exe, prjdir, build_opts)) except CommandError: print("elbe control build Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) print("Build started, waiting till it finishes") try: system('%s control wait_busy "%s"' % (elbe_exe, prjdir)) except CommandError: print('elbe control wait_busy Failed', file=sys.stderr) print('', file=sys.stderr) print('The project will not be deleted from the initvm.', file=sys.stderr) print('The files, that have been built, can be downloaded using:', file=sys.stderr) print('%s control get_files --output "%s" "%s"' % (elbe_exe, opt.outdir, prjdir), file=sys.stderr) print("", file=sys.stderr) print('The project can then be removed using:', file=sys.stderr) print('%s control del_project "%s"' % (elbe_exe, prjdir), file=sys.stderr) print("", file=sys.stderr) sys.exit(10) print("") print("Build finished !") print("") if opt.build_sdk: try: system('%s control build_sdk "%s" %s' % (elbe_exe, prjdir, build_opts)) except CommandError: print("elbe control build_sdk Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) print("SDK Build started, waiting till it finishes") try: system('%s control wait_busy "%s"' % (elbe_exe, prjdir)) except CommandError: print('elbe control wait_busy Failed, while waiting for the SDK', file=sys.stderr) print('', file=sys.stderr) print('The project will not be deleted from the initvm.', file=sys.stderr) print('The files, that have been built, can be downloaded using:', file=sys.stderr) print('%s control get_files --output "%s" "%s"' % (elbe_exe, opt.outdir, prjdir), file=sys.stderr) print("", file=sys.stderr) print('The project can then be removed using:', file=sys.stderr) print('%s control del_project "%s"' % (elbe_exe, prjdir), file=sys.stderr) print("", file=sys.stderr) sys.exit(10) print("") print("SDK Build finished !") print("") try: system('%s control dump_file "%s" validation.txt' % (elbe_exe, prjdir)) except CommandError: print("Project failed to generate validation.txt", file=sys.stderr) print("Getting log.txt", file=sys.stderr) try: system('%s control dump_file "%s" log.txt' % (elbe_exe, prjdir)) except CommandError: print("Failed to dump log.txt", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) if opt.skip_download: print("") print("Listing available files:") print("") try: system('%s control get_files "%s"' % (elbe_exe, prjdir)) except CommandError: print("elbe control get_files Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) print("") print('Get Files with: elbe control get_file "%s" <filename>' % prjdir) else: print("") print("Getting generated Files") print("") ensure_outdir(opt) try: system('%s control get_files --output "%s" "%s"' % (elbe_exe, opt.outdir, prjdir)) except CommandError: print("elbe control get_files Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) if not opt.keep_files: try: system('%s control del_project "%s"' % (elbe_exe, prjdir)) except CommandError: print("remove project from initvm failed", file=sys.stderr) sys.exit(20)
def execute(self, opt, _args): crossopt = "" if opt.cross: crossopt = "--cross" if opt.noccache: ccacheopt = "--no-ccache" ccachesize = "" else: ccacheopt = "--ccache-size" ccachesize = opt.ccachesize if opt.xmlfile: try: with PreprocessWrapper(opt.xmlfile, opt) as ppw: ret, prjdir, err = command_out_stderr( '%s control create_project' % (elbe_exe)) if ret != 0: print("elbe control create_project failed.", file=sys.stderr) print(err, file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) prjdir = prjdir.strip() ret, _, err = command_out_stderr( '%s control set_xml "%s" "%s"' % (elbe_exe, prjdir, ppw.preproc)) if ret != 0: print("elbe control set_xml failed.", file=sys.stderr) print(err, file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) except CommandError: # this is the failure from PreprocessWrapper # it already printed the error message from # elbe preprocess print("Giving up", file=sys.stderr) sys.exit(20) if opt.writeproject: wpf = open(opt.writeproject, "w") wpf.write(prjdir) wpf.close() elif opt.project: prjdir = opt.project else: print("you need to specify --project option", file=sys.stderr) sys.exit(20) print("Creating pbuilder") try: system('%s control build_pbuilder "%s" %s %s %s' % (elbe_exe, prjdir, crossopt, ccacheopt, ccachesize)) except CommandError: print("elbe control build_pbuilder Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) try: system('%s control wait_busy "%s"' % (elbe_exe, prjdir)) except CommandError: print("elbe control wait_busy Failed", file=sys.stderr) print("Giving up", file=sys.stderr) sys.exit(20) print("") print("Building Pbuilder finished !") print("")
def run_command(argv): oparser = OptionParser(usage="usage: elbe pbuilder [options] <command>") oparser.add_option("--project", dest="project", default=None, help="project directory on the initvm") oparser.add_option("--xmlfile", dest="xmlfile", default=None, help="xmlfile to use") oparser.add_option("--writeproject", dest="writeproject", default=None, help="write project name to file") oparser.add_option("--skip-download", action="store_true", dest="skip_download", default=False, help="Skip downloading generated Files") oparser.add_option("--origfile", dest="origfile", default=[], action="append", help="upload orig file") oparser.add_option("--output", dest="outdir", default=None, help="directory where to save downloaded Files") oparser.add_option("--cpuset", default=-1, type="int", help="Limit cpuset of pbuilder commands (bitmask) " "(defaults to -1 for all CPUs)") oparser.add_option("--profile", dest="profile", default="", help="profile that shall be built") PreprocessWrapper.add_options(oparser) (opt, args) = oparser.parse_args(argv) if len(args) < 1: print("elbe pbuilder - no subcommand given", file=sys.stderr) PBuilderAction.print_actions() return try: action = PBuilderAction(args[0]) except KeyError: print("elbe pbuilder - unknown subcommand", file=sys.stderr) PBuilderAction.print_actions() sys.exit(20) try: action.execute(opt, args[1:]) except PBuilderError as e: print("PBuilder Exception", file=sys.stderr) print(e, file=sys.stderr) sys.exit(5)
def run_command(argv): oparser = OptionParser(usage="usage: elbe pbuilder [options] <command>") oparser.add_option("--project", dest="project", default=None, help="project directory on the initvm") oparser.add_option("--xmlfile", dest="xmlfile", default=None, help="xmlfile to use") oparser.add_option("--writeproject", dest="writeproject", default=None, help="write project name to file") oparser.add_option("--skip-download", action="store_true", dest="skip_download", default=False, help="Skip downloading generated Files") oparser.add_option("--origfile", dest="origfile", default=[], action="append", help="upload orig file") oparser.add_option("--output", dest="outdir", default=None, help="directory where to save downloaded Files") oparser.add_option("--cpuset", default=-1, type="int", help="Limit cpuset of pbuilder commands (bitmask) " "(defaults to -1 for all CPUs)") oparser.add_option("--profile", dest="profile", default="", help="profile that shall be built") oparser.add_option("--cross", dest="cross", default=False, action="store_true", help="Creates an environment for crossbuilding if " "combined with create. Combined with build it" " will use this environment.") oparser.add_option("--no-ccache", dest="noccache", default=False, action="store_true", help="Deactivates the compiler cache 'ccache'") oparser.add_option("--ccache-size", dest="ccachesize", default="10G", action="store", type="string", help="set a limit for the compiler cache size " "(should be a number followed by an optional " "suffix: k, M, G, T. Use 0 for no limit.)") PreprocessWrapper.add_options(oparser) (opt, args) = oparser.parse_args(argv) if len(args) < 1: print("elbe pbuilder - no subcommand given", file=sys.stderr) PBuilderAction.print_actions() return try: action = PBuilderAction(args[0]) except KeyError: print("elbe pbuilder - unknown subcommand", file=sys.stderr) PBuilderAction.print_actions() sys.exit(20) try: action.execute(opt, args[1:]) except PBuilderError as e: print("PBuilder Exception", file=sys.stderr) print(e, file=sys.stderr) sys.exit(5)
def run_command(argv): oparser = OptionParser(usage="usage: elbe initvm [options] <command>") oparser.add_option( "--directory", dest="directory", default=None, help="directory, where the initvm resides, default is ./initvm") oparser.add_option("--cdrom", dest="cdrom", default=None, help="iso image of Binary cdrom") oparser.add_option( "--devel", action="store_true", dest="devel", default=False, help="Install elbe Version from the current working into initvm") oparser.add_option("--skip-download", action="store_true", dest="skip_download", default=False, help="Skip downloading generated Files") oparser.add_option("--output", dest="outdir", default=None, help="directory where to save downloaded Files") oparser.add_option( "--skip-build-bin", action="store_false", dest="build_bin", default=True, help="Skip building Binary Repository CDROM, for exact Reproduction") oparser.add_option("--skip-build-sources", action="store_false", dest="build_sources", default=True, help="Skip building Source CDROM") oparser.add_option("--keep-files", action="store_true", dest="keep_files", default=False, help="don't delete elbe project files in initvm") oparser.add_option("--writeproject", dest="writeproject", default=None, help="write project name to file") oparser.add_option( "--nesting", dest="nesting", action="store_true", default=False, help="allow initvm to support nested kvm. " "This makes /proc/cpuinfo inside initvm differ per host.") PreprocessWrapper.add_options(oparser) (opt, args) = oparser.parse_args(argv) if len(args) < 1: print("elbe initvm - no subcommand given", file=sys.stderr) InitVMAction.print_actions() sys.exit(20) directory = opt.directory or os.getcwd() + '/initvm' # Use absolute Path directory = os.path.abspath(directory) try: action = InitVMAction(args[0]) except KeyError: print("elbe initvm - unknown subcommand", file=sys.stderr) InitVMAction.print_actions() sys.exit(20) try: action.execute(directory, opt, args[1:]) except InitVMError as e: print("InitVM Exception", file=sys.stderr) print(e, file=sys.stderr) sys.exit(5)