def create_app_catalog_subscription(compute_client, module): existing_app_catalog_subscription = get_app_catalog_subscription( compute_client, module) if existing_app_catalog_subscription: return dict(changed=False, app_catalog_subscription=existing_app_catalog_subscription) create_app_catalog_subscription_details = CreateAppCatalogSubscriptionDetails( ) for attr in six.iterkeys( create_app_catalog_subscription_details.swagger_types): setattr(create_app_catalog_subscription_details, attr, module.params.get(attr)) # sanitize time_retrieved parameter create_app_catalog_subscription_details.time_retrieved = _sanitize_time_retrieved( create_app_catalog_subscription_details.time_retrieved) oci_utils.to_dict( oci_utils.call_with_backoff( compute_client.create_app_catalog_subscription, create_app_catalog_subscription_details= create_app_catalog_subscription_details, ).data) app_catalog_subscription = get_app_catalog_subscription( compute_client, module) return dict(changed=True, app_catalog_subscription=app_catalog_subscription)
def create_app_catalog_subscription(compute_client, module): existing_app_catalog_subscription = get_app_catalog_subscription( compute_client, module) if existing_app_catalog_subscription: return dict(changed=False, app_catalog_subscription=existing_app_catalog_subscription) create_app_catalog_subscription_details = CreateAppCatalogSubscriptionDetails( ) for attr in create_app_catalog_subscription_details.swagger_types: setattr(create_app_catalog_subscription_details, attr, module.params.get(attr)) # The time retrieved passed to the ansible module as string. Convert to datetime. # If there is an error converting to date, pass the original string to the API. agreement_time_retrieved_as_date = oci_utils.parse_iso8601_str_as_datetime( create_app_catalog_subscription_details.time_retrieved) if agreement_time_retrieved_as_date: create_app_catalog_subscription_details.time_retrieved = ( agreement_time_retrieved_as_date) oci_utils.to_dict( oci_utils.call_with_backoff( compute_client.create_app_catalog_subscription, create_app_catalog_subscription_details= create_app_catalog_subscription_details, ).data) app_catalog_subscription = get_app_catalog_subscription( compute_client, module) return dict(changed=True, app_catalog_subscription=app_catalog_subscription)
def modify_rrset(dns_client, module, modify_operation, modify_kwargs): result = {} try: # get current rrset rrset_old = oci_utils.call_with_backoff( dns_client.get_rr_set, zone_name_or_id=get_zone_name_or_id(module), domain=module.params['domain'], rtype=module.params['rtype']).data.items # update rrset updated_rec_coll = oci_utils.call_with_backoff(modify_operation, **modify_kwargs).data result[RESOURCE_NAME] = oci_utils.to_dict(updated_rec_coll.items) # get rrset after update rrset_new = oci_utils.call_with_backoff( dns_client.get_rr_set, zone_name_or_id=get_zone_name_or_id(module), domain=module.params['domain'], rtype=module.params['rtype']).data.items # check if there is any change between the old and the new rrsets, and set changed accordingly result['changed'] = not oci_utils.compare_list(rrset_old, rrset_new) except ServiceError as ex: module.fail_json(msg=str(ex)) return result
def main(): module_args = oci_utils.get_common_arg_spec() module_args.update(dict(name=dict(type="str", required=False))) module = AnsibleModule(argument_spec=module_args, supports_check_mode=False) if not HAS_OCI_PY_SDK: module.fail_json(msg="oci python sdk required for this module.") result = dict(changed=False) resource_search_client = oci_utils.create_service_client( module, ResourceSearchClient) name = module.params.get("name") res_coll = None if name is not None: res_coll = [ oci_utils.call_with_backoff( resource_search_client.get_resource_type, name=name).data ] else: res_coll = oci_utils.call_with_backoff( resource_search_client.list_resource_types).data result["resource_types"] = oci_utils.to_dict(res_coll) module.exit_json(**result)
def modify_domain_records(dns_client, module, modify_operation, modify_kwargs): result = {} try: # get current domain records domain_records_old = oci_utils.call_with_backoff( dns_client.get_domain_records, zone_name_or_id=get_zone_name_or_id(module), domain=module.params["domain"], ).data.items # update domain records updated_rec_coll = oci_utils.call_with_backoff(modify_operation, **modify_kwargs).data result[RESOURCE_NAME] = oci_utils.to_dict(updated_rec_coll.items) # get domain records after update domain_records_new = oci_utils.call_with_backoff( dns_client.get_domain_records, zone_name_or_id=get_zone_name_or_id(module), domain=module.params["domain"], ).data.items # check if there is any change between the old and the new domain records, and set changed accordingly result["changed"] = not oci_utils.are_lists_equal( domain_records_old, domain_records_new) except ServiceError as ex: module.fail_json(msg=str(ex)) return result
def get_app_catalog_subscription(compute_client, module): app_catalog_subscriptions = oci_utils.list_all_resources( compute_client.list_app_catalog_subscriptions, compartment_id=module.params["compartment_id"], listing_id=module.params["listing_id"], ) for app_catalog_subscription in app_catalog_subscriptions: if (app_catalog_subscription.listing_resource_version == module.params["listing_resource_version"]): return oci_utils.to_dict(app_catalog_subscription) return None
def test_launch_instance_success(compute_client, get_oci_utils_create_and_wait_patch): module = get_module() inst_created = oci.core.models.Instance() inst_created.display_name = module.params['name'] inst_created.id = "XYZ" inst_created.lifecycle_state = "RUNNING" get_oci_utils_create_and_wait_patch.return_value = {"changed": True, "instance": to_dict(inst_created)} resp = oci_instance.launch_instance(compute_client, module, None) assert resp['instance']['lifecycle_state'] == "RUNNING"
def main(): module_args = oci_utils.get_common_arg_spec() module_args.update( dict( type=dict(type="str", required=True, choices=["FreeText", "Structured"]), matching_context_type=dict( type="str", required=False, choices=["NONE", "HIGHLIGHTS"], default="NONE", ), query=dict(type="str", required=False), text=dict(type="str", required=False), )) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, required_if=[("type", "FreeText", ["text"]), ("type", "Structured", ["query"])], ) if not HAS_OCI_PY_SDK: module.fail_json(msg="oci python sdk required for this module.") result = dict(changed=False) resource_search_client = oci_utils.create_service_client( module, ResourceSearchClient) matching_context_type = module.params.get("matching_context_type") search_details = None if module.params["type"] == "FreeText": ftsd = FreeTextSearchDetails() ftsd.type = "FreeText" if matching_context_type is not None: ftsd.matching_context_type = matching_context_type ftsd.text = module.params["text"] search_details = ftsd else: ssd = StructuredSearchDetails() if matching_context_type is not None: ssd.type = "Structured" ssd.matching_context_type = matching_context_type ssd.query = module.params["query"] search_details = ssd res_coll = oci_utils.call_with_backoff( resource_search_client.search_resources, search_details=search_details).data result["search_resources"] = oci_utils.to_dict(res_coll.items) module.exit_json(**result)
def main(): module_args = oci_utils.get_common_arg_spec() module_args.update( dict( type=dict(type='str', required=True, choices=['FreeText', 'Structured']), matching_context_type=dict(type='str', required=False, choices=['NONE', 'HIGHLIGHTS'], default='NONE'), query=dict(type='str', required=False), text=dict(type='str', required=False), )) module = AnsibleModule(argument_spec=module_args, supports_check_mode=False, required_if=[('type', 'FreeText', ['text']), ('type', 'Structured', ['query'])]) if not HAS_OCI_PY_SDK: module.fail_json(msg='oci python sdk required for this module.') result = dict(changed=False) resource_search_client = oci_utils.create_service_client( module, ResourceSearchClient) matching_context_type = module.params.get('matching_context_type') search_details = None if module.params['type'] == 'FreeText': ftsd = FreeTextSearchDetails() ftsd.type = 'FreeText' if matching_context_type is not None: ftsd.matching_context_type = matching_context_type ftsd.text = module.params['text'] search_details = ftsd else: ssd = StructuredSearchDetails() if matching_context_type is not None: ssd.type = 'Structured' ssd.matching_context_type = matching_context_type ssd.query = module.params['query'] search_details = ssd res_coll = oci_utils.call_with_backoff( resource_search_client.search_resources, search_details=search_details).data result['search_resources'] = oci_utils.to_dict(res_coll.items) module.exit_json(**result)