Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions plugins/module_utils/email_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
TypedEmailAlertToAnsible,
TypedEmailAlertFromAnsible,
)
from typing import Union, Any, Dict
from typing import Union, Any, Dict, Optional


class EmailAlert(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
alert_tag_uuid: Union[str, None] = None,
email: Union[str, None] = None,
resend_delay: Union[int, None] = None,
silent_period: Union[int, None] = None,
uuid: Optional[str] = None,
alert_tag_uuid: Optional[str] = None,
email: Optional[str] = None,
resend_delay: Optional[int] = None,
silent_period: Optional[int] = None,
latest_task_tag: Union[TypedTaskTag, dict[Any, Any], None] = None,
):
self.uuid = uuid
Expand Down
8 changes: 4 additions & 4 deletions plugins/module_utils/hypercore_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TypedUpdateStatusToAnsible,
TypedTaskTag,
)
from typing import Any, Union
from typing import Any, Optional


class HyperCoreVersion:
Expand Down Expand Up @@ -174,8 +174,8 @@ def from_ansible(cls, ansible_data: dict[Any, Any]) -> None:

@classmethod
def from_hypercore(
cls, hypercore_data: Union[dict[Any, Any], None]
) -> Union[None, Update]:
cls, hypercore_data: Optional[dict[Any, Any]]
) -> Optional[Update]:
if not hypercore_data:
return None
return cls(
Expand Down Expand Up @@ -231,7 +231,7 @@ def get(
uuid: str,
must_exist: bool = True,
check_mode: bool = False,
) -> Union[None, Update]:
) -> Optional[Update]:
# api has a bug - the endpoint "/rest/v1/Update/{uuid}" returns a list of all available updates (and uuid can actually be anything),
# that is why query is used
update = rest_client.get_record(
Expand Down
16 changes: 8 additions & 8 deletions plugins/module_utils/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
TypedOidcToAnsible,
TypedOidcFromAnsible,
)
from typing import Union, Any
from typing import Any, Optional


class Oidc(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
client_id: Union[str, None] = None,
config_url: Union[str, None] = None,
certificate: Union[str, None] = None,
shared_secret: Union[str, None] = None, # Write-only
scopes: Union[str, None] = None,
uuid: Optional[str] = None,
client_id: Optional[str] = None,
config_url: Optional[str] = None,
certificate: Optional[str] = None,
shared_secret: Optional[str] = None, # Write-only
scopes: Optional[str] = None,
):
self.uuid = uuid
self.client_id = client_id
Expand All @@ -38,7 +38,7 @@ def __init__(
self.scopes = scopes

@classmethod
def get(cls, rest_client: RestClient) -> Union[Oidc, None]:
def get(cls, rest_client: RestClient) -> Optional[Oidc]:
result = rest_client.list_records("/rest/v1/OIDCConfig")
if result:
# One OIDC per cluster.
Expand Down
22 changes: 11 additions & 11 deletions plugins/module_utils/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
TypedRegistrationFromAnsible,
TypedRegistrationToAnsible,
)
from typing import Union, Any
from typing import Any, Optional


class Registration(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
company_name: Union[str, None] = None,
contact: Union[str, None] = None,
phone: Union[str, None] = None,
email: Union[str, None] = None,
cluster_id: Union[str, None] = None,
cluster_data: Union[str, None] = None,
cluster_data_hash: Union[str, None] = None,
cluster_data_hash_accepted: Union[str, None] = None,
uuid: Optional[str] = None,
company_name: Optional[str] = None,
contact: Optional[str] = None,
phone: Optional[str] = None,
email: Optional[str] = None,
cluster_id: Optional[str] = None,
cluster_data: Optional[str] = None,
cluster_data_hash: Optional[str] = None,
cluster_data_hash_accepted: Optional[str] = None,
):
self.uuid = uuid
self.company_name = company_name
Expand All @@ -44,7 +44,7 @@ def __init__(
self.cluster_data_hash_accepted = cluster_data_hash_accepted

@classmethod
def get(cls, rest_client: RestClient) -> Union[Registration, None]:
def get(cls, rest_client: RestClient) -> Optional[Registration]:
result = rest_client.list_records("/rest/v1/Registration")
if result:
# One registration per cluster.
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__metaclass__ = type

from typing import Any, Union
from typing import Any, Optional


def _query(original=None):
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_record(
query: dict[Any, Any] = None,
must_exist: bool = False,
timeout: float = None,
) -> Union[dict[Any, Any], None]:
) -> Optional[dict[Any, Any]]:
records = self.list_records(endpoint=endpoint, query=query, timeout=timeout)
if len(records) > 1:
raise errors.ScaleComputingError(
Expand Down
10 changes: 4 additions & 6 deletions plugins/module_utils/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..module_utils.rest_client import RestClient
from ..module_utils.typed_classes import TypedRoleToAnsible

from typing import Union, Any
from typing import Any, Optional


class Role(PayloadMapper):
Expand All @@ -26,9 +26,7 @@ def from_ansible(cls, ansible_data: Any) -> None:
pass

@classmethod
def from_hypercore(
cls, hypercore_data: Union[dict[Any, Any], None]
) -> Union[Role, None]:
def from_hypercore(cls, hypercore_data: Optional[dict[Any, Any]]) -> Optional[Role]:
if not hypercore_data:
# In case for get_record, return None if no result is found
return None
Expand Down Expand Up @@ -63,7 +61,7 @@ def __eq__(self, other: object) -> bool:
@classmethod
def get_role_from_uuid(
cls, role_uuid: str, rest_client: RestClient, must_exist: bool = False
) -> Union[Role, None]:
) -> Optional[Role]:
hypercore_dict = rest_client.get_record(
"/rest/v1/Role/{0}".format(role_uuid), must_exist=must_exist
)
Expand All @@ -73,7 +71,7 @@ def get_role_from_uuid(
@classmethod
def get_role_from_name(
cls, role_name: str, rest_client: RestClient, must_exist: bool = False
) -> Union[Role, None]:
) -> Optional[Role]:
hypercore_dict = rest_client.get_record(
"/rest/v1/Role", {"name": role_name}, must_exist=must_exist
)
Expand Down
20 changes: 10 additions & 10 deletions plugins/module_utils/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
TypedSmtpToAnsible,
TypedSmtpFromAnsible,
)
from typing import Union, Any, Dict
from typing import Union, Any, Dict, Optional


class SMTP(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
server: Union[str, None] = None,
port: Union[int, None] = None,
use_ssl: Union[bool, None] = False,
use_auth: Union[bool, None] = False,
auth_user: Union[str, None] = None,
auth_password: Union[str, None] = None,
from_address: Union[str, None] = None,
uuid: Optional[str] = None,
server: Optional[str] = None,
port: Optional[int] = None,
use_ssl: Optional[bool] = False,
use_auth: Optional[bool] = False,
auth_user: Optional[str] = None,
auth_password: Optional[str] = None,
from_address: Optional[str] = None,
latest_task_tag: Union[TypedTaskTag, dict[Any, Any], None] = None,
):
self.uuid = uuid
Expand Down Expand Up @@ -121,7 +121,7 @@ def get_by_uuid(
ansible_dict: Dict[Any, Any],
rest_client: RestClient,
must_exist: bool = False,
) -> Union[SMTP, None]:
) -> Optional[SMTP]:
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
hypercore_dict = rest_client.get_record(
"/rest/v1/AlertSMTPConfig", query, must_exist=must_exist
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/support_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from ansible.module_utils.basic import AnsibleModule
from ..module_utils.client import Client
from ..module_utils.typed_classes import TypedSupportTunnelToAnsible
from typing import Any, Union
from typing import Any, Union, Optional


class SupportTunnel(PayloadMapper):
def __init__(self, open: bool, code: Union[int, None]):
def __init__(self, open: bool, code: Optional[int]):
self.open = open
self.code = code

Expand Down
26 changes: 12 additions & 14 deletions plugins/module_utils/syslog_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
TypedSyslogServerToAnsible,
TypedSyslogServerFromAnsible,
)
from typing import List, Union, Any, Dict
from typing import List, Union, Any, Dict, Optional

protocols = {"SYSLOG_PROTOCOL_TCP": "tcp", "SYSLOG_PROTOCOL_UDP": "udp"}


class SyslogServer(PayloadMapper):
def __init__(
self,
uuid: Union[str, None] = None,
alert_tag_uuid: Union[str, None] = None,
host: Union[str, None] = None,
port: Union[int, None] = None,
protocol: Union[str, None] = None,
resend_delay: Union[int, None] = None,
silent_period: Union[int, None] = None,
uuid: Optional[str] = None,
alert_tag_uuid: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = None,
protocol: Optional[str] = None,
resend_delay: Optional[int] = None,
silent_period: Optional[int] = None,
latest_task_tag: Union[TypedTaskTag, dict[Any, Any], None] = None,
):
self.uuid = uuid
Expand All @@ -54,9 +54,7 @@ def from_ansible(cls, ansible_data: TypedSyslogServerFromAnsible) -> SyslogServe
)

@classmethod
def from_hypercore(
cls, hypercore_data: Dict[Any, Any]
) -> Union[SyslogServer, None]:
def from_hypercore(cls, hypercore_data: Dict[Any, Any]) -> Optional[SyslogServer]:
if not hypercore_data:
return None
return cls(
Expand Down Expand Up @@ -112,7 +110,7 @@ def get_by_uuid(
ansible_dict: Dict[Any, Any],
rest_client: RestClient,
must_exist: bool = False,
) -> Union[SyslogServer, None]:
) -> Optional[SyslogServer]:
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
hypercore_dict = rest_client.get_record(
"/rest/v1/AlertSyslogTarget", query, must_exist=must_exist
Expand All @@ -126,7 +124,7 @@ def get_by_host(
host: str,
rest_client: RestClient,
must_exist: bool = False,
) -> Union[SyslogServer, None]:
) -> Optional[SyslogServer]:
hypercore_dict = rest_client.get_record(
"/rest/v1/AlertSyslogTarget", {"host": host}, must_exist=must_exist
)
Expand All @@ -138,7 +136,7 @@ def get_by_host(
def get_state(
cls,
rest_client: RestClient,
) -> List[Union[TypedSyslogServerToAnsible, None]]:
) -> List[Optional[TypedSyslogServerToAnsible]]:
state = [
cls.from_hypercore(hypercore_data=hypercore_dict).to_ansible() # type: ignore
for hypercore_dict in rest_client.list_records(
Expand Down
Loading