def main(): """main command handler""" parser = argparse.ArgumentParser(description='Prepare a cloud image from a virtual disk') parser.add_argument('-a', '--artifacts-dir', required=True, help='Absolute path to the artifacts directory') parser.add_argument('-c', '--check-name', action="store_true", help='Check cloud image name') parser.add_argument('-i', '--input', required=True, help='Absolute path to the input virtual disk') parser.add_argument('-p', '--platform', required=True, help='The cloud type (i.e. aws, gce, azure, alibaba)') parser.add_argument('-s', '--seed-image-name', default='', help='Use supplied autogenerated seed cloud image name') parser.add_argument('-u', '--user-image-name', default='', help='Use user-supplied cloud image name') args = parser.parse_args() # Check either seed or user cloud image name was provided if (args.seed_image_name == '' and args.user_image_name == '') or \ (args.seed_image_name != '' and args.user_image_name != ''): raise Exception('You must provide either --seed-image-name or --user-image-name') # create log handler for the global LOGGER create_log_handler() if args.check_name: # Check name if args.user_image_name == '': raise Exception('--check-name can only be used with --user-image-name') ImageController.check_valid_name(args.platform, args.user_image_name) else: result = False try: # Prepare image image_controller = ImageController(args.artifacts_dir, args.platform, args.input) image_controller.prepare(args.seed_image_name, args.user_image_name) # If execution came so far, all is well. result = True except RuntimeError as runtime_exce: LOGGER.exception(runtime_exce) finally: # Clean-up image controller and other internal constructs it created. image_controller.clean_up() if result is True: LOGGER.info("SUCCESS: Image generation completed.") else: LOGGER.warning("FAILURE: Check the log file '%s' and fix the problem " "before re-running.", get_config_value('LOG_FILE')) sys.exit(1) sys.exit(0)
def main(): """ Wrapper to read user defined values for LV sizes """ # create log handler for the global LOGGER create_log_handler() if len(sys.argv) != 2: LOGGER.error('%s received %s arguments, expected 1', basename(__file__), len(sys.argv) - 1) sys.exit(1) try: read_lv_sizes(sys.argv[1]) except RuntimeError as runtime_exception: LOGGER.exception(runtime_exception) sys.exit(1) sys.exit(0)
def main(): """main output json information file function""" # create log handler for the global LOGGER create_log_handler() output_path = sys.argv[1] # gather output json file info output_json_file = OutputJsonFile() LOGGER.info("Information in output file:") LOGGER.info(output_json_file.json_info) if (len(output_path) > 4 and output_path[-5:] == ".json"): output_json_file.set_output_path(output_path) else: output_json_file.set_output_path(output_path + "output_info.json") output_json_file.to_file() sys.exit(0)
def main(): """main read injected iles function""" # create log handler for the global LOGGER create_log_handler() if len(sys.argv) != 3: LOGGER.error('%s received %s arguments, expected 2', basename(__file__), len(sys.argv) - 1) sys.exit(1) try: read_injected_files(sys.argv[1], sys.argv[2]) except RuntimeError as runtime_exception: LOGGER.exception(runtime_exception) sys.exit(1) sys.exit(0)
def main(): """main publish telemetry information function""" # create log handler for the global LOGGER create_log_handler() # gather telemetry info build_info_telemetry = BuildInfoTelemetry() LOGGER.debug("telemetry info:") LOGGER.debug(build_info_telemetry.build_info) version = build_info_telemetry.build_info['product']['version'] # Check if specific api key is set, if not use default if environ.get("F5_TEEM_API_KEY") is not None: environ['F5_TEEM_API_ENVIRONMENT'] = "staging" f5_api_key = environ.get("F5_TEEM_API_KEY") else: f5_api_key = 'mmhJU2sCd63BznXAXDh4kxLIyfIMm3Ar' generated_uuid = str(uuid.uuid4()) LOGGER.debug("telemetry UUID: %s", generated_uuid) client_info = { 'name': 'f5-image-generator', 'version': str(version), 'id': generated_uuid } telemetry_client = AnonymousDeviceClient(client_info, api_key=f5_api_key) retrier = Retrier(_publish_telemetry_database, build_info_telemetry, telemetry_client) retrier.tries = int(get_config_value('PUBLISH_TELEMETRY_TASK_RETRY_COUNT')) retrier.delay = int(get_config_value('PUBLISH_TELEMETRY_TASK_RETRY_DELAY')) if retrier.execute(): LOGGER.info("Publishing to telemetry success.") return True LOGGER.info("Publishing to telemetry did not succeed.") sys.exit(0)
def main(): """main command handler""" parser = argparse.ArgumentParser( description='Output configuration variables to a file') parser.add_argument('-a', '--artifacts-dir', required=True, help='Absolute path to the artifacts directory') args = parser.parse_args() # create log handler for the global LOGGER create_log_handler() # gather config variable info config_vars = get_config_vars() # Dump alpha sorted file output_file = args.artifacts_dir + '/build_config.json' with open(output_file, 'w') as output_fp: json.dump(config_vars, output_fp, sort_keys=True, indent=4) LOGGER.info('Wrote config to: %s', output_file) sys.exit(0)