diff --git a/hcloud/actions/domain.py b/hcloud/actions/domain.py index 6950aea..71f3f3a 100644 --- a/hcloud/actions/domain.py +++ b/hcloud/actions/domain.py @@ -31,7 +31,7 @@ class Action(BaseDomain): STATUS_ERROR = "error" """Action Status error""" - __slots__ = ( + __api_properties__ = ( "id", "command", "status", @@ -41,6 +41,7 @@ class Action(BaseDomain): "started", "finished", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/certificates/domain.py b/hcloud/certificates/domain.py index 20be3e3..2434a74 100644 --- a/hcloud/certificates/domain.py +++ b/hcloud/certificates/domain.py @@ -31,7 +31,7 @@ class Certificate(BaseDomain, DomainIdentityMixin): :param status: ManagedCertificateStatus Current status of a type managed Certificate, always none for type uploaded Certificates """ - __slots__ = ( + __api_properties__ = ( "id", "name", "certificate", @@ -44,6 +44,8 @@ class Certificate(BaseDomain, DomainIdentityMixin): "type", "status", ) + __slots__ = __api_properties__ + TYPE_UPLOADED = "uploaded" TYPE_MANAGED = "managed" @@ -119,7 +121,8 @@ class CreateManagedCertificateResponse(BaseDomain): Shows the progress of the certificate creation """ - __slots__ = ("certificate", "action") + __api_properties__ = ("certificate", "action") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/core/domain.py b/hcloud/core/domain.py index bba954f..d848525 100644 --- a/hcloud/core/domain.py +++ b/hcloud/core/domain.py @@ -2,23 +2,22 @@ class BaseDomain: - __slots__ = () + __api_properties__: tuple @classmethod def from_dict(cls, data: dict): # type: ignore[no-untyped-def] """ Build the domain object from the data dict. """ - supported_data = {k: v for k, v in data.items() if k in cls.__slots__} + supported_data = {k: v for k, v in data.items() if k in cls.__api_properties__} return cls(**supported_data) def __repr__(self) -> str: - kwargs = [f"{key}={getattr(self, key)!r}" for key in self.__slots__] # type: ignore[var-annotated] + kwargs = [f"{key}={getattr(self, key)!r}" for key in self.__api_properties__] # type: ignore[var-annotated] return f"{self.__class__.__qualname__}({', '.join(kwargs)})" class DomainIdentityMixin: - __slots__ = () id: int | None name: str | None @@ -54,7 +53,7 @@ def has_id_or_name(self, id_or_name: int | str) -> bool: class Pagination(BaseDomain): - __slots__ = ( + __api_properties__ = ( "page", "per_page", "previous_page", @@ -62,6 +61,7 @@ class Pagination(BaseDomain): "last_page", "total_entries", ) + __slots__ = __api_properties__ def __init__( self, @@ -81,7 +81,8 @@ def __init__( class Meta(BaseDomain): - __slots__ = ("pagination",) + __api_properties__ = ("pagination",) + __slots__ = __api_properties__ def __init__(self, pagination: Pagination | None = None): self.pagination = pagination diff --git a/hcloud/datacenters/domain.py b/hcloud/datacenters/domain.py index 05d5f79..badd335 100644 --- a/hcloud/datacenters/domain.py +++ b/hcloud/datacenters/domain.py @@ -19,7 +19,8 @@ class Datacenter(BaseDomain, DomainIdentityMixin): :param server_types: :class:`DatacenterServerTypes ` """ - __slots__ = ("id", "name", "description", "location", "server_types") + __api_properties__ = ("id", "name", "description", "location", "server_types") + __slots__ = __api_properties__ def __init__( self, @@ -47,7 +48,8 @@ class DatacenterServerTypes(BaseDomain): All available for migration (change type) server types for this datacenter """ - __slots__ = ("available", "supported", "available_for_migration") + __api_properties__ = ("available", "supported", "available_for_migration") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/deprecation/domain.py b/hcloud/deprecation/domain.py index cd1b536..152a24e 100644 --- a/hcloud/deprecation/domain.py +++ b/hcloud/deprecation/domain.py @@ -17,10 +17,11 @@ class DeprecationInfo(BaseDomain): new servers with this image after the mentioned date. """ - __slots__ = ( + __api_properties__ = ( "announced", "unavailable_after", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/firewalls/domain.py b/hcloud/firewalls/domain.py index 41959ce..e0787ec 100644 --- a/hcloud/firewalls/domain.py +++ b/hcloud/firewalls/domain.py @@ -29,7 +29,8 @@ class Firewall(BaseDomain, DomainIdentityMixin): Point in time when the image was created """ - __slots__ = ("id", "name", "labels", "rules", "applied_to", "created") + __api_properties__ = ("id", "name", "labels", "rules", "applied_to", "created") + __slots__ = __api_properties__ def __init__( self, @@ -66,7 +67,7 @@ class FirewallRule(BaseDomain): Short description of the firewall rule """ - __slots__ = ( + __api_properties__ = ( "direction", "port", "protocol", @@ -74,6 +75,7 @@ class FirewallRule(BaseDomain): "destination_ips", "description", ) + __slots__ = __api_properties__ DIRECTION_IN = "in" """Firewall Rule Direction In""" @@ -138,7 +140,8 @@ class FirewallResource(BaseDomain): applied to. """ - __slots__ = ("type", "server", "label_selector", "applied_to_resources") + __api_properties__ = ("type", "server", "label_selector", "applied_to_resources") + __slots__ = __api_properties__ TYPE_SERVER = "server" """Firewall Used By Type Server""" @@ -177,7 +180,8 @@ class FirewallResourceAppliedToResources(BaseDomain): :param server: Server the Firewall is applied to """ - __slots__ = ("type", "server") + __api_properties__ = ("type", "server") + __slots__ = __api_properties__ def __init__( self, @@ -207,7 +211,8 @@ class CreateFirewallResponse(BaseDomain): The Action which shows the progress of the Firewall Creation """ - __slots__ = ("firewall", "actions") + __api_properties__ = ("firewall", "actions") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/floating_ips/domain.py b/hcloud/floating_ips/domain.py index 78b701f..1b02d8c 100644 --- a/hcloud/floating_ips/domain.py +++ b/hcloud/floating_ips/domain.py @@ -42,7 +42,7 @@ class FloatingIP(BaseDomain, DomainIdentityMixin): Name of the Floating IP """ - __slots__ = ( + __api_properties__ = ( "id", "type", "description", @@ -56,6 +56,7 @@ class FloatingIP(BaseDomain, DomainIdentityMixin): "name", "created", ) + __slots__ = __api_properties__ def __init__( self, @@ -95,7 +96,8 @@ class CreateFloatingIPResponse(BaseDomain): The Action which shows the progress of the Floating IP Creation """ - __slots__ = ("floating_ip", "action") + __api_properties__ = ("floating_ip", "action") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/images/domain.py b/hcloud/images/domain.py index 37d6d9f..497bedb 100644 --- a/hcloud/images/domain.py +++ b/hcloud/images/domain.py @@ -51,7 +51,7 @@ class Image(BaseDomain, DomainIdentityMixin): User-defined labels (key-value pairs) """ - __slots__ = ( + __api_properties__ = ( "id", "name", "type", @@ -70,6 +70,7 @@ class Image(BaseDomain, DomainIdentityMixin): "created", "deprecated", ) + __slots__ = __api_properties__ # pylint: disable=too-many-locals def __init__( @@ -120,7 +121,8 @@ class CreateImageResponse(BaseDomain): The Action which shows the progress of the Floating IP Creation """ - __slots__ = ("action", "image") + __api_properties__ = ("action", "image") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/isos/domain.py b/hcloud/isos/domain.py index b2f4d30..2a5667e 100644 --- a/hcloud/isos/domain.py +++ b/hcloud/isos/domain.py @@ -27,7 +27,7 @@ class Iso(BaseDomain, DomainIdentityMixin): deprecated. If it has a value, it is considered deprecated. """ - __slots__ = ( + __api_properties__ = ( "id", "name", "type", @@ -35,6 +35,7 @@ class Iso(BaseDomain, DomainIdentityMixin): "description", "deprecation", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/load_balancer_types/domain.py b/hcloud/load_balancer_types/domain.py index 35719db..6ef4c28 100644 --- a/hcloud/load_balancer_types/domain.py +++ b/hcloud/load_balancer_types/domain.py @@ -25,7 +25,7 @@ class LoadBalancerType(BaseDomain, DomainIdentityMixin): """ - __slots__ = ( + __api_properties__ = ( "id", "name", "description", @@ -35,6 +35,7 @@ class LoadBalancerType(BaseDomain, DomainIdentityMixin): "max_assigned_certificates", "prices", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/load_balancers/domain.py b/hcloud/load_balancers/domain.py index fdf211a..d1a370a 100644 --- a/hcloud/load_balancers/domain.py +++ b/hcloud/load_balancers/domain.py @@ -52,7 +52,7 @@ class LoadBalancer(BaseDomain, DomainIdentityMixin): Free Traffic for the current billing period in bytes """ - __slots__ = ( + __api_properties__ = ( "id", "name", "public_net", @@ -69,6 +69,7 @@ class LoadBalancer(BaseDomain, DomainIdentityMixin): "ingoing_traffic", "included_traffic", ) + __slots__ = __api_properties__ # pylint: disable=too-many-locals def __init__( @@ -422,7 +423,8 @@ class PublicNetwork(BaseDomain): :param enabled: boolean """ - __slots__ = ("ipv4", "ipv6", "enabled") + __api_properties__ = ("ipv4", "ipv6", "enabled") + __slots__ = __api_properties__ def __init__( self, @@ -442,7 +444,8 @@ class IPv4Address(BaseDomain): The IPv4 Address """ - __slots__ = ("ip", "dns_ptr") + __api_properties__ = ("ip", "dns_ptr") + __slots__ = __api_properties__ def __init__( self, @@ -460,7 +463,8 @@ class IPv6Network(BaseDomain): The IPv6 Network as CIDR Notation """ - __slots__ = ("ip", "dns_ptr") + __api_properties__ = ("ip", "dns_ptr") + __slots__ = __api_properties__ def __init__( self, @@ -480,7 +484,8 @@ class PrivateNet(BaseDomain): The main IP Address of the LoadBalancer in the Network """ - __slots__ = ("network", "ip") + __api_properties__ = ("network", "ip") + __slots__ = __api_properties__ def __init__( self, @@ -500,7 +505,8 @@ class CreateLoadBalancerResponse(BaseDomain): Shows the progress of the Load Balancer creation """ - __slots__ = ("load_balancer", "action") + __api_properties__ = ("load_balancer", "action") + __slots__ = __api_properties__ def __init__( self, @@ -525,7 +531,8 @@ class GetMetricsResponse(BaseDomain): :param metrics: The Load Balancer metrics """ - __slots__ = ("metrics",) + __api_properties__ = ("metrics",) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/locations/domain.py b/hcloud/locations/domain.py index 7d4af22..dcdf7a9 100644 --- a/hcloud/locations/domain.py +++ b/hcloud/locations/domain.py @@ -24,7 +24,7 @@ class Location(BaseDomain, DomainIdentityMixin): Name of network zone this location resides in """ - __slots__ = ( + __api_properties__ = ( "id", "name", "description", @@ -34,6 +34,7 @@ class Location(BaseDomain, DomainIdentityMixin): "longitude", "network_zone", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/metrics/domain.py b/hcloud/metrics/domain.py index 4693f15..cf65571 100644 --- a/hcloud/metrics/domain.py +++ b/hcloud/metrics/domain.py @@ -26,12 +26,13 @@ class Metrics(BaseDomain): step: float time_series: TimeSeries - __slots__ = ( + __api_properties__ = ( "start", "end", "step", "time_series", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/networks/domain.py b/hcloud/networks/domain.py index 2135d5f..58e97c4 100644 --- a/hcloud/networks/domain.py +++ b/hcloud/networks/domain.py @@ -35,7 +35,7 @@ class Network(BaseDomain, DomainIdentityMixin): User-defined labels (key-value pairs) """ - __slots__ = ( + __api_properties__ = ( "id", "name", "ip_range", @@ -47,6 +47,7 @@ class Network(BaseDomain, DomainIdentityMixin): "labels", "created", ) + __slots__ = __api_properties__ def __init__( self, @@ -94,7 +95,9 @@ class NetworkSubnet(BaseDomain): """Subnet Type cloud""" TYPE_VSWITCH = "vswitch" """Subnet Type vSwitch""" - __slots__ = ("type", "ip_range", "network_zone", "gateway", "vswitch_id") + + __api_properties__ = ("type", "ip_range", "network_zone", "gateway", "vswitch_id") + __slots__ = __api_properties__ def __init__( self, @@ -120,7 +123,8 @@ class NetworkRoute(BaseDomain): Gateway for the route. """ - __slots__ = ("destination", "gateway") + __api_properties__ = ("destination", "gateway") + __slots__ = __api_properties__ def __init__(self, destination: str, gateway: str): self.destination = destination @@ -136,7 +140,8 @@ class CreateNetworkResponse(BaseDomain): The Action which shows the progress of the network Creation """ - __slots__ = ("network", "action") + __api_properties__ = ("network", "action") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/placement_groups/domain.py b/hcloud/placement_groups/domain.py index 7b7fcb3..4315140 100644 --- a/hcloud/placement_groups/domain.py +++ b/hcloud/placement_groups/domain.py @@ -28,7 +28,8 @@ class PlacementGroup(BaseDomain, DomainIdentityMixin): Point in time when the image was created """ - __slots__ = ("id", "name", "labels", "servers", "type", "created") + __api_properties__ = ("id", "name", "labels", "servers", "type", "created") + __slots__ = __api_properties__ """Placement Group type spread spreads all servers in the group on different vhosts @@ -61,7 +62,8 @@ class CreatePlacementGroupResponse(BaseDomain): The Action which shows the progress of the Placement Group Creation """ - __slots__ = ("placement_group", "action") + __api_properties__ = ("placement_group", "action") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/primary_ips/domain.py b/hcloud/primary_ips/domain.py index bd47060..7cb0fa6 100644 --- a/hcloud/primary_ips/domain.py +++ b/hcloud/primary_ips/domain.py @@ -43,7 +43,7 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin): Delete the Primary IP when the Assignee it is assigned to is deleted. """ - __slots__ = ( + __api_properties__ = ( "id", "ip", "type", @@ -58,6 +58,7 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin): "assignee_type", "auto_delete", ) + __slots__ = __api_properties__ def __init__( self, @@ -99,7 +100,8 @@ class CreatePrimaryIPResponse(BaseDomain): The Action which shows the progress of the Primary IP Creation """ - __slots__ = ("primary_ip", "action") + __api_properties__ = ("primary_ip", "action") + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/server_types/domain.py b/hcloud/server_types/domain.py index ab2553b..54f9bf4 100644 --- a/hcloud/server_types/domain.py +++ b/hcloud/server_types/domain.py @@ -36,7 +36,7 @@ class ServerType(BaseDomain, DomainIdentityMixin): Free traffic per month in bytes """ - __slots__ = ( + __api_properties__ = ( "id", "name", "description", @@ -51,6 +51,7 @@ class ServerType(BaseDomain, DomainIdentityMixin): "deprecation", "included_traffic", ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/servers/domain.py b/hcloud/servers/domain.py index e886e1a..4f9d80d 100644 --- a/hcloud/servers/domain.py +++ b/hcloud/servers/domain.py @@ -81,7 +81,8 @@ class Server(BaseDomain, DomainIdentityMixin): """Server Status rebuilding""" STATUS_UNKNOWN = "unknown" """Server Status unknown""" - __slots__ = ( + + __api_properties__ = ( "id", "name", "status", @@ -104,6 +105,7 @@ class Server(BaseDomain, DomainIdentityMixin): "primary_disk_size", "placement_group", ) + __slots__ = __api_properties__ # pylint: disable=too-many-locals def __init__( @@ -166,7 +168,8 @@ class CreateServerResponse(BaseDomain): The root password of the server if no SSH-Key was given on server creation """ - __slots__ = ("server", "action", "next_actions", "root_password") + __api_properties__ = ("server", "action", "next_actions", "root_password") + __slots__ = __api_properties__ def __init__( self, @@ -190,7 +193,8 @@ class ResetPasswordResponse(BaseDomain): The root password of the server """ - __slots__ = ("action", "root_password") + __api_properties__ = ("action", "root_password") + __slots__ = __api_properties__ def __init__( self, @@ -210,7 +214,8 @@ class EnableRescueResponse(BaseDomain): The root password of the server in the rescue mode """ - __slots__ = ("action", "root_password") + __api_properties__ = ("action", "root_password") + __slots__ = __api_properties__ def __init__( self, @@ -232,7 +237,8 @@ class RequestConsoleResponse(BaseDomain): VNC password to use for this connection. This password only works in combination with a wss_url with valid token. """ - __slots__ = ("action", "wss_url", "password") + __api_properties__ = ("action", "wss_url", "password") + __slots__ = __api_properties__ def __init__( self, @@ -252,7 +258,8 @@ class RebuildResponse(BaseDomain): :param root_password: The root password of the server when not using SSH keys """ - __slots__ = ("action", "root_password") + __api_properties__ = ("action", "root_password") + __slots__ = __api_properties__ def __init__( self, @@ -274,7 +281,7 @@ class PublicNetwork(BaseDomain): :param firewalls: List[:class:`PublicNetworkFirewall `] """ - __slots__ = ( + __api_properties__ = ( "ipv4", "ipv6", "floating_ips", @@ -282,6 +289,7 @@ class PublicNetwork(BaseDomain): "primary_ipv4", "primary_ipv6", ) + __slots__ = __api_properties__ def __init__( self, @@ -307,7 +315,8 @@ class PublicNetworkFirewall(BaseDomain): :param status: str """ - __slots__ = ("firewall", "status") + __api_properties__ = ("firewall", "status") + __slots__ = __api_properties__ STATUS_APPLIED = "applied" """Public Network Firewall Status applied""" @@ -334,7 +343,8 @@ class IPv4Address(BaseDomain): DNS PTR for the ip """ - __slots__ = ("ip", "blocked", "dns_ptr") + __api_properties__ = ("ip", "blocked", "dns_ptr") + __slots__ = __api_properties__ def __init__( self, @@ -362,7 +372,8 @@ class IPv6Network(BaseDomain): The network mask """ - __slots__ = ("ip", "blocked", "dns_ptr", "network", "network_mask") + __api_properties__ = ("ip", "blocked", "dns_ptr", "network", "network_mask") + __slots__ = __api_properties__ def __init__( self, @@ -391,7 +402,8 @@ class PrivateNet(BaseDomain): The mac address of the interface on the server """ - __slots__ = ("network", "ip", "alias_ips", "mac_address") + __api_properties__ = ("network", "ip", "alias_ips", "mac_address") + __slots__ = __api_properties__ def __init__( self, @@ -415,7 +427,8 @@ class ServerCreatePublicNetwork(BaseDomain): :param enable_ipv6: bool """ - __slots__ = ("ipv4", "ipv6", "enable_ipv4", "enable_ipv6") + __api_properties__ = ("ipv4", "ipv6", "enable_ipv4", "enable_ipv6") + __slots__ = __api_properties__ def __init__( self, @@ -443,7 +456,8 @@ class GetMetricsResponse(BaseDomain): :param metrics: The Server metrics """ - __slots__ = ("metrics",) + __api_properties__ = ("metrics",) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/ssh_keys/domain.py b/hcloud/ssh_keys/domain.py index 09c98ca..8f8bdda 100644 --- a/hcloud/ssh_keys/domain.py +++ b/hcloud/ssh_keys/domain.py @@ -22,7 +22,15 @@ class SSHKey(BaseDomain, DomainIdentityMixin): Point in time when the SSH Key was created """ - __slots__ = ("id", "name", "fingerprint", "public_key", "labels", "created") + __api_properties__ = ( + "id", + "name", + "fingerprint", + "public_key", + "labels", + "created", + ) + __slots__ = __api_properties__ def __init__( self, diff --git a/hcloud/volumes/domain.py b/hcloud/volumes/domain.py index fb793ef..f293437 100644 --- a/hcloud/volumes/domain.py +++ b/hcloud/volumes/domain.py @@ -45,7 +45,7 @@ class Volume(BaseDomain, DomainIdentityMixin): STATUS_AVAILABLE = "available" """Volume Status available""" - __slots__ = ( + __api_properties__ = ( "id", "name", "server", @@ -58,6 +58,7 @@ class Volume(BaseDomain, DomainIdentityMixin): "status", "created", ) + __slots__ = __api_properties__ def __init__( self, @@ -97,7 +98,8 @@ class CreateVolumeResponse(BaseDomain): List of actions that are performed after the creation, like attaching to a server """ - __slots__ = ("volume", "action", "next_actions") + __api_properties__ = ("volume", "action", "next_actions") + __slots__ = __api_properties__ def __init__( self, diff --git a/tests/unit/core/test_client.py b/tests/unit/core/test_client.py index 584af8c..3155eed 100644 --- a/tests/unit/core/test_client.py +++ b/tests/unit/core/test_client.py @@ -13,7 +13,8 @@ class TestBoundModelBase: @pytest.fixture() def bound_model_class(self): class Model(BaseDomain): - __slots__ = ("id", "name", "description") + __api_properties__ = ("id", "name", "description") + __slots__ = __api_properties__ def __init__(self, id, name="", description=""): self.id = id diff --git a/tests/unit/core/test_domain.py b/tests/unit/core/test_domain.py index fabf762..d5e588f 100644 --- a/tests/unit/core/test_domain.py +++ b/tests/unit/core/test_domain.py @@ -42,7 +42,8 @@ def test_parse_meta_json_ok(self): class SomeDomain(BaseDomain, DomainIdentityMixin): - __slots__ = ("id", "name") + __api_properties__ = ("id", "name") + __slots__ = __api_properties__ def __init__(self, id=None, name=None): self.id = id @@ -86,7 +87,8 @@ def test_has_id_or_name_exception(self, other, expected): class ActionDomain(BaseDomain, DomainIdentityMixin): - __slots__ = ("id", "name", "started") + __api_properties__ = ("id", "name", "started") + __slots__ = __api_properties__ def __init__(self, id, name="name1", started=None): self.id = id @@ -95,7 +97,8 @@ def __init__(self, id, name="name1", started=None): class SomeOtherDomain(BaseDomain): - __slots__ = ("id", "name", "child") + __api_properties__ = ("id", "name", "child") + __slots__ = __api_properties__ def __init__(self, id=None, name=None, child=None): self.id = id