Skip to content

Commit af1d659

Browse files
committed
Deprecate old return values.
1 parent 08c1db5 commit af1d659

File tree

8 files changed

+203
-20
lines changed

8 files changed

+203
-20
lines changed

changelogs/fragments/173-storagebox.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ deprecated_features:
22
- "storagebox* modules - the ``hetzner_user`` and ``hetzner_pass`` options for these modules are deprecated; support will be removed in community.hrobot 3.0.0. Use ``hetzner_token`` instead (https://github.com/ansible-collections/community.hrobot/pull/173)."
33
- "storagebox* modules - the ``hetzner_token`` option for these modules will be required from community.hrobot 3.0.0 on (https://github.com/ansible-collections/community.hrobot/pull/173)."
44
- "storagebox* modules - membership in the ``community.hrobot.robot`` action group (module defaults group) is deprecated; the modules will be removed from the group in community.hrobot 3.0.0. Use ``community.hrobot.api`` instead (https://github.com/ansible-collections/community.hrobot/pull/173)."
5+
- "storagebox_info - the ``storageboxes[].login``, ``storageboxes[].disk_quota``, ``storageboxes[].disk_usage``, ``storageboxes[].disk_usage_data``, ``storageboxes[].disk_usage_snapshot``, ``storageboxes[].webdav``, ``storageboxes[].samba``, ``storageboxes[].ssh``, ``storageboxes[].external_reachability``, and ``storageboxes[].zfs`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/173)."
6+
- "storagebox_snapshot_info - the ``snapshots[].timestamp``, ``snapshots[].size``, ``snapshots[].filesystem_size``, ``snapshots[].automatic``, and ``snapshots[].comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/173)."
7+
- "storagebox_snapshot_plan - the ``plans[].month`` return value is deprecated, since it only returns ``null`` with the new API and cannot be set to any other value (https://github.com/ansible-collections/community.hrobot/pull/173)."
8+
- "storagebox_snapshot_plan_info - the ``plans[].month`` return value is deprecated, since it only returns ``null`` with the new API and cannot be set to any other value (https://github.com/ansible-collections/community.hrobot/pull/173)."
9+
- "storagebox_subaccount - the ``subaccount.homedirectory``, ``subaccount.samba``, ``subaccount.ssh``, ``subaccount.external_reachability``, ``subaccount.webdav``, ``subaccount.readonly``, ``subaccount.createtime``, and ``subaccount.comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/173)."
10+
- "storagebox_subaccount_info - the ``subaccounts[].accountid``, ``subaccounts[].homedirectory``, ``subaccounts[].samba``, ``subaccounts[].ssh``, ``subaccounts[].external_reachability``, ``subaccounts[].webdav``, ``subaccounts[].readonly``, ``subaccounts[].createtime``, and ``subaccounts[].comment`` return values are deprecated and will be removed from community.routeros. Check out the documentation to find out their new names according to the new API (https://github.com/ansible-collections/community.hrobot/pull/173)."
511
minor_changes:
612
- "storagebox* modules - the code for the old API (that has been removed by Hetzner) has been replaced by hard-coding the result of the API, namely that no storagebox of this ID exists (https://github.com/ansible-collections/community.hrobot/pull/173)."

plugins/module_utils/_tagging.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (c) 2025 Felix Fontein <[email protected]>
4+
# This code is licensed under the following two licenses:
5+
# - Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
6+
# - GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
7+
# SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later
8+
9+
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
10+
# Do not use this from other collections or standalone plugins/modules!
11+
12+
from __future__ import absolute_import, division, print_function
13+
__metaclass__ = type
14+
15+
16+
try:
17+
from ansible.module_utils.datatag import deprecate_value as _deprecate_value
18+
HAS_DEPRECATE_VALUE = True
19+
except ImportError:
20+
HAS_DEPRECATE_VALUE = False
21+
22+
23+
def deprecate_value(value, msg, version, help_text=None):
24+
"""
25+
Given a value, tag it as deprecated (with message, removal version, and optional help text).
26+
27+
For ansible-core versions that do not support data tagging, simply returns the value as-is.
28+
"""
29+
if not HAS_DEPRECATE_VALUE:
30+
return value
31+
return _deprecate_value(
32+
value,
33+
msg,
34+
collection_name="community.hrobot",
35+
version=version,
36+
help_text=help_text,
37+
)

plugins/modules/storagebox_info.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
description:
8989
- The storage box's login name.
9090
- Note that this is copied from RV(storageboxes[].username) in case O(hetzner_token) is specified.
91+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
92+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
9193
type: str
9294
sample: u12345
9395
returned: success
@@ -200,62 +202,80 @@
200202
description:
201203
- Total amount of MB available.
202204
- Note that this is copied from RV(storageboxes[].storage_box_type.size) in case O(hetzner_token) is specified.
205+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
206+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
203207
type: int
204208
sample: 10240000
205209
returned: when O(full_info=true), or O(hetzner_token) is specified
206210
disk_usage:
207211
description:
208212
- The amount of MB in use.
209213
- Note that this is copied from RV(storageboxes[].stats.size) in case O(hetzner_token) is specified.
214+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
215+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
210216
type: int
211217
sample: 900
212218
returned: when O(full_info=true), or O(hetzner_token) is specified
213219
disk_usage_data:
214220
description:
215221
- The amount of MB used by files.
216222
- Note that this is copied from RV(storageboxes[].stats.size_data) in case O(hetzner_token) is specified.
223+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
224+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
217225
type: int
218226
sample: 500
219227
returned: when O(full_info=true), or O(hetzner_token) is specified
220228
disk_usage_snapshots:
221229
description:
222230
- The amount of MB used by snapshots.
223231
- Note that this is copied from RV(storageboxes[].stats.size_snapshots) in case O(hetzner_token) is specified.
232+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
233+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
224234
type: int
225235
sample: 400
226236
returned: when O(full_info=true), or O(hetzner_token) is specified
227237
webdav:
228238
description:
229239
- Whether WebDAV is active.
230240
- Note that this is copied from RV(storageboxes[].access_settings.webdav_enabled) in case O(hetzner_token) is specified.
241+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
242+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
231243
type: bool
232244
sample: true
233245
returned: when O(full_info=true), or O(hetzner_token) is specified
234246
samba:
235247
description:
236248
- Whether SAMBA is active.
237249
- Note that this is copied from RV(storageboxes[].access_settings.samba_enabled) in case O(hetzner_token) is specified.
250+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
251+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
238252
type: bool
239253
sample: true
240254
returned: when O(full_info=true), or O(hetzner_token) is specified
241255
ssh:
242256
description:
243257
- Whether SSH is active.
244258
- Note that this is copied from RV(storageboxes[].access_settings.ssh_enabled) in case O(hetzner_token) is specified.
259+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
260+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
245261
type: bool
246262
sample: true
247263
returned: when O(full_info=true), or O(hetzner_token) is specified
248264
external_reachability:
249265
description:
250266
- Whether the storage box is reachable externally.
251267
- Note that this is copied from RV(storageboxes[].access_settings.reachable_externally) in case O(hetzner_token) is specified.
268+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
269+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
252270
type: bool
253271
sample: true
254272
returned: when O(full_info=true), or O(hetzner_token) is specified
255273
zfs:
256274
description:
257275
- Shows whether the ZFS directory is visible.
258276
- Note that this is copied from RV(storageboxes[].access_settings.zfs_enabled) in case O(hetzner_token) is specified.
277+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
278+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
259279
type: bool
260280
sample: false
261281
returned: when O(full_info=true), or O(hetzner_token) is specified
@@ -531,6 +551,10 @@
531551
api_fetch_url_json_list,
532552
)
533553

554+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
555+
deprecate_value,
556+
)
557+
534558

535559
_CONVERT = {
536560
"login": ["username"],
@@ -552,7 +576,11 @@ def add_hrobot_compat_shim(storagebox):
552576
value = storagebox
553577
for src in source:
554578
value = value[src]
555-
result[dest] = value
579+
result[dest] = deprecate_value(
580+
value,
581+
"The return value `{0}` is deprecated; use `{1}` instead.".format(dest, ".".join(source)),
582+
version="3.0.0",
583+
)
556584
return result
557585

558586

plugins/modules/storagebox_snapshot_info.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,44 @@
7171
description:
7272
- The timestamp of snapshot in UTC.
7373
- Note that this is copied from RV(snapshots[].created) in case O(hetzner_token) is specified.
74+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
75+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
7476
type: str
7577
sample: "2025-01-21T13:40:38+00:00"
7678
returned: success
7779
size:
7880
description:
7981
- The Snapshot size in MB.
8082
- Note that this is copied from RV(snapshots[].stats.size) in case O(hetzner_token) is specified.
83+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
84+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
8185
type: int
8286
sample: 400
8387
returned: success
8488
filesystem_size:
8589
description:
8690
- The size of the Storage Box at creation time of the snapshot in MB.
8791
- Note that this is computed from RV(snapshots[].stats.size_filesystem) in case O(hetzner_token) is specified.
92+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
93+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
8894
type: int
8995
sample: 12345
9096
returned: success
9197
automatic:
9298
description:
9399
- Whether the snapshot was created automatically.
94100
- Note that this is computed from RV(snapshots[].is_automatic) in case O(hetzner_token) is specified.
101+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
102+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
95103
type: bool
96104
sample: false
97105
returned: success
98106
comment:
99107
description:
100108
- The comment for the snapshot.
101109
- Note that this is copied from RV(snapshots[].description) in case O(hetzner_token) is specified.
110+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
111+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
102112
type: str
103113
sample: "This is a snapshot"
104114
returned: success
@@ -176,14 +186,38 @@
176186
api_fetch_url_json,
177187
)
178188

189+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
190+
deprecate_value,
191+
)
192+
179193

180194
def adjust_legacy(snapshot):
181195
result = dict(snapshot)
182-
result["timestamp"] = result["created"]
183-
result["size"] = result["stats"]["size"] // (1024 * 1024)
184-
result["filesystem_size"] = result["stats"]["size_filesystem"] // (1024 * 1024)
185-
result["automatic"] = result["is_automatic"]
186-
result["comment"] = result["description"]
196+
result["timestamp"] = deprecate_value(
197+
result["created"],
198+
"The return value `timestamp` is deprecated; use `created` instead.",
199+
version="3.0.0",
200+
)
201+
result["size"] = deprecate_value(
202+
result["stats"]["size"] // (1024 * 1024),
203+
"The return value `size` is deprecated; use `stats.size / (1024*1024)` instead.",
204+
version="3.0.0",
205+
)
206+
result["filesystem_size"] = deprecate_value(
207+
result["stats"]["size_filesystem"] // (1024 * 1024),
208+
"The return value `filesystem_size` is deprecated; use `stats.size_filesystem / (1024*1024)` instead.",
209+
version="3.0.0",
210+
)
211+
result["automatic"] = deprecate_value(
212+
result["is_automatic"],
213+
"The return value `automatic` is deprecated; use `is_automatic` instead.",
214+
version="3.0.0",
215+
)
216+
result["comment"] = deprecate_value(
217+
result["description"],
218+
"The return value `comment` is deprecated; use `description` instead.",
219+
version="3.0.0",
220+
)
187221
return result
188222

189223

plugins/modules/storagebox_snapshot_plan.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155
- The month of execution of the plan. V(1) is January, V(12) is December.
156156
- If set to V(null), the plan is run every month.
157157
- Always V(null) if O(hetzner_token) is provided.
158+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
159+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
158160
type: int
159161
sample: null
160162
returned: success
@@ -182,6 +184,10 @@
182184
api_fetch_url_json,
183185
)
184186

187+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
188+
deprecate_value,
189+
)
190+
185191

186192
def extract(result):
187193
sb = result['storage_box']
@@ -193,7 +199,7 @@ def extract(result):
193199
'hour': None,
194200
'day_of_week': None,
195201
'day_of_month': None,
196-
'month': None,
202+
'month': deprecate_value(None, "The return value `month` is deprecated; it is always null.", version="3.0.0"),
197203
'max_snapshots': None,
198204
}
199205

@@ -203,7 +209,7 @@ def extract(result):
203209
'hour': sp['hour'],
204210
'day_of_week': sp['day_of_week'],
205211
'day_of_month': sp['day_of_month'],
206-
'month': None,
212+
'month': deprecate_value(None, "The return value `month` is deprecated; it is always null.", version="3.0.0"),
207213
'max_snapshots': sp['max_snapshots'],
208214
}
209215

plugins/modules/storagebox_snapshot_plan_info.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
- The month of execution of the plan. V(1) is January, V(12) is December.
102102
- If set to V(null), the plan is run every month.
103103
- Always V(null) if O(hetzner_token) is provided.
104+
- B(This return value is deprecated and will be removed from community.hrobot 3.0.0.)
105+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using this return value.
104106
type: int
105107
sample: null
106108
returned: success
@@ -126,6 +128,10 @@
126128
api_fetch_url_json,
127129
)
128130

131+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
132+
deprecate_value,
133+
)
134+
129135

130136
def extract(result):
131137
sb = result['storage_box']
@@ -137,7 +143,7 @@ def extract(result):
137143
'hour': None,
138144
'day_of_week': None,
139145
'day_of_month': None,
140-
'month': None,
146+
'month': deprecate_value(None, "The return value `month` is deprecated; it is always null.", version="3.0.0"),
141147
'max_snapshots': None,
142148
}
143149

@@ -147,7 +153,7 @@ def extract(result):
147153
'hour': sp['hour'],
148154
'day_of_week': sp['day_of_week'],
149155
'day_of_month': sp['day_of_month'],
150-
'month': None,
156+
'month': deprecate_value(None, "The return value `month` is deprecated; it is always null.", version="3.0.0"),
151157
'max_snapshots': sp['max_snapshots'],
152158
}
153159

plugins/modules/storagebox_subaccount.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@
270270
description:
271271
- The subaccount object returned by the API.
272272
- If O(hetzner_token) is provided, some extra fields are added to make this more compatible with the format returned by O(hetzner_user).
273+
- B(This extra return values are deprecated and will be removed from community.hrobot 3.0.0.)
274+
If you are using ansible-core 2.19 or newer, you will see a deprecation message when using these return values.
275+
These return values are RV(ignore:homedirectory), RV(ignore:samba), RV(ignore:ssh), RV(ignore:webdav), RV(ignore:external_reachability),
276+
RV(ignore:readonly), RV(ignore:createtime), and RV(ignore:comment).
273277
type: dict
274278
returned: if O(state=present)
275279
"""
@@ -291,6 +295,10 @@
291295
api_fetch_url_json,
292296
)
293297

298+
from ansible_collections.community.hrobot.plugins.module_utils._tagging import (
299+
deprecate_value,
300+
)
301+
294302

295303
def create_subaccount(module, storagebox_id, subaccount):
296304
action_url = "{0}/v1/storage_boxes/{1}/subaccounts".format(API_BASE_URL, storagebox_id)
@@ -483,7 +491,11 @@ def adjust_legacy(subaccount):
483491
}.items():
484492
value, exists = get_value_opt(subaccount, path)
485493
if exists:
486-
result[key] = value
494+
result[key] = deprecate_value(
495+
value,
496+
"The return value `{0}` is deprecated; use `{1}` instead.".format(key, ".".join(path)),
497+
version="3.0.0",
498+
)
487499
return result
488500

489501

0 commit comments

Comments
 (0)