Skip to content

Commit 1f09ffe

Browse files
committed
Use /rest/v2
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
1 parent 28c6d24 commit 1f09ffe

62 files changed

Lines changed: 225 additions & 162 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

plugins/inventory/hypercore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
from ..module_utils import errors
149149
from ..module_utils.client import Client
150150
from ..module_utils.rest_client import RestClient
151+
from ..module_utils.utils import REST_API_VERSION
151152

152153
logging.basicConfig(level=logging.ERROR)
153154
logger = logging.getLogger(__name__)
@@ -247,7 +248,7 @@ def parse(self, inventory, loader, path, cache=False):
247248
)
248249
client = Client(host, username, password, timeout, auth_method)
249250
rest_client = RestClient(client)
250-
vms = rest_client.list_records("/rest/v1/VirDomain")
251+
vms = rest_client.list_records(f"{REST_API_VERSION}/VirDomain")
251252

252253
for vm in vms:
253254
groups = []

plugins/module_utils/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from .errors import AuthError
3232
from .errors import ScaleComputingError
3333
from .errors import UnexpectedAPIResponse
34+
from .utils import REST_API_VERSION
3435

3536
DEFAULT_HEADERS = dict(Accept="application/json")
3637

@@ -128,7 +129,7 @@ def _login_username_password(self) -> dict[str, str]:
128129
use_oidc = self.auth_method == AuthMethod.oidc.value
129130
resp = self._request(
130131
"POST",
131-
f"{self.host}/rest/v1/login",
132+
f"{self.host}{REST_API_VERSION}/login",
132133
data=json.dumps(
133134
dict(
134135
username=self.username,
@@ -150,7 +151,7 @@ def _logout(self) -> None:
150151
}
151152
self._request(
152153
"POST",
153-
f"{self.host}/rest/v1/logout",
154+
f"{self.host}{REST_API_VERSION}/logout",
154155
# data=json.dumps({}),
155156
headers=headers,
156157
timeout=self.timeout,

plugins/module_utils/cluster.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..module_utils.typed_classes import TypedClusterToAnsible
1919
from ..module_utils.typed_classes import TypedTaskTag
2020
from ..module_utils.utils import PayloadMapper
21+
from ..module_utils.utils import REST_API_VERSION
2122

2223

2324
class Cluster(PayloadMapper):
@@ -65,18 +66,18 @@ def __eq__(self, other: object) -> bool:
6566

6667
@classmethod
6768
def get(cls, rest_client: RestClient, must_exist: bool = True) -> Cluster:
68-
hypercore_dict = rest_client.get_record("/rest/v1/Cluster", must_exist=must_exist)
69+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/Cluster", must_exist=must_exist)
6970
cluster = cls.from_hypercore(hypercore_dict) # type: ignore # cluster never None
7071
return cluster
7172

7273
def update_name(self, rest_client: RestClient, name_new: str, check_mode: bool = False) -> TypedTaskTag:
73-
return rest_client.update_record(f"/rest/v1/Cluster/{self.uuid}", dict(clusterName=name_new), check_mode)
74+
return rest_client.update_record(f"{REST_API_VERSION}/Cluster/{self.uuid}", dict(clusterName=name_new), check_mode)
7475

7576
@staticmethod
7677
def shutdown(rest_client: RestClient, force_shutdown: bool = False, check_mode: bool = False) -> None:
7778
try:
7879
rest_client.create_record(
79-
"/rest/v1/Cluster/shutdown",
80+
f"{REST_API_VERSION}/Cluster/shutdown",
8081
dict(forceShutdown=force_shutdown),
8182
check_mode,
8283
)

plugins/module_utils/disk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..module_utils import errors
1818
from ..module_utils.rest_client import RestClient
1919
from ..module_utils.utils import PayloadMapper
20+
from ..module_utils.utils import REST_API_VERSION
2021

2122
TIERING_PRIORITY_MAPPING_TO_HYPERCORE = {
2223
0: 0,
@@ -223,5 +224,5 @@ def needs_reboot(self, action: str, desired_disk=None) -> bool:
223224

224225
@classmethod
225226
def get_by_uuid(cls, uuid: str, rest_client: RestClient, must_exist: bool) -> Optional[Disk]:
226-
hypercore_dict = rest_client.get_record(f"/rest/v1/VirDomainBlockDevice/{uuid}", must_exist=must_exist)
227+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/VirDomainBlockDevice/{uuid}", must_exist=must_exist)
227228
return cls.from_hypercore(hypercore_dict)

plugins/module_utils/dns_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..module_utils import errors
1313
from ..module_utils.utils import PayloadMapper
1414
from ..module_utils.utils import get_query
15+
from ..module_utils.utils import REST_API_VERSION
1516

1617

1718
class DNSConfig(PayloadMapper):
@@ -76,7 +77,7 @@ def __eq__(self, other):
7677
@classmethod
7778
def get_by_uuid(cls, ansible_dict, rest_client, must_exist=False):
7879
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
79-
hypercore_dict = rest_client.get_record("/rest/v1/DNSConfig", query, must_exist=must_exist)
80+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/DNSConfig", query, must_exist=must_exist)
8081
dns_config_from_hypercore = DNSConfig.from_hypercore(hypercore_dict)
8182
return dns_config_from_hypercore
8283

@@ -85,7 +86,7 @@ def get_by_uuid(cls, ansible_dict, rest_client, must_exist=False):
8586
def get_state(cls, rest_client):
8687
state = [
8788
DNSConfig.from_hypercore(hypercore_data=hypercore_dict).to_ansible()
88-
for hypercore_dict in rest_client.list_records("/rest/v1/DNSConfig/")
89+
for hypercore_dict in rest_client.list_records(f"{REST_API_VERSION}/DNSConfig/")
8990
]
9091

9192
# Raise an error if there is more than 1 DNS configuration available

plugins/module_utils/email_alert.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# from .client import Client
2424
from ..module_utils.utils import PayloadMapper
2525
from ..module_utils.utils import get_query
26+
from ..module_utils.utils import REST_API_VERSION
2627
from .rest_client import RestClient
2728

2829

@@ -105,7 +106,7 @@ def get_by_uuid(
105106
must_exist: bool = False,
106107
) -> Optional[EmailAlert]:
107108
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
108-
hypercore_dict = rest_client.get_record("/rest/v1/AlertEmailTarget", query, must_exist=must_exist)
109+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/AlertEmailTarget", query, must_exist=must_exist)
109110
alert_email_from_hypercore = cls.from_hypercore(hypercore_dict)
110111
return alert_email_from_hypercore
111112

@@ -121,7 +122,7 @@ def get_by_email(
121122
"email",
122123
ansible_hypercore_map=dict(email="emailAddress"),
123124
)
124-
hypercore_dict = rest_client.get_record("/rest/v1/AlertEmailTarget", query, must_exist=must_exist)
125+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/AlertEmailTarget", query, must_exist=must_exist)
125126

126127
alert_email_from_hypercore = EmailAlert.from_hypercore(hypercore_dict)
127128
return alert_email_from_hypercore
@@ -137,7 +138,7 @@ def list_by_email(
137138
"email",
138139
ansible_hypercore_map=dict(email="emailAddress"),
139140
)
140-
hypercore_dict_list = rest_client.list_records("/rest/v1/AlertEmailTarget", query)
141+
hypercore_dict_list = rest_client.list_records(f"{REST_API_VERSION}/AlertEmailTarget", query)
141142

142143
alert_email_from_hypercore_list = [EmailAlert.from_hypercore(hc_dict) for hc_dict in hypercore_dict_list]
143144
return alert_email_from_hypercore_list
@@ -149,7 +150,7 @@ def get_state(
149150
):
150151
state = [
151152
EmailAlert.from_hypercore(hypercore_data=hypercore_dict).to_ansible()
152-
for hypercore_dict in rest_client.list_records("/rest/v1/AlertEmailTarget/")
153+
for hypercore_dict in rest_client.list_records(f"{REST_API_VERSION}/AlertEmailTarget/")
153154
]
154155

155156
return state
@@ -161,7 +162,7 @@ def create(
161162
payload: Dict[Any, Any],
162163
check_mode: bool = False,
163164
):
164-
task_tag = rest_client.create_record("/rest/v1/AlertEmailTarget/", payload, check_mode)
165+
task_tag = rest_client.create_record(f"{REST_API_VERSION}/AlertEmailTarget/", payload, check_mode)
165166
email_alert = cls.get_by_uuid(
166167
dict(uuid=task_tag["createdUUID"]),
167168
rest_client,
@@ -175,18 +176,18 @@ def update(
175176
payload: Dict[Any, Any],
176177
check_mode: bool = False,
177178
) -> None:
178-
rest_client.update_record(f"/rest/v1/AlertEmailTarget/{self.uuid}", payload, check_mode)
179+
rest_client.update_record(f"{REST_API_VERSION}/AlertEmailTarget/{self.uuid}", payload, check_mode)
179180

180181
def delete(
181182
self,
182183
rest_client: RestClient,
183184
check_mode: bool = False,
184185
) -> None:
185-
rest_client.delete_record(f"/rest/v1/AlertEmailTarget/{self.uuid}", check_mode)
186+
rest_client.delete_record(f"{REST_API_VERSION}/AlertEmailTarget/{self.uuid}", check_mode)
186187

187188
def test(
188189
self,
189190
rest_client: RestClient,
190191
) -> TypedTaskTag:
191-
response = rest_client.client.post(f"/rest/v1/AlertEmailTarget/{self.uuid}/test", None)
192+
response = rest_client.client.post(f"{REST_API_VERSION}/AlertEmailTarget/{self.uuid}/test", None)
192193
return response

plugins/module_utils/hypercore_version.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ..module_utils.typed_classes import TypedUpdateStatusToAnsible
2525
from ..module_utils.typed_classes import TypedUpdateToAnsible
2626
from ..module_utils.utils import PayloadMapper
27+
from ..module_utils.utils import REST_API_VERSION
2728

2829

2930
class HyperCoreVersion:
@@ -41,7 +42,7 @@ def __init__(self, rest_client: RestClient):
4142
@property
4243
def version(self) -> str:
4344
if not self._version:
44-
record = self._rest_client.get_record("/rest/v1/Cluster")
45+
record = self._rest_client.get_record(f"{REST_API_VERSION}/Cluster")
4546
if record is None or "icosVersion" not in record or not isinstance(record["icosVersion"], str):
4647
raise AssertionError("HyperCore version not found in REST API response.")
4748
self._version = record["icosVersion"]
@@ -235,7 +236,7 @@ def get(
235236
) -> Optional[Update]:
236237
# api has a bug - the endpoint "/rest/v1/Update/{uuid}" returns a list of all available updates (and uuid can actually be anything),
237238
# that is why query is used
238-
update = rest_client.get_record(f"/rest/v1/Update/{uuid}", query=dict(uuid=uuid), must_exist=must_exist)
239+
update = rest_client.get_record(f"{REST_API_VERSION}/Update/{uuid}", query=dict(uuid=uuid), must_exist=must_exist)
239240
return cls.from_hypercore(update)
240241

241242
@classmethod
@@ -245,7 +246,7 @@ def apply_update(
245246
version: str,
246247
check_mode: bool = False,
247248
) -> TypedTaskTag:
248-
return rest_client.create_record(f"/rest/v1/Update/{version}/apply", payload=None, check_mode=check_mode)
249+
return rest_client.create_record(f"{REST_API_VERSION}/Update/{version}/apply", payload=None, check_mode=check_mode)
249250

250251

251252
class UpdateStatus(PayloadMapper):

plugins/module_utils/iso.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ..module_utils.utils import PayloadMapper
1414
from ..module_utils.utils import get_query
15+
from ..module_utils.utils import REST_API_VERSION
1516

1617

1718
class ISO(PayloadMapper):
@@ -99,7 +100,7 @@ def get_by_name(cls, ansible_dict, rest_client, must_exist=False):
99100
the record exists. If there is no record with such name, None is returned.
100101
"""
101102
query = get_query(ansible_dict, "name", ansible_hypercore_map=dict(name="name"))
102-
hypercore_dict = rest_client.get_record("/rest/v1/ISO", query, must_exist=must_exist)
103+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/ISO", query, must_exist=must_exist)
103104
iso_from_hypercore = ISO.from_hypercore(hypercore_dict)
104105
return iso_from_hypercore
105106

plugins/module_utils/node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
__metaclass__ = type
1212

1313
from ..module_utils.utils import PayloadMapper
14+
from ..module_utils.utils import REST_API_VERSION
1415

1516

1617
class Node(PayloadMapper):
@@ -63,6 +64,6 @@ def __eq__(self, other):
6364

6465
@classmethod
6566
def get_node(cls, query, rest_client, must_exist=False):
66-
hypercore_dict = rest_client.get_record("/rest/v1/Node", query, must_exist=must_exist)
67+
hypercore_dict = rest_client.get_record(f"{REST_API_VERSION}/Node", query, must_exist=must_exist)
6768
node_from_hypercore = cls.from_hypercore(hypercore_dict)
6869
return node_from_hypercore

plugins/module_utils/oidc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ..module_utils.typed_classes import TypedOidcToAnsible
2121
from ..module_utils.typed_classes import TypedTaskTag
2222
from ..module_utils.utils import PayloadMapper
23+
from ..module_utils.utils import REST_API_VERSION
2324

2425

2526
class Oidc(PayloadMapper):
@@ -41,7 +42,7 @@ def __init__(
4142

4243
@classmethod
4344
def get(cls, rest_client: RestClient) -> Optional[Oidc]:
44-
result = rest_client.list_records("/rest/v1/OIDCConfig")
45+
result = rest_client.list_records(f"{REST_API_VERSION}/OIDCConfig")
4546
if result:
4647
# One OIDC per cluster.
4748
return cls.from_hypercore(result[0])
@@ -93,8 +94,8 @@ def to_ansible(self) -> TypedOidcToAnsible:
9394

9495
def send_create_request(self, rest_client: RestClient) -> TypedTaskTag:
9596
payload = self.to_hypercore()
96-
return rest_client.create_record("/rest/v1/OIDCConfig", payload, False)
97+
return rest_client.create_record(f"{REST_API_VERSION}/OIDCConfig", payload, False)
9798

9899
def send_update_request(self, rest_client: RestClient) -> TypedTaskTag:
99100
payload = self.to_hypercore()
100-
return rest_client.update_record("/rest/v1/OIDCConfig/oidcconfig_uuid", payload, False)
101+
return rest_client.update_record(f"{REST_API_VERSION}/OIDCConfig/oidcconfig_uuid", payload, False)

0 commit comments

Comments
 (0)