We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
vsphere_copy: Remove deprecated parameters
##### SUMMARY
The parameters `host` and `login` are deprecated and should be removed in version 3.

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
vsphere_copy

##### ADDITIONAL INFORMATION
#1194

https://github.com/ansible-collections/community.vmware/blob/67b9506a306da2caec9a2eda60003fd54a9df71e/plugins/modules/vsphere_copy.py#L143-L146

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/modules/vsphere_copy.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 # Copyright: (c) 2015, Dag Wieers (@dagwieers) <dag@wieers.com>
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7 
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10 
11 
12 DOCUMENTATION = r'''
13 ---
14 module: vsphere_copy
15 short_description: Copy a file to a VMware datastore
16 description:
17     - Upload files to a VMware datastore through a vCenter REST API.
18 author:
19 - Dag Wieers (@dagwieers)
20 options:
21   hostname:
22     aliases: ['host']
23   username:
24     aliases: ['login']
25   src:
26     description:
27       - The file to push to vCenter.
28     required: true
29     type: str
30     aliases: [ name ]
31   datacenter:
32     description:
33       - The datacenter on the vCenter server that holds the datastore.
34     required: false
35     type: str
36   datastore:
37     description:
38       - The datastore to push files to.
39     required: true
40     type: str
41   path:
42     description:
43       - The file to push to the datastore.
44     required: true
45     type: str
46     aliases: [ dest ]
47   timeout:
48     description:
49       - The timeout in seconds for the upload to the datastore.
50     default: 10
51     type: int
52 
53 notes:
54   - "This module ought to be run from a system that can access the vCenter or the ESXi directly and has the file to transfer.
55     It can be the normal remote target or you can change it either by using C(transport: local) or using C(delegate_to)."
56 extends_documentation_fragment:
57 - community.vmware.vmware.documentation
58 
59 '''
60 
61 EXAMPLES = r'''
62 - name: Copy file to datastore using delegate_to
63   community.vmware.vsphere_copy:
64     hostname: '{{ vcenter_hostname }}'
65     username: '{{ vcenter_username }}'
66     password: '{{ vcenter_password }}'
67     src: /some/local/file
68     datacenter: DC1 Someplace
69     datastore: datastore1
70     path: some/remote/file
71   delegate_to: localhost
72 
73 - name: Copy file to datastore when datacenter is inside folder called devel
74   community.vmware.vsphere_copy:
75     hostname: '{{ vcenter_hostname }}'
76     username: '{{ vcenter_username }}'
77     password: '{{ vcenter_password }}'
78     src: /some/local/file
79     datacenter: devel/DC1
80     datastore: datastore1
81     path: some/remote/file
82   delegate_to: localhost
83 
84 - name: Copy file to datastore using other_system
85   community.vmware.vsphere_copy:
86     hostname: '{{ vcenter_hostname }}'
87     username: '{{ vcenter_username }}'
88     password: '{{ vcenter_password }}'
89     src: /other/local/file
90     datacenter: DC2 Someplace
91     datastore: datastore2
92     path: other/remote/file
93   delegate_to: other_system
94 '''
95 
96 import atexit
97 import errno
98 import mmap
99 import os
100 import socket
101 import traceback
102 
103 from ansible.module_utils.basic import AnsibleModule
104 from ansible.module_utils.six.moves.urllib.parse import urlencode, quote
105 from ansible.module_utils._text import to_native
106 from ansible.module_utils.urls import open_url
107 from ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec
108 
109 
110 def vmware_path(datastore, datacenter, path):
111     ''' Constructs a URL path that vSphere accepts reliably '''
112     path = "/folder/%s" % quote(path.lstrip("/"))
113     # Due to a software bug in vSphere, it fails to handle ampersand in datacenter names
114     # The solution is to do what vSphere does (when browsing) and double-encode ampersands, maybe others ?
115     if not path.startswith("/"):
116         path = "/" + path
117     params = dict(dsName=datastore)
118     if datacenter:
119         datacenter = datacenter.replace('&', '%26')
120         params["dcPath"] = datacenter
121     params = urlencode(params)
122     return "%s?%s" % (path, params)
123 
124 
125 def main():
126     argument_spec = vmware_argument_spec()
127     argument_spec.update(dict(
128         hostname=dict(required=False, aliases=['host']),
129         username=dict(required=False, aliases=['login']),
130         src=dict(required=True, aliases=['name']),
131         datacenter=dict(required=False),
132         datastore=dict(required=True),
133         path=dict(required=True, aliases=['dest'], type='str'),
134         timeout=dict(default=10, type='int'))
135     )
136 
137     module = AnsibleModule(
138         argument_spec=argument_spec,
139         # Implementing check-mode using HEAD is impossible, since size/date is not 100% reliable
140         supports_check_mode=False,
141     )
142 
143     if module.params.get('host'):
144         module.deprecate("The 'host' option is being replaced by 'hostname'", version='3.0.0', collection_name='community.vmware')
145     if module.params.get('login'):
146         module.deprecate("The 'login' option is being replaced by 'username'", version='3.0.0', collection_name='community.vmware')
147 
148     hostname = module.params['hostname']
149     username = module.params['username']
150     password = module.params.get('password')
151     src = module.params.get('src')
152     datacenter = module.params.get('datacenter')
153     datastore = module.params.get('datastore')
154     path = module.params.get('path')
155     validate_certs = module.params.get('validate_certs')
156     timeout = module.params.get('timeout')
157 
158     try:
159         fd = open(src, "rb")
160         atexit.register(fd.close)
161     except Exception as e:
162         module.fail_json(msg="Failed to open src file %s" % to_native(e))
163 
164     if os.stat(src).st_size == 0:
165         data = ''
166     else:
167         data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)
168         atexit.register(data.close)
169 
170     remote_path = vmware_path(datastore, datacenter, path)
171 
172     if not all([hostname, username, password]):
173         module.fail_json(msg="One of following parameter is missing - hostname, username, password")
174     url = 'https://%s%s' % (hostname, remote_path)
175 
176     headers = {
177         "Content-Type": "application/octet-stream",
178         "Content-Length": str(len(data)),
179     }
180 
181     r = None
182     try:
183         r = open_url(url, data=data, headers=headers, method='PUT', timeout=timeout,
184                      url_username=username, url_password=password, validate_certs=validate_certs,
185                      force_basic_auth=True)
186     except socket.error as e:
187         if isinstance(e.args, tuple):
188             if len(e.args) > 0:
189                 if e[0] == errno.ECONNRESET:
190                     # vSphere resets connection if the file is in use and cannot be replaced
191                     module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=to_native(e), url=url)
192             else:
193                 module.fail_json(msg=to_native(e))
194         else:
195             module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e),
196                              url=url, exception=traceback.format_exc())
197     except Exception as e:
198         error_code = -1
199         try:
200             if isinstance(e[0], int):
201                 error_code = e[0]
202         except (KeyError, TypeError):
203             pass
204         module.fail_json(msg=to_native(e), status=None, errno=error_code,
205                          reason=to_native(e), url=url, exception=traceback.format_exc())
206 
207     if not r:
208         module.fail_json(msg="Failed to upload", url=url,
209                          errno=None, status=None, reason=None)
210     status = r.getcode()
211     if 200 <= status < 300:
212         module.exit_json(changed=True, status=status, reason=r.msg, url=url)
213     else:
214         length = r.headers.get('content-length', None)
215         if r.headers.get('transfer-encoding', '').lower() == 'chunked':
216             chunked = 1
217         else:
218             chunked = 0
219 
220         module.fail_json(msg='Failed to upload', errno=None, status=status, reason=r.msg, length=length, headers=dict(r.headers), chunked=chunked, url=url)
221 
222 
223 if __name__ == '__main__':
224     main()
225
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py
--- a/plugins/modules/vsphere_copy.py
+++ b/plugins/modules/vsphere_copy.py
@@ -18,10 +18,6 @@
 author:
 - Dag Wieers (@dagwieers)
 options:
-  hostname:
-    aliases: ['host']
-  username:
-    aliases: ['login']
   src:
     description:
       - The file to push to vCenter.
@@ -125,8 +121,6 @@
 def main():
     argument_spec = vmware_argument_spec()
     argument_spec.update(dict(
-        hostname=dict(required=False, aliases=['host']),
-        username=dict(required=False, aliases=['login']),
         src=dict(required=True, aliases=['name']),
         datacenter=dict(required=False),
         datastore=dict(required=True),
@@ -140,11 +134,6 @@
         supports_check_mode=False,
     )
 
-    if module.params.get('host'):
-        module.deprecate("The 'host' option is being replaced by 'hostname'", version='3.0.0', collection_name='community.vmware')
-    if module.params.get('login'):
-        module.deprecate("The 'login' option is being replaced by 'username'", version='3.0.0', collection_name='community.vmware')
-
     hostname = module.params['hostname']
     username = module.params['username']
     password = module.params.get('password')

{"golden_diff": "diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py\n--- a/plugins/modules/vsphere_copy.py\n+++ b/plugins/modules/vsphere_copy.py\n@@ -18,10 +18,6 @@\n author:\n - Dag Wieers (@dagwieers)\n options:\n-  hostname:\n-    aliases: ['host']\n-  username:\n-    aliases: ['login']\n   src:\n     description:\n       - The file to push to vCenter.\n@@ -125,8 +121,6 @@\n def main():\n     argument_spec = vmware_argument_spec()\n     argument_spec.update(dict(\n-        hostname=dict(required=False, aliases=['host']),\n-        username=dict(required=False, aliases=['login']),\n         src=dict(required=True, aliases=['name']),\n         datacenter=dict(required=False),\n         datastore=dict(required=True),\n@@ -140,11 +134,6 @@\n         supports_check_mode=False,\n     )\n \n-    if module.params.get('host'):\n-        module.deprecate(\"The 'host' option is being replaced by 'hostname'\", version='3.0.0', collection_name='community.vmware')\n-    if module.params.get('login'):\n-        module.deprecate(\"The 'login' option is being replaced by 'username'\", version='3.0.0', collection_name='community.vmware')\n-\n     hostname = module.params['hostname']\n     username = module.params['username']\n     password = module.params.get('password')\n", "issue": "vsphere_copy: Remove deprecated parameters\n##### SUMMARY\r\nThe parameters `host` and `login` are deprecated and should be removed in version 3.\r\n\r\n##### ISSUE TYPE\r\n- Feature Idea\r\n\r\n##### COMPONENT NAME\r\nvsphere_copy\r\n\r\n##### ADDITIONAL INFORMATION\r\n#1194\r\n\r\nhttps://github.com/ansible-collections/community.vmware/blob/67b9506a306da2caec9a2eda60003fd54a9df71e/plugins/modules/vsphere_copy.py#L143-L146\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright: (c) 2015, Dag Wieers (@dagwieers) <dag@wieers.com>\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nDOCUMENTATION = r'''\n---\nmodule: vsphere_copy\nshort_description: Copy a file to a VMware datastore\ndescription:\n    - Upload files to a VMware datastore through a vCenter REST API.\nauthor:\n- Dag Wieers (@dagwieers)\noptions:\n  hostname:\n    aliases: ['host']\n  username:\n    aliases: ['login']\n  src:\n    description:\n      - The file to push to vCenter.\n    required: true\n    type: str\n    aliases: [ name ]\n  datacenter:\n    description:\n      - The datacenter on the vCenter server that holds the datastore.\n    required: false\n    type: str\n  datastore:\n    description:\n      - The datastore to push files to.\n    required: true\n    type: str\n  path:\n    description:\n      - The file to push to the datastore.\n    required: true\n    type: str\n    aliases: [ dest ]\n  timeout:\n    description:\n      - The timeout in seconds for the upload to the datastore.\n    default: 10\n    type: int\n\nnotes:\n  - \"This module ought to be run from a system that can access the vCenter or the ESXi directly and has the file to transfer.\n    It can be the normal remote target or you can change it either by using C(transport: local) or using C(delegate_to).\"\nextends_documentation_fragment:\n- community.vmware.vmware.documentation\n\n'''\n\nEXAMPLES = r'''\n- name: Copy file to datastore using delegate_to\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /some/local/file\n    datacenter: DC1 Someplace\n    datastore: datastore1\n    path: some/remote/file\n  delegate_to: localhost\n\n- name: Copy file to datastore when datacenter is inside folder called devel\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /some/local/file\n    datacenter: devel/DC1\n    datastore: datastore1\n    path: some/remote/file\n  delegate_to: localhost\n\n- name: Copy file to datastore using other_system\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /other/local/file\n    datacenter: DC2 Someplace\n    datastore: datastore2\n    path: other/remote/file\n  delegate_to: other_system\n'''\n\nimport atexit\nimport errno\nimport mmap\nimport os\nimport socket\nimport traceback\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils.six.moves.urllib.parse import urlencode, quote\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.urls import open_url\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec\n\n\ndef vmware_path(datastore, datacenter, path):\n    ''' Constructs a URL path that vSphere accepts reliably '''\n    path = \"/folder/%s\" % quote(path.lstrip(\"/\"))\n    # Due to a software bug in vSphere, it fails to handle ampersand in datacenter names\n    # The solution is to do what vSphere does (when browsing) and double-encode ampersands, maybe others ?\n    if not path.startswith(\"/\"):\n        path = \"/\" + path\n    params = dict(dsName=datastore)\n    if datacenter:\n        datacenter = datacenter.replace('&', '%26')\n        params[\"dcPath\"] = datacenter\n    params = urlencode(params)\n    return \"%s?%s\" % (path, params)\n\n\ndef main():\n    argument_spec = vmware_argument_spec()\n    argument_spec.update(dict(\n        hostname=dict(required=False, aliases=['host']),\n        username=dict(required=False, aliases=['login']),\n        src=dict(required=True, aliases=['name']),\n        datacenter=dict(required=False),\n        datastore=dict(required=True),\n        path=dict(required=True, aliases=['dest'], type='str'),\n        timeout=dict(default=10, type='int'))\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        # Implementing check-mode using HEAD is impossible, since size/date is not 100% reliable\n        supports_check_mode=False,\n    )\n\n    if module.params.get('host'):\n        module.deprecate(\"The 'host' option is being replaced by 'hostname'\", version='3.0.0', collection_name='community.vmware')\n    if module.params.get('login'):\n        module.deprecate(\"The 'login' option is being replaced by 'username'\", version='3.0.0', collection_name='community.vmware')\n\n    hostname = module.params['hostname']\n    username = module.params['username']\n    password = module.params.get('password')\n    src = module.params.get('src')\n    datacenter = module.params.get('datacenter')\n    datastore = module.params.get('datastore')\n    path = module.params.get('path')\n    validate_certs = module.params.get('validate_certs')\n    timeout = module.params.get('timeout')\n\n    try:\n        fd = open(src, \"rb\")\n        atexit.register(fd.close)\n    except Exception as e:\n        module.fail_json(msg=\"Failed to open src file %s\" % to_native(e))\n\n    if os.stat(src).st_size == 0:\n        data = ''\n    else:\n        data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)\n        atexit.register(data.close)\n\n    remote_path = vmware_path(datastore, datacenter, path)\n\n    if not all([hostname, username, password]):\n        module.fail_json(msg=\"One of following parameter is missing - hostname, username, password\")\n    url = 'https://%s%s' % (hostname, remote_path)\n\n    headers = {\n        \"Content-Type\": \"application/octet-stream\",\n        \"Content-Length\": str(len(data)),\n    }\n\n    r = None\n    try:\n        r = open_url(url, data=data, headers=headers, method='PUT', timeout=timeout,\n                     url_username=username, url_password=password, validate_certs=validate_certs,\n                     force_basic_auth=True)\n    except socket.error as e:\n        if isinstance(e.args, tuple):\n            if len(e.args) > 0:\n                if e[0] == errno.ECONNRESET:\n                    # vSphere resets connection if the file is in use and cannot be replaced\n                    module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=to_native(e), url=url)\n            else:\n                module.fail_json(msg=to_native(e))\n        else:\n            module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e),\n                             url=url, exception=traceback.format_exc())\n    except Exception as e:\n        error_code = -1\n        try:\n            if isinstance(e[0], int):\n                error_code = e[0]\n        except (KeyError, TypeError):\n            pass\n        module.fail_json(msg=to_native(e), status=None, errno=error_code,\n                         reason=to_native(e), url=url, exception=traceback.format_exc())\n\n    if not r:\n        module.fail_json(msg=\"Failed to upload\", url=url,\n                         errno=None, status=None, reason=None)\n    status = r.getcode()\n    if 200 <= status < 300:\n        module.exit_json(changed=True, status=status, reason=r.msg, url=url)\n    else:\n        length = r.headers.get('content-length', None)\n        if r.headers.get('transfer-encoding', '').lower() == 'chunked':\n            chunked = 1\n        else:\n            chunked = 0\n\n        module.fail_json(msg='Failed to upload', errno=None, status=status, reason=r.msg, length=length, headers=dict(r.headers), chunked=chunked, url=url)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vsphere_copy.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright: (c) 2015, Dag Wieers (@dagwieers) <dag@wieers.com>\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nDOCUMENTATION = r'''\n---\nmodule: vsphere_copy\nshort_description: Copy a file to a VMware datastore\ndescription:\n    - Upload files to a VMware datastore through a vCenter REST API.\nauthor:\n- Dag Wieers (@dagwieers)\noptions:\n  src:\n    description:\n      - The file to push to vCenter.\n    required: true\n    type: str\n    aliases: [ name ]\n  datacenter:\n    description:\n      - The datacenter on the vCenter server that holds the datastore.\n    required: false\n    type: str\n  datastore:\n    description:\n      - The datastore to push files to.\n    required: true\n    type: str\n  path:\n    description:\n      - The file to push to the datastore.\n    required: true\n    type: str\n    aliases: [ dest ]\n  timeout:\n    description:\n      - The timeout in seconds for the upload to the datastore.\n    default: 10\n    type: int\n\nnotes:\n  - \"This module ought to be run from a system that can access the vCenter or the ESXi directly and has the file to transfer.\n    It can be the normal remote target or you can change it either by using C(transport: local) or using C(delegate_to).\"\nextends_documentation_fragment:\n- community.vmware.vmware.documentation\n\n'''\n\nEXAMPLES = r'''\n- name: Copy file to datastore using delegate_to\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /some/local/file\n    datacenter: DC1 Someplace\n    datastore: datastore1\n    path: some/remote/file\n  delegate_to: localhost\n\n- name: Copy file to datastore when datacenter is inside folder called devel\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /some/local/file\n    datacenter: devel/DC1\n    datastore: datastore1\n    path: some/remote/file\n  delegate_to: localhost\n\n- name: Copy file to datastore using other_system\n  community.vmware.vsphere_copy:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    src: /other/local/file\n    datacenter: DC2 Someplace\n    datastore: datastore2\n    path: other/remote/file\n  delegate_to: other_system\n'''\n\nimport atexit\nimport errno\nimport mmap\nimport os\nimport socket\nimport traceback\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils.six.moves.urllib.parse import urlencode, quote\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.urls import open_url\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec\n\n\ndef vmware_path(datastore, datacenter, path):\n    ''' Constructs a URL path that vSphere accepts reliably '''\n    path = \"/folder/%s\" % quote(path.lstrip(\"/\"))\n    # Due to a software bug in vSphere, it fails to handle ampersand in datacenter names\n    # The solution is to do what vSphere does (when browsing) and double-encode ampersands, maybe others ?\n    if not path.startswith(\"/\"):\n        path = \"/\" + path\n    params = dict(dsName=datastore)\n    if datacenter:\n        datacenter = datacenter.replace('&', '%26')\n        params[\"dcPath\"] = datacenter\n    params = urlencode(params)\n    return \"%s?%s\" % (path, params)\n\n\ndef main():\n    argument_spec = vmware_argument_spec()\n    argument_spec.update(dict(\n        src=dict(required=True, aliases=['name']),\n        datacenter=dict(required=False),\n        datastore=dict(required=True),\n        path=dict(required=True, aliases=['dest'], type='str'),\n        timeout=dict(default=10, type='int'))\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        # Implementing check-mode using HEAD is impossible, since size/date is not 100% reliable\n        supports_check_mode=False,\n    )\n\n    hostname = module.params['hostname']\n    username = module.params['username']\n    password = module.params.get('password')\n    src = module.params.get('src')\n    datacenter = module.params.get('datacenter')\n    datastore = module.params.get('datastore')\n    path = module.params.get('path')\n    validate_certs = module.params.get('validate_certs')\n    timeout = module.params.get('timeout')\n\n    try:\n        fd = open(src, \"rb\")\n        atexit.register(fd.close)\n    except Exception as e:\n        module.fail_json(msg=\"Failed to open src file %s\" % to_native(e))\n\n    if os.stat(src).st_size == 0:\n        data = ''\n    else:\n        data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)\n        atexit.register(data.close)\n\n    remote_path = vmware_path(datastore, datacenter, path)\n\n    if not all([hostname, username, password]):\n        module.fail_json(msg=\"One of following parameter is missing - hostname, username, password\")\n    url = 'https://%s%s' % (hostname, remote_path)\n\n    headers = {\n        \"Content-Type\": \"application/octet-stream\",\n        \"Content-Length\": str(len(data)),\n    }\n\n    r = None\n    try:\n        r = open_url(url, data=data, headers=headers, method='PUT', timeout=timeout,\n                     url_username=username, url_password=password, validate_certs=validate_certs,\n                     force_basic_auth=True)\n    except socket.error as e:\n        if isinstance(e.args, tuple):\n            if len(e.args) > 0:\n                if e[0] == errno.ECONNRESET:\n                    # vSphere resets connection if the file is in use and cannot be replaced\n                    module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=to_native(e), url=url)\n            else:\n                module.fail_json(msg=to_native(e))\n        else:\n            module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e),\n                             url=url, exception=traceback.format_exc())\n    except Exception as e:\n        error_code = -1\n        try:\n            if isinstance(e[0], int):\n                error_code = e[0]\n        except (KeyError, TypeError):\n            pass\n        module.fail_json(msg=to_native(e), status=None, errno=error_code,\n                         reason=to_native(e), url=url, exception=traceback.format_exc())\n\n    if not r:\n        module.fail_json(msg=\"Failed to upload\", url=url,\n                         errno=None, status=None, reason=None)\n    status = r.getcode()\n    if 200 <= status < 300:\n        module.exit_json(changed=True, status=status, reason=r.msg, url=url)\n    else:\n        length = r.headers.get('content-length', None)\n        if r.headers.get('transfer-encoding', '').lower() == 'chunked':\n            chunked = 1\n        else:\n            chunked = 0\n\n        module.fail_json(msg='Failed to upload', errno=None, status=status, reason=r.msg, length=length, headers=dict(r.headers), chunked=chunked, url=url)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vsphere_copy.py"}]}