Skip to content

Commit

Permalink
Add primary IP support (#160)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Kämmerling <[email protected]>

Co-authored-by: Vanderson Mota dos Santos <[email protected]>
  • Loading branch information
LKaemmerling and Vanderson Mota dos Santos authored Jun 29, 2022
1 parent fad8707 commit 08f3a40
Show file tree
Hide file tree
Showing 31 changed files with 1,159 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10.0-beta.1" ]
python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10" ]
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 13 additions & 0 deletions docs/api.clients.primary_ips.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PrimaryIPsClient
==================


.. autoclass:: hcloud.primary_ips.client.PrimaryIPsClient
:members:

.. autoclass:: hcloud.primary_ips.client.BoundPrimaryIP
:members:

.. autoclass:: hcloud.primary_ips.domain.PrimaryIP
:members:

3 changes: 3 additions & 0 deletions docs/api.clients.servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ ServersClient
.. autoclass:: hcloud.servers.domain.CreateServerResponse
:members:

.. autoclass:: hcloud.servers.domain.ServerCreatePublicNetwork
:members:

.. autoclass:: hcloud.servers.domain.ResetPasswordResponse
:members:

Expand Down
22 changes: 10 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
master_doc = "index"

# General information about the project.
project = u"Hetzner Cloud Python"
copyright = u"2019, Hetzner Cloud GmbH"
author = u"Hetzner Cloud GmbH"
project = "Hetzner Cloud Python"
copyright = "2019, Hetzner Cloud GmbH"
author = "Hetzner Cloud GmbH"

# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
Expand Down Expand Up @@ -93,9 +93,7 @@
# theme further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
"logo_only": True,
}
html_theme_options = {"logo_only": True}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down Expand Up @@ -131,17 +129,17 @@
(
master_doc,
"hcloud.tex",
u"Hetzner Cloud Python Documentation",
u"Hetzner Cloud GmbH",
"Hetzner Cloud Python Documentation",
"Hetzner Cloud GmbH",
"manual",
),
)
]

# -- Options for manual page output ------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, u"Hetzner Cloud Python Documentation", [author], 1)]
man_pages = [(master_doc, "Hetzner Cloud Python Documentation", [author], 1)]

# -- Options for Texinfo output ----------------------------------------

Expand All @@ -151,11 +149,11 @@
texinfo_documents = [
(
master_doc,
u"Hetzner Cloud Python Documentation",
"Hetzner Cloud Python Documentation",
author,
"HCloud-python is a library for the Hetzner Cloud API.",
"Miscellaneous",
),
)
]

source_suffix = [".rst"]
5 changes: 1 addition & 4 deletions hcloud/certificates/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ class CreateManagedCertificateResponse(BaseDomain):
Shows the progress of the certificate creation
"""

__slots__ = (
"certificate",
"action",
)
__slots__ = ("certificate", "action")

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions hcloud/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _get_all(
**kwargs
):
# type (...) -> List[BoundModelBase]

page = 1

results = []
Expand Down
5 changes: 1 addition & 4 deletions hcloud/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ class Meta(BaseDomain):

__slots__ = ("pagination",)

def __init__(
self,
pagination=None,
):
def __init__(self, pagination=None):
self.pagination = pagination

@classmethod
Expand Down
8 changes: 1 addition & 7 deletions hcloud/datacenters/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ class Datacenter(BaseDomain, DomainIdentityMixin):
:param server_types: :class:`DatacenterServerTypes <hcloud.datacenters.domain.DatacenterServerTypes>`
"""

__slots__ = (
"id",
"name",
"description",
"location",
"server_types",
)
__slots__ = ("id", "name", "description", "location", "server_types")

def __init__(
self, id=None, name=None, description=None, location=None, server_types=None
Expand Down
4 changes: 1 addition & 3 deletions hcloud/firewalls/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def __init__(
self.label_selector = label_selector

def to_payload(self):
payload = {
"type": self.type,
}
payload = {"type": self.type}
if self.server is not None:
payload.update({"server": {"id": self.server.id}})

Expand Down
6 changes: 6 additions & 0 deletions hcloud/hcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from hcloud.actions.client import ActionsClient
from hcloud.certificates.client import CertificatesClient
from hcloud.floating_ips.client import FloatingIPsClient
from hcloud.primary_ips.client import PrimaryIPsClient
from hcloud.networks.client import NetworksClient
from hcloud.isos.client import IsosClient
from hcloud.servers.client import ServersClient
Expand Down Expand Up @@ -121,6 +122,11 @@ def __init__(
:type: :class:`FloatingIPsClient <hcloud.floating_ips.client.FloatingIPsClient>`
"""
self.primary_ips = PrimaryIPsClient(self)
"""PrimaryIPsClient Instance
:type: :class:`PrimaryIPsClient <hcloud.primary_ips.client.PrimaryIPsClient>`
"""
self.networks = NetworksClient(self)
"""NetworksClient Instance
Expand Down
7 changes: 1 addition & 6 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class Iso(BaseDomain, DomainIdentityMixin):
__slots__ = ("id", "name", "type", "description", "deprecated")

def __init__(
self,
id=None,
name=None,
type=None,
description=None,
deprecated=None,
self, id=None, name=None, type=None, description=None, deprecated=None
):
self.id = id
self.name = name
Expand Down
16 changes: 4 additions & 12 deletions hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,7 @@ def delete_service(self, load_balancer, service):
The LoadBalancerService you want to delete from the Load Balancer
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"listen_port": service.listen_port,
}
data = {"listen_port": service.listen_port}

response = self._client.request(
url="/load_balancers/{load_balancer_id}/actions/delete_service".format(
Expand Down Expand Up @@ -732,9 +730,7 @@ def remove_target(self, load_balancer, target):
The LoadBalancerTarget you want to remove from the Load Balancer
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"type": target.type,
}
data = {"type": target.type}
if target.type == "server":
data["server"] = {"id": target.server.id}
elif target.type == "label_selector":
Expand Down Expand Up @@ -848,9 +844,7 @@ def detach_from_network(self, load_balancer, network):
:param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"network": network.id,
}
data = {"network": network.id}
response = self._client.request(
url="/load_balancers/{load_balancer_id}/actions/detach_from_network".format(
load_balancer_id=load_balancer.id
Expand Down Expand Up @@ -903,9 +897,7 @@ def change_type(self, load_balancer, load_balancer_type):
Load Balancer type the Load Balancer should migrate to
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"load_balancer_type": load_balancer_type.id_or_name,
}
data = {"load_balancer_type": load_balancer_type.id_or_name}
response = self._client.request(
url="/load_balancers/{load_balancer_id}/actions/change_type".format(
load_balancer_id=load_balancer.id
Expand Down
20 changes: 4 additions & 16 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ class IPv4Address(BaseDomain):
The IPv4 Address
"""

__slots__ = (
"ip",
"dns_ptr",
)
__slots__ = ("ip", "dns_ptr")

def __init__(
self,
Expand All @@ -320,10 +317,7 @@ class IPv6Network(BaseDomain):
The IPv6 Network as CIDR Notation
"""

__slots__ = (
"ip",
"dns_ptr",
)
__slots__ = ("ip", "dns_ptr")

def __init__(
self,
Expand All @@ -343,10 +337,7 @@ class PrivateNet(BaseDomain):
The main IP Address of the LoadBalancer in the Network
"""

__slots__ = (
"network",
"ip",
)
__slots__ = ("network", "ip")

def __init__(
self,
Expand All @@ -366,10 +357,7 @@ class CreateLoadBalancerResponse(BaseDomain):
Shows the progress of the Load Balancer creation
"""

__slots__ = (
"load_balancer",
"action",
)
__slots__ = ("load_balancer", "action")

def __init__(
self,
Expand Down
23 changes: 5 additions & 18 deletions hcloud/networks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ def add_subnet(self, network, subnet):
The NetworkSubnet you want to add to the Network
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"type": subnet.type,
"network_zone": subnet.network_zone,
}
data = {"type": subnet.type, "network_zone": subnet.network_zone}
if subnet.ip_range is not None:
data["ip_range"] = subnet.ip_range
if subnet.vswitch_id is not None:
Expand All @@ -385,9 +382,7 @@ def delete_subnet(self, network, subnet):
The NetworkSubnet you want to remove from the Network
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"ip_range": subnet.ip_range,
}
data = {"ip_range": subnet.ip_range}

response = self._client.request(
url="/networks/{network_id}/actions/delete_subnet".format(
Expand All @@ -407,10 +402,7 @@ def add_route(self, network, route):
The NetworkRoute you want to add to the Network
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"destination": route.destination,
"gateway": route.gateway,
}
data = {"destination": route.destination, "gateway": route.gateway}

response = self._client.request(
url="/networks/{network_id}/actions/add_route".format(
Expand All @@ -430,10 +422,7 @@ def delete_route(self, network, route):
The NetworkRoute you want to remove from the Network
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"destination": route.destination,
"gateway": route.gateway,
}
data = {"destination": route.destination, "gateway": route.gateway}

response = self._client.request(
url="/networks/{network_id}/actions/delete_route".format(
Expand All @@ -453,9 +442,7 @@ def change_ip_range(self, network, ip_range):
The new prefix for the whole network.
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""
data = {
"ip_range": ip_range,
}
data = {"ip_range": ip_range}

response = self._client.request(
url="/networks/{network_id}/actions/change_ip_range".format(
Expand Down
1 change: 1 addition & 0 deletions hcloud/primary_ips/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
Loading

0 comments on commit 08f3a40

Please sign in to comment.