def main(): """Main function which manages plugin behavior""" pdc_arguments = { "component-nvr": { "type": "str", 'required': True }, "pdc-api-url": { "type": "str", 'required': True }, "ca-cert": { "type": "str", 'default': '/etc/ssl/certs/ca-bundle.crt' }, "output": { "type": "str", "default": "metamorph.json" } } setup_logging(default_path="metamorph/etc/logging.json") module = AnsibleModule(argument_spec=pdc_arguments) client = PDCApi(module.params['pdc-api-url'], module.params['ca-cert'], module.params['component-nvr']) pdc_metadata = client.get_pdc_metadata_by_component_name() client.write_json_file(dict(pdc=dict(results=pdc_metadata)), module.params['output']) module.exit_json(changed=True, meta=dict(pdc=pdc_metadata))
def main(): """Main function which manages plugin behavior""" extractor_args = { "ci-message": { "type": "str", "required": True }, "output": { "type": "str", "default": "metamorph.json" } } setup_logging(default_path="etc/logging.json") module = AnsibleModule(argument_spec=extractor_args) data_extractor = MessageDataExtractor(module.params['ci-message']) ci_message_data = {} try: ci_message_data = data_extractor.get_ci_message_data() except CIMessageKeyValueException or CIMessageReadingException as detail: module.fail_json(msg=detail) except Exception as detail: module.fail_json(msg=detail) data_extractor.write_json_file(dict(ci_message_data=ci_message_data), module.params['output']) module.exit_json(changed=True, meta=dict(ci_message_data=ci_message_data))
def main(): """Main function which manages plugin behavior""" argument_spec = dict(job_names=dict(type='list', nargs='*'), resultsdb_api_url=dict(required=True, type='str'), nvr=dict(type='str'), ci_message=dict(type='str'), env_variable=dict(type='str'), test_tier=dict(type='int', required=True), output=dict(default='metamorph.json', type='str'), ca_bundle=dict(default='/etc/ssl/certs/ca-bundle.crt', type='str')) mutually_exclusive = [ ['nvr', 'ci_message'], ['nvr', 'env_variable'], ['ci_message', 'env_variable'], ] setup_logging(default_path="./etc/logging.json") module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive) if not (module.params['nvr'] or module.params['ci_message'] or module.params['env_variable']): module.fail_json(msg="Error in argument parsing. " "One of (nvr, ci_message, env_variable) is required") get_nvr_information(module) resultsdb = ResultsDBApi(module.params['job_names'], module.params['nvr'], module.params['test_tier'], module.params['resultsdb_api_url'], module.params['ca_bundle']) resultsdb.get_test_tier_status_metadata() result = resultsdb.format_result() resultsdb.write_json_file(dict(resultsDB=result), module.params['output']) module.exit_json(changed=True, meta=dict(result))
def main(): """Main function which manages plugin behavior""" setup_logging(default_path="metamorph/etc/logging.json") args = parse_args() try: ci_message = args.func(args) MetamorphPlugin.write_json_file(dict(ci_message=ci_message), args.output) except Exception as exc: if "\'Namespace\' object has no attribute \'func\'".startswith( exc.__str__()): logging.warning( "You need to specify input. Please run: \"morph_messagehub.py --help\" " "for more information") try: if args.env_variable: logging.error( "ERROR during parsing json data from environmental variable. " "Please check provided data or given environmental variable itself." ) except AttributeError: logging.error( "Error with function parsing. If this is a bug make an issue in " "github repo.\n Message: {0}".format(exc)) exit(1)
def main(): """Main function which manages plugin behavior""" setup_logging(default_path="metamorph/etc/logging.json") args = parse_args() client = PDCApi(args.pdc_api_url, args.ca_cert, args.component_nvr) pdc_metadata = client.get_pdc_metadata_by_component_name() client.write_json_file(dict(pdc=dict(results=pdc_metadata)), args.output)
def main(): """Main function which manages plugin behavior""" setup_logging(default_path="etc/logging.json") args = parse_args() data_extractor = MessageDataExtractor(args.ci_message) ci_message_data = data_extractor.get_ci_message_data() data_extractor.write_json_file(dict(ci_message_data=ci_message_data), args.output)
def main(): """Main function which manages plugin behavior""" setup_logging(default_path="metamorph/etc/logging.json") logging.captureWarnings(True) args = parse_args() get_nvr_information(args) resultsdb = ResultsDBApi(args.job_names, args.nvr, args.test_tier, args.resultsdb_api_url, args.ca_bundle) resultsdb.get_test_tier_status_metadata() result = resultsdb.format_result() resultsdb.write_json_file(dict(resultsDB=result), args.output)
def main(): """Main function which manages plugin behavior""" setup_logging(default_path="metamorph/etc/logging.json") logging.captureWarnings(True) args = parse_args() if args.metadata_file and not args.metadata_loc: raise ArgumentError( None, "Argument error: '--metadata-file' " "must be provided with '--metadata-loc' argument") elif not args.metadata_file and args.metadata_loc: raise ArgumentError( None, "Argument error: '--metadata-loc' " "must be provided with '--metadata-file' argument") if args.metadata_file: # Metadata location data must be setup_metadata_location_param(args) provisioning = Provision(args.git_repo, args.metadata_file, args.metadata_loc, args.osp_config, args.topology_credentials_name) topology, topology_credentials = provisioning.get_provision_metadata() provisioning.write_yaml_file(topology, args.output_topology) provisioning.write_yaml_file(topology_credentials, provisioning.credentials_name)
def main(): """Main function which manages plugin behavior""" messagebus = { "user": { "type": "str" }, "password": { "type": "str" }, "selector": { "type": "str" }, "host": { "type": "str" }, "port": { "default": 61613, "type": "int" }, "destination": { "default": '/topic/CI', "type": "str" }, "count": { "default": 1, "type": "int" }, "env-variable": { "type": "str" }, "output": { "type": "str", "default": "metamorph.json" } } mutually_exclusive = [['env-variable', 'user'], ['env-variable', 'password'], ['env-variable', 'selector'], ['env-variable', 'host'], ['env-variable', 'port'], ['env-variable', 'destination'], ['env-variable', 'count']] setup_logging(default_path="metamorph/etc/logging.json") module = AnsibleModule(argument_spec=messagebus, mutually_exclusive=mutually_exclusive) error_message = "" ci_message = "" if module.params['env-variable']: ci_message = os.environ.get(module.params['env-variable'], "UNKNOWN") if ci_message == "UNKNOWN": logging.error("Environmental variable not found") error_message = "Environmental variable not found" # Need to erase \n in given message. They will cause parsing errors otherwise. try: ci_message = json.loads(ci_message.replace('\\n', '')) except ValueError as detail: module.fail_json( msg= "Error occurred during json parsing from given environmental " "variable. See detail: '{}'".format(detail)) elif not (module.params['user'] and module.params['password'] and module.params['host']): module.fail_json(msg="Error in argument parsing. Arguments: user, " "password and host are required") else: error_message, ci_message = messagebus_run(module) if not error_message: MetamorphPlugin.write_json_file(ci_message, module.params['output']) module.exit_json(changed=True, meta=dict(ci_message=ci_message)) else: module.fail_json(msg="Error occurred in processing CI Message.", meta=error_message)