Skip to content

Commit 831befc

Browse files
committed
Make it a one function call
1 parent 9d06ad7 commit 831befc

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

plugins/module_utils/hypercore_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from functools import total_ordering
1414
from typing import List
1515
from ..module_utils.utils import PayloadMapper
16+
from ansible.module_utils.basic import AnsibleModule
1617
from ..module_utils.rest_client import RestClient
1718
from ..module_utils.typed_classes import (
1819
TypedUpdateToAnsible,
@@ -56,6 +57,11 @@ def verify(self, spec: str) -> bool:
5657
version = ".".join(version.split(".")[:3])
5758
return VersionSpec(spec).match(Version(version))
5859

60+
def check_version(self, module: AnsibleModule, required_version: str) -> None:
61+
if not self.verify(required_version):
62+
msg = f"HyperCore server version={self.version} does not match required version {required_version}"
63+
module.fail_json(msg=msg)
64+
5965

6066
@total_ordering
6167
class Version:

plugins/modules/cluster_name.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def main() -> None:
100100
client = Client.get_client(module.params["cluster_instance"])
101101
rest_client = RestClient(client)
102102
hcversion = HyperCoreVersion(rest_client)
103-
if not hcversion.verify(HYPERCORE_VERSION_REQUIREMENTS):
104-
msg = f"HyperCore server version={hcversion.version} does not match required version {HYPERCORE_VERSION_REQUIREMENTS}"
105-
module.fail_json(msg=msg)
103+
hcversion.check_version(module, HYPERCORE_VERSION_REQUIREMENTS)
106104
changed, record, diff = run(module, rest_client)
107105
module.exit_json(changed=changed, record=record, diff=diff)
108106
except errors.ScaleComputingError as e:

plugins/modules/virtual_disk_info.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ def main() -> None:
9797
client = Client.get_client(module.params["cluster_instance"])
9898
rest_client = CachedRestClient(client)
9999
hcversion = HyperCoreVersion(rest_client)
100-
if not hcversion.verify(HYPERCORE_VERSION_REQUIREMENTS):
101-
msg = f"HyperCore server version={hcversion.version} does not match required version {HYPERCORE_VERSION_REQUIREMENTS}"
102-
module.fail_json(msg=msg)
100+
hcversion.check_version(module, HYPERCORE_VERSION_REQUIREMENTS)
103101
records = run(module, rest_client)
104102
module.exit_json(changed=False, records=records)
105103
except errors.ScaleComputingError as e:

0 commit comments

Comments
 (0)