def create_service_gateway(virtual_network_client, module): create_service_gateway_details = CreateServiceGatewayDetails() for attribute in create_service_gateway_details.attribute_map.keys(): if attribute in module.params: setattr(create_service_gateway_details, attribute, module.params[attribute]) list_of_request_details = [] if module.params['services'] is not None: for req in module.params['services']: req_details = ServiceIdRequestDetails() req_details.service_id = req['service_id'] list_of_request_details.append(req_details) create_service_gateway_details.services = list_of_request_details result = oci_utils.create_and_wait( resource_type="service_gateway", create_fn=virtual_network_client.create_service_gateway, kwargs_create={ "create_service_gateway_details": create_service_gateway_details }, client=virtual_network_client, get_fn=virtual_network_client.get_service_gateway, get_param="service_gateway_id", module=module) return result
def create_service_gateway(): global virtual_network_client_composite_ops global service_gateway_id global vcn_id # setup create service gateway details create_sgw_details = CreateServiceGatewayDetails() create_sgw_details.vcn_id = vcn_id create_sgw_details.compartment_id = src_compartment_id create_sgw_details.display_name = 'test_change_service_gateway' # Providing empty services field for the purpose of the test. Please update to required # services' value if reaching Oracle Services. create_sgw_details.services = list() # create sgw response = virtual_network_client_composite_ops.create_service_gateway_and_wait_for_state(create_sgw_details, wait_for_states=[ServiceGateway.LIFECYCLE_STATE_AVAILABLE]) service_gateway_id = response.data.id info("SERVICE GATEWAY ID : %s" % service_gateway_id)
def main(): module_args = oci_utils.get_taggable_arg_spec(supports_create=True, supports_wait=True) module_args.update( dict(block_traffic=dict(type='str', required=False, default=False), service_id=dict(type='str', required=False), vcn_id=dict(type='str', required=False), services=dict(type='list', required=False), compartment_id=dict(type='str', required=False), display_name=dict(type='str', required=False, aliases=['name']), state=dict(type='str', required=False, default='present', choices=['absent', 'present']), service_gateway_id=dict(type='str', required=False, aliases=['id']))) module = AnsibleModule(argument_spec=module_args, supports_check_mode=False, required_if=[('state', 'absent', ['service_gateway_id'])], mutually_exclusive=[['service_id', 'services']]) if not HAS_OCI_PY_SDK: module.fail_json(msg='oci python sdk required for this module.') virtual_network_client = oci_utils.create_service_client( module, VirtualNetworkClient) exclude_attributes = {'display_name': True} state = module.params['state'] if state == 'absent': if module.params['service_id']: # Detach service from service gateway. result = handle_service_id_request(virtual_network_client, module, False) else: # Delete service gateway. result = delete_service_gateway(virtual_network_client, module) else: service_gateway_id = module.params['service_gateway_id'] if service_gateway_id is not None: # Update service gateway details. result = update_service_gateway(virtual_network_client, module) if module.params['service_id']: # Attach/detach service to service gateway. serviceid_request_result = handle_service_id_request( virtual_network_client, module, True) result['changed'] = serviceid_request_result[ 'changed'] or result['changed'] result['service_gateway'] = serviceid_request_result[ 'service_gateway'] else: # Create service gateway. result = oci_utils.check_and_create_resource( resource_type='service_gateway', create_fn=create_service_gateway, kwargs_create={ 'virtual_network_client': virtual_network_client, 'module': module }, list_fn=virtual_network_client.list_service_gateways, kwargs_list={ 'compartment_id': module.params['compartment_id'], 'vcn_id': module.params['vcn_id'] }, module=module, model=CreateServiceGatewayDetails(), exclude_attributes=exclude_attributes) module.exit_json(**result)
def main(): module_args = oci_utils.get_taggable_arg_spec(supports_create=True, supports_wait=True) module_args.update( dict( block_traffic=dict(type="bool", required=False, default=False), service_id=dict(type="str", required=False), vcn_id=dict(type="str", required=False), services=dict(type="list", required=False), compartment_id=dict(type="str", required=False), display_name=dict(type="str", required=False, aliases=["name"]), state=dict( type="str", required=False, default="present", choices=["absent", "present"], ), service_gateway_id=dict(type="str", required=False, aliases=["id"]), )) module = AnsibleModule( argument_spec=module_args, supports_check_mode=False, required_if=[("state", "absent", ["service_gateway_id"])], mutually_exclusive=[["service_id", "services"]], ) if not HAS_OCI_PY_SDK: module.fail_json(msg="oci python sdk required for this module.") virtual_network_client = oci_utils.create_service_client( module, VirtualNetworkClient) exclude_attributes = {"display_name": True} state = module.params["state"] if state == "absent": if module.params["service_id"]: # Detach service from service gateway. result = handle_service_id_request(virtual_network_client, module, False) else: # Delete service gateway. result = delete_service_gateway(virtual_network_client, module) else: service_gateway_id = module.params["service_gateway_id"] if service_gateway_id is not None: # Update service gateway details. result = update_service_gateway(virtual_network_client, module) if module.params["service_id"]: # Attach/detach service to service gateway. serviceid_request_result = handle_service_id_request( virtual_network_client, module, True) result["changed"] = (serviceid_request_result["changed"] or result["changed"]) result["service_gateway"] = serviceid_request_result[ "service_gateway"] else: # Create service gateway. result = oci_utils.check_and_create_resource( resource_type="service_gateway", create_fn=create_service_gateway, kwargs_create={ "virtual_network_client": virtual_network_client, "module": module, }, list_fn=virtual_network_client.list_service_gateways, kwargs_list={ "compartment_id": module.params["compartment_id"], "vcn_id": module.params["vcn_id"], }, module=module, model=CreateServiceGatewayDetails(), exclude_attributes=exclude_attributes, ) module.exit_json(**result)