def cmd_build(ctx, verbose_build=False, fetch=True, prepare=True, progress=True, target=None, fast=False, force_build=False): """ Builds the Unikraft application for the target architecture and platform. """ kraft_list_preflight() try: kraft_build(workdir=ctx.obj.workdir, verbose=verbose_build, fetch=fetch, prepare=prepare, progress=progress, target=target, fast=fast, force_build=force_build) except Exception as e: logger.critical(str(e)) if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1)
def cmd_prepare(ctx): """ Prepares """ kraft_list_preflight() try: kraft_prepare(workdir=ctx.obj.workdir) except Exception as e: logger.critical(str(e)) if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1)
def cmd_configure(ctx, target=None, plat=None, arch=None, force_configure=False, show_menuconfig=False, workdir=None, yes=[], no=[], opts=[], use_versions=[]): """ Configure the unikernel using the KConfig options set in the kraft.yaml file. Alternatively, you can use the -k|--menuconfig flag to open the TUI to manually select the configuration for this unikernel. When the unikernel is configured, a .config file is written to the working directory with the selected KConfig options. """ kraft_list_preflight() if workdir is None: workdir = os.getcwd() options = list() for y in yes: if not y.startswith(KCONFIG): y = KCONFIG % y options.append(KCONFIG_EQ % (y, KCONFIG_Y)) for n in no: if not n.startswith(KCONFIG): n = KCONFIG % n if n in options: logger.critical( 'Cannot specify same option with multiple values: %s' % n) sys.exit(1) options.append(KCONFIG_EQ % (n, KCONFIG_N)) for o in opts: if not o.startswith(KCONFIG): o = KCONFIG % o if '=' not in o: logger.critical('Missing value for --set option: %s' % o) sys.exit(1) options.append(o) try: kraft_configure( env=ctx.obj.env, workdir=workdir, target=target, plat=plat, arch=arch, force_configure=force_configure, show_menuconfig=show_menuconfig, options=options, use_versions=use_versions, ) except MissingComponent as e: if force_configure is False: logger.warn(e) if force_configure or \ click.confirm("Would you like to pull %s?" % e.component): # noqa try: kraft_list_pull(name=str(e.component), pull_dependencies=False, skip_app=True) except Exception: if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1) # Try to configure again ctx.forward(cmd_configure, force_configure=True) elif ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1) except Exception as e: logger.critical(str(e)) if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1)
def cmd_lib_bump(ctx, lib=None, version=None, bump_all=False, force_version=False, fast_forward=False, build=False): """ Update an existing Unikraft library's source origin version (experimental). If --fast-forward is specified, the library will be upgraded to the latest determined version. Otherwise, and by default, the bump will increment by the smallest possible version. """ kraft_list_preflight() try: if bump_all: for manifest_origin in ctx.obj.cache.all(): manifest = ctx.obj.cache.get(manifest_origin) for _, item in manifest.items(): if item.type != ComponentType.LIB.shortname: continue if not (ctx.obj.assume_yes or click.confirm("Bump %s?" % item.name)): continue kraft_download_via_manifest(manifest=item, use_git=True) kraft_lib_bump(workdir=item.localdir, force_version=force_version, fast_forward=fast_forward, build=build) elif lib is not None and os.path.isdir(lib): kraft_lib_bump( workdir=lib, version=version, force_version=force_version, fast_forward=fast_forward, ) elif lib is not None: manifests = maniest_from_name(lib) for manifest in manifests: if manifest.type != ComponentType.LIB.shortname: continue if len(manifests) > 0 and version is not None: logger.warn("Ignoring --version flag") for manifest in manifests: kraft_download_via_manifest(manifest=manifest, use_git=True) kraft_lib_bump( workdir=manifest.localdir, version=version if len(manifests) == 1 else None, force_version=force_version, fast_forward=fast_forward, build=build) else: kraft_lib_bump(workdir=os.getcwd(), version=version, force_version=force_version, fast_forward=fast_forward, build=build) except Exception as e: logger.error(e) if ctx.obj.verbose: import traceback logger.error(traceback.format_exc()) sys.exit(1)
def cmd_up(ctx, workdir=None, name=None, plat=None, arch=None, initrd=None, background=False, paused=False, gdb=4123, dbg=False, virtio_nic=None, bridge=None, interface=None, dry_run=False, memory=64, cpu_sockets=1, cpu_cores=1, force=False, fast=False, create_makefile=False, template_app=None): """ Configures, builds and runs an application for a selected architecture and platform. """ kraft_list_preflight() if workdir is None and name is None: appdir = os.getcwd() name = os.path.basename(appdir) elif workdir is None: appdir = os.path.join(os.getcwd(), name) elif name is None: appdir = workdir name = os.path.basename(appdir) if arch is None: arch = ctx.obj.settings.get(KRAFTRC_CONFIGURE_ARCHITECTURE) if plat is None: plat = ctx.obj.settings.get(KRAFTRC_CONFIGURE_PLATFORM) # Check if the directory is non-empty and prompt for validation if util.is_dir_empty(appdir) is False and ctx.obj.assume_yes is False: if click.confirm( '%s is a non-empty directory, would you like to continue?' % appdir): # noqa: E501 force = True else: logger.critical("Cannot create directory: %s" % appdir) sys.exit(1) try: kraft_list_pull(name=template_app, pull_dependencies=True) kraft_app_init(name=name, appdir=appdir, plat=plat, arch=arch, template_app=template_app, create_makefile=create_makefile, force_init=force) kraft_configure(env=ctx.obj.env, workdir=appdir, plat=plat, arch=arch, force_configure=force, show_menuconfig=False) kraft_build(workdir=appdir, fetch=True, prepare=True, fast=fast) kraft_run( appdir=appdir, plat=plat, arch=arch, initrd=initrd, background=background, paused=paused, dbg=dbg, gdb=gdb, virtio_nic=virtio_nic, bridge=bridge, interface=interface, dry_run=dry_run, # args=args, memory=memory, cpu_sockets=cpu_sockets, cpu_cores=cpu_cores, ) except Exception as e: logger.critical(str(e)) if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1)
def cmd_init(ctx, name=None, plat=None, arch=None, template_app=None, workdir=None, create_makefile=False, no_dependencies=False, dumps_local=False, force_init=False): """ Initializes a new unikraft application. Start here if this is your first time using (uni)kraft. """ kraft_list_preflight() # kraft's init permutations: # # $ kraft init => $(pwd) # $ kraft init my_app => $(pwd)/my_app # $ kraft -w /path/to/app init => /path/to/app # $ kraft -w /path/to/app init my_app => /path/to/app/my_app if workdir is None and name is None: appdir = os.getcwd() name = os.path.basename(appdir) elif workdir is None: appdir = os.path.join(os.getcwd(), name) elif name is None: appdir = workdir name = os.path.basename(appdir) if arch is None: arch = ctx.obj.settings.get(KRAFTRC_CONFIGURE_ARCHITECTURE) if plat is None: plat = ctx.obj.settings.get(KRAFTRC_CONFIGURE_PLATFORM) # Check if the directory is non-empty and prompt for validation if util.is_dir_empty(appdir) is False and ctx.obj.assume_yes is False: if click.confirm( '%s is a non-empty directory, would you like to continue?' % appdir): # noqa: E501 force_init = True else: logger.critical("Cannot create directory: %s" % appdir) sys.exit(1) try: kraft_app_init(name=name, appdir=appdir, plat=plat, arch=arch, template_app=template_app, create_makefile=create_makefile, force_init=force_init, pull_dependencies=not no_dependencies, dumps_local=dumps_local) except Exception as e: logger.critical(str(e)) if ctx.obj.verbose: import traceback logger.critical(traceback.format_exc()) sys.exit(1)