Skip to content

Commit 6e326f7

Browse files
Revert "api module: Add support for PUT methods"
1 parent 8ba5d2a commit 6e326f7

File tree

4 files changed

+6
-127
lines changed

4 files changed

+6
-127
lines changed

examples/virtual_disk.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

plugins/module_utils/rest_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,24 @@ def put_record(
8484
endpoint,
8585
payload,
8686
check_mode,
87-
query=None,
8887
timeout=None,
8988
binary_data=None,
9089
headers=None,
9190
):
9291
# Method put doesn't support check mode # IT ACTUALLY DOES
9392
if check_mode:
9493
return None
94+
# Only /rest/v1/ISO/[uuid}/data is using put, which doesn't return anything.
95+
# self.client.put on this endpoint returns None.
9596
try:
9697
response = self.client.put(
9798
endpoint,
9899
data=payload,
99-
query=query,
100+
query=_query(),
100101
timeout=timeout,
101102
binary_data=binary_data,
102103
headers=headers,
103-
).json
104+
)
104105
except TimeoutError as e:
105106
raise errors.ScaleComputingError(f"Request timed out: {e}")
106107
return response

plugins/modules/api.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- Tjaž Eržen (@tjazsch)
1717
short_description: API interaction with Scale Computing HyperCore
1818
description:
19-
- Perform a C(GET), C(POST), C(PATCH), C(DELETE), or C(PUT) request on resource(s) from the given endpoint.
19+
- Perform a C(GET), C(POST), C(PATCH) or C(DELETE) request on resource(s) from the given endpoint.
2020
The api module can be used to perform raw API calls whenever there is no
2121
suitable concrete module or role implementation for a specific task.
2222
version_added: 1.0.0
@@ -36,7 +36,6 @@
3636
- delete
3737
- get
3838
- post_list
39-
- put
4039
data:
4140
type: dict
4241
description:
@@ -240,34 +239,6 @@ def delete_record(module, rest_client):
240239
return True, task_tag
241240
return False, dict()
242241

243-
"""
244-
PUT_TIMEOUT_TIME was copied from the iso module for ISO data upload.
245-
Currently, assume we have 4.7 GB ISO and speed 1 MB/s -> 4700 seconds.
246-
Rounded to 3600.
247-
248-
TODO: compute it from expected min upload speed and file size.
249-
Even better, try to detect stalled uploads and terminate if no data was transmitted for more than N seconds.
250-
Yum/dnf complain with error "Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds"
251-
in such case.
252-
"""
253-
PUT_TIMEOUT_TIME = 3600
254-
255-
def put_record(module, rest_client):
256-
with open(module.params["source"], "rb") as source_file:
257-
result = rest_client.put_record(
258-
endpoint=module.params["endpoint"],
259-
payload=None,
260-
check_mode=module.check_mode,
261-
query=module.params["data"],
262-
timeout=PUT_TIMEOUT_TIME,
263-
binary_data=source_file,
264-
headers={
265-
"Content-Type": "application/octet-stream",
266-
"Accept": "application/json",
267-
}
268-
)
269-
return True, result
270-
271242

272243
def get_records(module, rest_client):
273244
records = rest_client.list_records(
@@ -287,8 +258,6 @@ def run(module, rest_client):
287258
return post_list_record(module, rest_client)
288259
elif action == "get": # GET method
289260
return get_records(module, rest_client)
290-
elif action == "put": # PUT method
291-
return put_record(module, rest_client)
292261
return delete_record(module, rest_client) # DELETE methodx
293262

294263

@@ -302,16 +271,13 @@ def main():
302271
),
303272
action=dict(
304273
type="str",
305-
choices=["post", "patch", "delete", "get", "post_list", "put"],
274+
choices=["post", "patch", "delete", "get", "post_list"],
306275
required=True,
307276
),
308277
endpoint=dict(
309278
type="str",
310279
required=True,
311280
),
312-
source=dict(
313-
type="str",
314-
),
315281
),
316282
)
317283

tests/unit/plugins/modules/test_api.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ def test_get_method_record_absent(self, create_module, rest_client):
7575
assert result == (False, [])
7676

7777

78-
class TestPutMethod:
79-
def test_put_method(self, create_module, rest_client):
80-
# TODO: Put method hasn't been implemented yet, so tests still have to be written.
81-
# Harcoding value for now.
82-
module = create_module(
83-
params=dict(
84-
cluster_instance=dict(
85-
host="https://0.0.0.0",
86-
username="admin",
87-
password="admin",
88-
),
89-
action="put",
90-
endpoint="/rest/v1/VirDomain",
91-
unique_id="id",
92-
data=dict(),
93-
)
94-
)
95-
96-
result = api.put_record(module, rest_client)
97-
assert result == (-1, -1, -1)
98-
99-
10078
class TestDeleteRecord:
10179
def test_delete_method_record_present(self, create_module, rest_client, task_wait):
10280
module = create_module(

0 commit comments

Comments
 (0)