def main(): argument_spec = mso_argument_spec() argument_spec.update( state=dict(type='str', default='query', choices=['query']) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True ) mso = MSOModule(module) path = 'platform/version' # Query for mso.existing object mso.existing = mso.query_obj(path) mso.exit_json()
def main(): argument_spec = mso_argument_spec() argument_spec.update( source_schema=dict(type='str'), destination_schema=dict(type='str'), state=dict(type='str', default='clone', choices=['clone']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'clone', ['destination_schema']], ], ) source_schema = module.params.get('source_schema') destination_schema = module.params.get('destination_schema') state = module.params.get('state') mso = MSOModule(module) # Get source schema details source_schema_path = "schemas/{0}".format(mso.lookup_schema(source_schema)) source_schema_obj = mso.query_obj(source_schema_path, displayName=source_schema) source_data = source_schema_obj.get('templates') source_data = json.loads( json.dumps(source_data).replace('/{0}'.format(source_schema_path), '')) path = 'schemas' # Check if source and destination schema are named differently if source_schema == destination_schema: mso.fail_json( msg="Source and Destination schema cannot have same names.") # Query for existing object(s) if destination_schema: mso.existing = mso.get_obj(path, displayName=destination_schema) if mso.existing: mso.fail_json( msg= "Schema with the name '{0}' already exists. Please use another name." .format(destination_schema)) if state == 'clone': mso.previous = mso.existing payload = dict( displayName=destination_schema, templates=source_data, ) mso.sanitize(payload, collate=True) if not mso.existing: if module.check_mode: mso.existing = mso.proposed else: mso.existing = mso.request(path, method='POST', data=mso.sent) mso.exit_json()