text: #!/usr/bin/env python
  # Info module template
  
  #############################################
  #                WARNING                    #
  #############################################
  #
  # This file is auto generated by
  #   https://github.com/jgroom33/vmware_rest_code_generator
  #
  # Do not edit this file manually.
  #
  # Changes should be made in the swagger used to
  #   generate this file or in the generator
  #
  #############################################
  
  from __future__ import absolute_import, division, print_function
  
  __metaclass__ = type
  import socket
  import json
  
  DOCUMENTATION = """
  module: nsi_api_v2_0_fres_by_freid_userdata_by_userdatakey
  short_description: Handle resource of type nsi_api_v2_0_fres_by_freid_userdata_by_userdatakey
  description: Handle resource of type nsi_api_v2_0_fres_by_freid_userdata_by_userdatakey
  options:
    freId:
      description:
      - FRE identifier
      - Required with I(state=['delete', 'put'])
      - Used by I(state=['delete', 'put'])
      type: str
    state:
      choices:
      - delete
      - put
      description: []
      type: str
    userDataKey:
      description:
      - userData attribute name to delete
      - Required with I(state=['delete', 'put'])
      - Used by I(state=['delete', 'put'])
      type: str
    userDataValue:
      description:
      - The desired userData value
      - Required with I(state=['put'])
      - Used by I(state=['put'])
      type: str
  author: []
  version_added: 1.0.0
  requirements:
  - python >= 3.6
  """
  IN_QUERY_PARAMETER = []
  from ansible.module_utils.basic import env_fallback
  
  try:
      from ansible_module.turbo.module import AnsibleTurboModule as AnsibleModule
  except ImportError:
      from ansible.module_utils.basic import AnsibleModule
  from ansible_collections.ciena.mcp.plugins.module_utils.mcp import (
      gen_args,
      open_session,
      update_changed_flag,
  )
  
  
  def prepare_argument_spec():
      argument_spec = {
          "mcp_hostname": dict(
              type="str", required=False, fallback=(env_fallback, ["MCP_HOST"])
          ),
          "mcp_username": dict(
              type="str", required=False, fallback=(env_fallback, ["MCP_USER"])
          ),
          "mcp_password": dict(
              type="str",
              required=False,
              no_log=True,
              fallback=(env_fallback, ["MCP_PASSWORD"]),
          ),
      }
      argument_spec["userDataValue"] = {"type": "str", "operationIds": ["put"]}
      argument_spec["userDataKey"] = {"type": "str", "operationIds": ["delete", "put"]}
      argument_spec["state"] = {"type": "str", "choices": ["delete", "put"]}
      argument_spec["freId"] = {"type": "str", "operationIds": ["delete", "put"]}
      return argument_spec
  
  
  async def main():
      module_args = prepare_argument_spec()
      module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
      session = await open_session(
          mcp_hostname=module.params["mcp_hostname"],
          mcp_username=module.params["mcp_username"],
          mcp_password=module.params["mcp_password"],
      )
      result = await entry_point(module, session)
      module.exit_json(**result)
  
  
  def url(params):
      return "https://{mcp_hostname}/nsi/api/v2_0/fres/{freId}/userData/{userDataKey}".format(
          **params
      )
  
  
  async def entry_point(module, session):
      func = globals()[("_" + module.params["state"])]
      return await func(module.params, session)
  
  
  async def _delete(params, session):
      _url = "https://{mcp_hostname}/nsi/api/v2_0/fres/{freId}/userData/{userDataKey}".format(
          **params
      ) + gen_args(
          params, IN_QUERY_PARAMETER
      )
      async with session.delete(_url) as resp:
          content_types = [
              "application/json-patch+json",
              "application/vnd.api+json",
              "application/json",
          ]
          try:
              if resp.headers["Content-Type"] in content_types:
                  _json = await resp.json()
              else:
                  print("response Content-Type not supported")
          except KeyError:
              _json = {}
          return await update_changed_flag(_json, resp.status, "delete")
  
  
  async def _put(params, session):
      accepted_fields = ["freId", "userDataKey", "userDataValue"]
      spec = {}
      for i in accepted_fields:
          if params[i] is not None:
              spec[i] = params[i]
      _url = "https://{mcp_hostname}/nsi/api/v2_0/fres/{freId}/userData/{userDataKey}".format(
          **params
      ) + gen_args(
          params, IN_QUERY_PARAMETER
      )
      async with session.put(_url, json=spec) as resp:
          content_types = [
              "application/json-patch+json",
              "application/vnd.api+json",
              "application/json",
          ]
          try:
              if resp.headers["Content-Type"] in content_types:
                  _json = await resp.json()
              else:
                  print("response Content-Type not supported")
          except KeyError:
              _json = {}
          return await update_changed_flag(_json, resp.status, "put")
  
  
  if __name__ == "__main__":
      import asyncio
  
      loop = asyncio.get_event_loop()
      loop.run_until_complete(main())
  