File: domain.py

package info (click to toggle)
hcloud-python 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,396 kB
  • sloc: python: 15,311; makefile: 43; javascript: 3
file content (172 lines) | stat: -rw-r--r-- 5,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

from dateutil.parser import isoparse

from ..core import BaseDomain, DomainIdentityMixin

if TYPE_CHECKING:
    from ..actions import BoundAction
    from ..servers import BoundServer
    from .client import BoundNetwork


class Network(BaseDomain, DomainIdentityMixin):
    """Network Domain

    :param id: int
           ID of the network
    :param name: str
           Name of the network
    :param ip_range: str
           IPv4 prefix of the whole network
    :param subnets: List[:class:`NetworkSubnet <hcloud.networks.domain.NetworkSubnet>`]
           Subnets allocated in this network
    :param routes: List[:class:`NetworkRoute <hcloud.networks.domain.NetworkRoute>`]
           Routes set in this network
    :param expose_routes_to_vswitch: bool
           Indicates if the routes from this network should be exposed to the vSwitch connection.
    :param servers: List[:class:`BoundServer <hcloud.servers.client.BoundServer>`]
           Servers attached to this network
    :param protection: dict
           Protection configuration for the network
    :param labels: dict
           User-defined labels (key-value pairs)
    """

    __api_properties__ = (
        "id",
        "name",
        "ip_range",
        "subnets",
        "routes",
        "expose_routes_to_vswitch",
        "servers",
        "protection",
        "labels",
        "created",
    )
    __slots__ = __api_properties__

    def __init__(
        self,
        id: int,
        name: str | None = None,
        created: str | None = None,
        ip_range: str | None = None,
        subnets: list[NetworkSubnet] | None = None,
        routes: list[NetworkRoute] | None = None,
        expose_routes_to_vswitch: bool | None = None,
        servers: list[BoundServer] | None = None,
        protection: dict | None = None,
        labels: dict[str, str] | None = None,
    ):
        self.id = id
        self.name = name
        self.created = isoparse(created) if created else None
        self.ip_range = ip_range
        self.subnets = subnets
        self.routes = routes
        self.expose_routes_to_vswitch = expose_routes_to_vswitch
        self.servers = servers
        self.protection = protection
        self.labels = labels


class NetworkSubnet(BaseDomain):
    """Network Subnet Domain

    :param type: str
              Type of sub network.
    :param ip_range: str
              Range to allocate IPs from.
    :param network_zone: str
              Name of network zone.
    :param gateway: str
              Gateway for the route.
    :param vswitch_id: int
              ID of the vSwitch.
    """

    @property
    def TYPE_SERVER(self) -> str:  # pylint: disable=invalid-name
        """
        Used to connect cloud servers and load balancers.

        .. deprecated:: 2.2.0
            Use :attr:`NetworkSubnet.TYPE_CLOUD` instead.
        """
        warnings.warn(
            "The 'NetworkSubnet.TYPE_SERVER' property is deprecated, please use the `NetworkSubnet.TYPE_CLOUD` property instead.",
            DeprecationWarning,
            stacklevel=2,
        )
        return "server"

    TYPE_CLOUD = "cloud"
    """
    Used to connect cloud servers and load balancers.
    """
    TYPE_VSWITCH = "vswitch"
    """
    Used to connect cloud servers and load balancers with dedicated servers.

    See https://docs.hetzner.com/cloud/networks/connect-dedi-vswitch/
    """

    __api_properties__ = ("type", "ip_range", "network_zone", "gateway", "vswitch_id")
    __slots__ = __api_properties__

    def __init__(
        self,
        ip_range: str,
        type: str | None = None,
        network_zone: str | None = None,
        gateway: str | None = None,
        vswitch_id: int | None = None,
    ):
        self.type = type
        self.ip_range = ip_range
        self.network_zone = network_zone
        self.gateway = gateway
        self.vswitch_id = vswitch_id


class NetworkRoute(BaseDomain):
    """Network Route Domain

    :param destination: str
           Destination network or host of this route.
    :param gateway: str
           Gateway for the route.
    """

    __api_properties__ = ("destination", "gateway")
    __slots__ = __api_properties__

    def __init__(self, destination: str, gateway: str):
        self.destination = destination
        self.gateway = gateway


class CreateNetworkResponse(BaseDomain):
    """Create Network Response Domain

    :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>`
           The network which was created
    :param action: :class:`BoundAction <hcloud.actions.client.BoundAction>`
           The Action which shows the progress of the network Creation
    """

    __api_properties__ = ("network", "action")
    __slots__ = __api_properties__

    def __init__(
        self,
        network: BoundNetwork,
        action: BoundAction,
    ):
        self.network = network
        self.action = action