def add_assets(self) -> None: ''' Backup input and output files in metadata (including snap files). ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.snap_input)) metadata.add_asset(metadata.FileAsset(self.snap_output))
def _add_container_metadata(self) -> None: ''' Adds container metadata to run metadata assets. ''' logger.emlog('# Looking for container metadata...') # Skip any image activators that do not have build metadata. if not cntrimg.activator().requires_img_activation(): iact = self.args.image_activator logger.log(F'# Note: the {iact} activator has no metadata\n') return imgdir = self.inflated_cntrimg_path # The subdirectory where container metadata are stored. buildl = os.path.join( imgdir, constants.METADATA_DIR, constants.SERVICE_LOG_NAME ) # Don't error out if the image doesn't have our metadata. if not os.path.exists(buildl): logger.log('# Note: container image provides no metadata\n') return logger.log(F'# Adding metadata from {imgdir}\n') mdatadir = 'container' metadata.add_asset(metadata.FileAsset(buildl, mdatadir))
def main(argv): # Name the experiment. experiment.name('test-shellcmds') fname = 'afile.txt' logger.log('# Testing globbing...') shargs = {'echo': True} # Wildcards don't need to be escaped with a `\' or quoted to protect them # from expansion by the host. We take care of that for you. container.run('ls *') # host and container interfaces should behave as identically as possible. host.run('ls *', **shargs) logger.emlog('# Testing redirection...') logger.log(F'# Adding text to {fname}:') host.run(F'echo "Some Text" | tee {fname}', **shargs) host.run(F'echo "More \'Text\'" >> {fname}', **shargs) logger.emlog(F'# The contents of {fname} are:') host.run(F'cat {fname}', **shargs) logger.emlog('# Testing quoting...') container.run('echo "Some \'Text\'"') logger.emlog('# Testing command chaining...') container.run('true && echo true!') container.run('false || echo false is good && echo true is good') logger.emlog('# Testing variable lifetimes within chained commands...') container.run('export FOO="bar" && ' 'test ! -z $FOO && ' 'echo "Looks good!" || ' 'exit 1') metadata.add_asset(metadata.FileAsset(fname))
def main(argv): # Name the experiment. experiment.name('test-shellcmds') fname = 'afile.txt' logger.log('# Testing globbing...') shargs = {'echo': True} # Wildcards need to be escaped with a `\' or quoted to protect them from # expansion by the host. container.run('ls \\*') # shell and container interfaces should behave as identically as possible. host.run('ls \\*', **shargs) logger.emlog('# Testing redirection...') logger.log(F'# Adding text to {fname}:') container.run(F'echo "Some Text" | tee {fname}') container.run(F'echo "More \'Text\'" >> {fname}') logger.emlog(F'# The contents of {fname} are:') host.run(F'cat {fname}', **shargs) logger.emlog('# Testing quoting...') container.run('echo "Some \'Text\'"') logger.emlog('# Testing command chaining...') container.run('true && echo true!') container.run('false || echo false... && echo and done!') metadata.add_asset(metadata.FileAsset(fname))
def _emit_build_spec(self) -> None: dockerf = self.config['spec'] # Add spec file to the metadata assets. metadata.add_asset(metadata.FileAsset(dockerf)) # Emit the contents of the spec file. logger.log('# Begin Spec Output') logger.log(utils.chomp(str().join(utils.cat(dockerf)))) logger.log('# End Spec Output')
def main(argv): logger.log('adding a file asset...') metadata.add_asset(metadata.FileAsset('some-metadata.txt')) logger.log('adding a yaml dict asset...') adict = dict() adict['Application'] = {'argv': argv} adict['System'] = {'whoami': host.whoami(), 'hostname': host.hostname()} metadata.add_asset(metadata.YAMLDictAsset(adict, 'yaml-metadata'))
def main(argv): logger.log('adding a file asset...') # adds an arbitrary metadata file to a subfolder: custom metadata.add_asset( metadata.FileAsset('some-metadata.txt', 'subdir-a/subdir-b')) logger.log('adding a yaml dict asset...') adict = dict() # collect metadata adict['Application'] = {'argv': argv} adict['System'] = {'whoami': host.whoami(), 'hostname': host.hostname()} # save metadata to file metadata.add_asset(metadata.YAMLDictAsset(adict, 'yaml-metadata'))
def run(argv: List[str]) -> None: ''' Loads and executes the run program specified at argv[0], passing along all program-specific arguments to the program (argv). ''' argz = argv[0] # Stash the program. metadata.add_asset(metadata.FileAsset(argz)) # Import and run the specified program. argz passed twice for nicer # error messages when a user specifies a bogus program. spec = importlib.util.spec_from_file_location(argz, argz) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) # Save cwd so we can restore it after program execution. scwd = os.getcwd() try: # What's the specified program's cwd? pbase = os.path.dirname(argz) # cddir to base of given program so relative operations work # properly. os.chdir(pbase) mod.main(argv) finally: os.chdir(scwd)
def add_assets(self) -> None: ''' Backup metadata assets ''' metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self): metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self): if not utils.emptystr(self.config.args.input): metadata.add_asset(metadata.FileAsset(self.config.args.input))
def add_assets(self) -> None: ''' Backup input and output files in metadata ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.config.args.bransonfile))
def add_assets(self) -> None: ''' Select additional assets to copy ''' metadata.add_asset(metadata.FileAsset(self.config.args.input)) metadata.add_asset(metadata.FileAsset(self.pinfile))