def update_policy(identity_client, module): result = dict() changed = False try: update_policy_details = UpdatePolicyDetails() existing_policy = oci_utils.call_with_backoff( identity_client.get_policy, policy_id=module.params['policy_id']).data if not oci_utils.are_attrs_equal( current_resource=existing_policy, module=module, attributes=update_policy_details.attribute_map.keys()): update_policy_details = oci_utils.update_model_with_user_options( curr_model=existing_policy, update_model=update_policy_details, module=module) # If policy statements are provided using policy document option if module.params['policy_document'] is not None: update_policy_details.statements = get_policy_statements( module.params['policy_document']) response = oci_utils.call_with_backoff( identity_client.update_policy, policy_id=existing_policy.id, update_policy_details=update_policy_details) changed = True result['policy'] = to_dict(response.data) else: # No change needed, return the exising policy result['policy'] = to_dict(existing_policy) except ServiceError as ex: module.fail_json(msg=ex.message) result['changed'] = changed return result
def main(): my_logger = oci_utils.get_logger("oci_instance") set_logger(my_logger) module_args = oci_utils.get_common_arg_spec() module_args.update( dict(name=dict(type='str', required=False, aliases=['display_name']), vnic_id=dict(type='str', required=False, aliases=['id']), hostname_label=dict(type='str', required=False), skip_source_dest_check=dict(type='bool', required=False, default=False), state=dict(type='str', required=False, default='present', choices=['present']))) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, required_if=[('state', 'present', ['id'])], ) if not HAS_OCI_PY_SDK: module.fail_json(msg='oci python sdk required for this module.') virtnetwork_client = oci_utils.create_service_client( module, VirtualNetworkClient) result = dict(changed=False) id = module.params['id'] debug("VNIC Id provided by user is " + str(id)) try: vnic = oci_utils.call_with_backoff(virtnetwork_client.get_vnic, vnic_id=id).data if vnic is not None: name = module.params['name'] hostname_label = module.params['hostname_label'] skip_source_dest_check = module.params['skip_source_dest_check'] if not oci_utils.are_attrs_equal(vnic, module, vnic.attribute_map.keys()): debug("Need to update VNIC " + str(id)) uvd = UpdateVnicDetails() uvd.skip_source_dest_check = skip_source_dest_check uvd.hostname_label = hostname_label uvd.display_name = name oci_utils.call_with_backoff(virtnetwork_client.update_vnic, vnic_id=id, update_vnic_details=uvd) result['changed'] = True resp = oci_utils.call_with_backoff(virtnetwork_client.get_vnic, vnic_id=id) result['vnic'] = to_dict(resp.data) except ServiceError as ex: module.fail_json(msg=ex.message) module.exit_json(**result)
def main(): my_logger = oci_utils.get_logger("oci_instance") set_logger(my_logger) module_args = oci_utils.get_taggable_arg_spec( supports_create=True, supports_wait=True ) module_args.update( dict( compartment_id=dict(type="str", required=False), name=dict(type="str", required=False, aliases=["display_name"]), image_id=dict(type="str", required=False, aliases=["id"]), instance_id=dict(type="str", required=False), image_source_details=dict(type="dict", required=False), state=dict( type="str", required=False, default="present", choices=["present", "absent"], ), launch_mode=dict( type="str", required=False, choices=["NATIVE", "EMULATED", "PARAVIRTUALIZED", "CUSTOM"], ), ) ) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, mutually_exclusive=[("instance_id", "image_source_details")], required_if=[("state", "absent", ["image_id"])], ) if not HAS_OCI_PY_SDK: module.fail_json(msg="oci python sdk required for this module.") compute_client = oci_utils.create_service_client(module, ComputeClient) state = module.params["state"] result = dict(changed=False) id = module.params.get("image_id", None) exclude_attributes = {"display_name": True} debug("Id is " + str(id)) if id is not None: image_resp = _get_image_from_id(compute_client, id, module) if state == "absent": debug("Delete " + id + " requested") if image_resp.data is not None: debug("Deleting " + image_resp.data.id) result = delete_image(compute_client, id, module) else: debug("Image " + id + " already deleted.") elif state == "present": display_name = module.params["name"] current_image = image_resp.data attrs_equal = oci_utils.are_attrs_equal( current_image, module, ["display_name", "freeform_tags", "defined_tags"] ) if not attrs_equal: result = update_image(compute_client, id, display_name, module) else: result = oci_utils.check_and_create_resource( resource_type="image", create_fn=create_image, kwargs_create={"compute_client": compute_client, "module": module}, list_fn=compute_client.list_images, kwargs_list={"compartment_id": module.params["compartment_id"]}, module=module, model=CreateImageDetails(), exclude_attributes=exclude_attributes, ) module.exit_json(**result)
def main(): my_logger = oci_utils.get_logger("oci_instance") set_logger(my_logger) module_args = oci_utils.get_taggable_arg_spec(supports_create=True, supports_wait=True) module_args.update( dict(compartment_id=dict(type='str', required=False), name=dict(type='str', required=False, aliases=['display_name']), image_id=dict(type='str', required=False, aliases=['id']), instance_id=dict(type='str', required=False), image_source_details=dict(type='dict', required=False), state=dict(type='str', required=False, default='present', choices=['present', 'absent']))) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, mutually_exclusive=['instance_id', 'image_source_details'], required_if=[('state', 'absent', ['image_id'])], ) if not HAS_OCI_PY_SDK: module.fail_json(msg='oci python sdk required for this module.') config = oci_utils.get_oci_config(module) compute_client = ComputeClient(config) state = module.params['state'] result = dict(changed=False) id = module.params.get("image_id", None) exclude_attributes = {'display_name': True, 'launch_mode': True} debug("Id is " + str(id)) if id is not None: image_resp = _get_image_from_id(compute_client, id, module) if state == 'absent': debug("Delete " + id + " requested") if image_resp.data is not None: debug("Deleting " + image_resp.data.id) result = delete_image(compute_client, id, module) else: debug("Image " + id + " already deleted.") elif state == 'present': display_name = module.params['name'] current_image = image_resp.data attrs_equal = oci_utils.are_attrs_equal( current_image, module, ["display_name", "freeform_tags", "defined_tags"]) if not attrs_equal: result = update_image(compute_client, id, display_name, module) else: result = oci_utils.check_and_create_resource( resource_type="image", create_fn=create_image, kwargs_create={ "compute_client": compute_client, "module": module }, list_fn=compute_client.list_images, kwargs_list={"compartment_id": module.params['compartment_id']}, module=module, model=CreateImageDetails(), exclude_attributes=exclude_attributes) module.exit_json(**result)
def main(): my_logger = oci_utils.get_logger("oci_instance") set_logger(my_logger) module_args = oci_utils.get_common_arg_spec() module_args.update( dict( name=dict(type="str", required=False, aliases=["display_name"]), vnic_id=dict(type="str", required=False, aliases=["id"]), hostname_label=dict(type="str", required=False), nsg_ids=dict(type="list", required=False), skip_source_dest_check=dict(type="bool", required=False, default=False), state=dict(type="str", required=False, default="present", choices=["present"]), )) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, required_if=[("state", "present", ["id"])], ) if not HAS_OCI_PY_SDK: module.fail_json(msg="oci python sdk required for this module.") virtnetwork_client = oci_utils.create_service_client( module, VirtualNetworkClient) result = dict(changed=False) id = module.params["id"] debug("VNIC Id provided by user is " + str(id)) try: vnic = oci_utils.call_with_backoff(virtnetwork_client.get_vnic, vnic_id=id).data if vnic is not None: name = module.params["name"] hostname_label = module.params["hostname_label"] skip_source_dest_check = module.params["skip_source_dest_check"] if not oci_utils.are_attrs_equal(vnic, module, vnic.attribute_map.keys()): debug("Need to update VNIC " + str(id)) uvd = UpdateVnicDetails() uvd.skip_source_dest_check = skip_source_dest_check uvd.hostname_label = hostname_label uvd.display_name = name uvd.nsg_ids = module.params.get("nsg_ids", None) oci_utils.call_with_backoff(virtnetwork_client.update_vnic, vnic_id=id, update_vnic_details=uvd) result["changed"] = True resp = oci_utils.call_with_backoff(virtnetwork_client.get_vnic, vnic_id=id) result["vnic"] = to_dict(resp.data) except ServiceError as ex: module.fail_json(msg=ex.message) module.exit_json(**result)