Skip to content

Commit

Permalink
Fix crash on extra fields in response (#142)
Browse files Browse the repository at this point in the history
* Fix crash on extra fields in public_net response

* Run black for code formatting

* Update CHANGELOG
  • Loading branch information
Adi146 authored Aug 10, 2021
1 parent da8ec1f commit 593baef
Show file tree
Hide file tree
Showing 91 changed files with 4,519 additions and 3,983 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements/test.txt
pip install tox tox-gh-actions
- name: Test with tox
sudo apt install build-essential
- name: flake8 with tox
run: tox -e flake8
- name: black with tox
run: tox -e black
1 change: 1 addition & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements/test.txt
pip install tox tox-gh-actions
sudo apt install build-essential
- name: Test with tox
run: tox
env:
Expand Down
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ stages:
.tests_template: &tests_template
before_script:
- pip install tox
- apk add build-base
stage: test
script:
tox
Expand Down Expand Up @@ -36,9 +37,8 @@ python310:
script: tox -e py310

test-style:
before_script:
- pip install tox
<<: *tests_template
image: python:3.7-alpine
script: tox -e flake8
tags:
- hc-bladerunner
script:
- tox -e flake8
- tox -e black
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

v1.14.1 (2021-08-10)
---------------------
* Bugfix: Fix crash on extra fields in public_net response
* Improvement: Format code with black

v1.14.0 (2021-08-03)
---------------------
* Feature: Add support for Firewall rule descriptions
Expand Down
57 changes: 28 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import sys

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
from hcloud.__version__ import VERSION # noqa

# -- General configuration ---------------------------------------------
Expand All @@ -32,10 +32,10 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
Expand All @@ -44,10 +44,10 @@
# source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

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

Expand All @@ -70,10 +70,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -87,41 +87,38 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_logo = '_static/logo-hetzner-online.svg'
html_theme = "sphinx_rtd_theme"
html_logo = "_static/logo-hetzner-online.svg"
# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'logo_only': True,
"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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# -- Options for HTMLHelp output ---------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'hclouddoc'
htmlhelp_basename = "hclouddoc"

# -- Options for LaTeX output ------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -131,32 +128,34 @@
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(master_doc, 'hcloud.tex',
u'Hetzner Cloud Python Documentation',
u'Hetzner Cloud GmbH', 'manual'),
(
master_doc,
"hcloud.tex",
u"Hetzner Cloud Python Documentation",
u"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, u"Hetzner Cloud Python Documentation", [author], 1)]

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

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc,
u'Hetzner Cloud Python Documentation',
author,
'HCloud-python is a library for the Hetzner Cloud API.',
'Miscellaneous'),
(
master_doc,
u"Hetzner Cloud Python Documentation",
author,
"HCloud-python is a library for the Hetzner Cloud API.",
"Miscellaneous",
),
]

source_suffix = ['.rst']
source_suffix = [".rst"]
8 changes: 6 additions & 2 deletions examples/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType

client = Client(token="{YOUR_API_TOKEN}") # Please paste your API token here between the quotes
response = client.servers.create(name="my-server", server_type=ServerType("cx11"), image=Image(name="ubuntu-20.04"))
client = Client(
token="{YOUR_API_TOKEN}"
) # Please paste your API token here between the quotes
response = client.servers.create(
name="my-server", server_type=ServerType("cx11"), image=Image(name="ubuntu-20.04")
)
server = response.server
print(server)
print("Root Password" + response.root_password)
4 changes: 3 additions & 1 deletion examples/list_servers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from hcloud import Client

client = Client(token="{YOUR_API_TOKEN}") # Please paste your API token here between the quotes
client = Client(
token="{YOUR_API_TOKEN}"
) # Please paste your API token here between the quotes
servers = client.servers.get_all()
print(servers)
20 changes: 4 additions & 16 deletions examples/usage_oop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
# Create 2 servers
# Create 2 servers
response1 = client.servers.create(
"Server1",
server_type=ServerType(name="cx11"),
image=Image(id=4711)
"Server1", server_type=ServerType(name="cx11"), image=Image(id=4711)
)

response2 = client.servers.create(
"Server2",
server_type=ServerType(name="cx11"),
image=Image(id=4711)
"Server2", server_type=ServerType(name="cx11"), image=Image(id=4711)
)
# Get all servers
server1 = response1.server
Expand All @@ -28,16 +24,8 @@
assert servers[1].id == server2.id
# Create 2 volumes

response1 = client.volumes.create(
size=15,
name="Volume1",
location=server1.location
)
response2 = client.volumes.create(
size=10,
name="Volume2",
location=server2.location
)
response1 = client.volumes.create(size=15, name="Volume1", location=server1.location)
response2 = client.volumes.create(size=10, name="Volume2", location=server2.location)

volume1 = response1.volume
volume2 = response2.volume
Expand Down
28 changes: 6 additions & 22 deletions examples/usage_procedurale.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

# Create 2 servers
response1 = client.servers.create(
name="Server1",
server_type=ServerType(name="cx11"),
image=Image(id=4711)
name="Server1", server_type=ServerType(name="cx11"), image=Image(id=4711)
)

response2 = client.servers.create(
"Server2",
server_type=ServerType(name="cx11"),
image=Image(id=4711)
"Server2", server_type=ServerType(name="cx11"), image=Image(id=4711)
)

server1 = response1.server
Expand All @@ -32,16 +28,8 @@

# Create 2 volumes

response1 = client.volumes.create(
size=15,
name="Volume1",
location=server1.location
)
response2 = client.volumes.create(
size=10,
name="Volume2",
location=server2.location
)
response1 = client.volumes.create(size=15, name="Volume1", location=server1.location)
response2 = client.volumes.create(size=10, name="Volume2", location=server2.location)

volume1 = response1.volume
volume2 = response2.volume
Expand All @@ -61,11 +49,7 @@
# Create one more volume and attach it to server with id=33

server33 = Server(id=33)
response = client.volumes.create(
size=33,
name="Volume33",
server=server33
)
response = client.volumes.create(size=33, name="Volume33", server=server33)

print(response.action.status)

Expand All @@ -74,5 +58,5 @@
"Server3",
server_type=ServerType(name="cx11"),
image=Image(id=4711),
volumes = [Volume(id=221), Volume(id=222)]
volumes=[Volume(id=221), Volume(id=222)],
)
2 changes: 1 addition & 1 deletion hcloud/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.13.0'
VERSION = "1.13.0"
27 changes: 16 additions & 11 deletions hcloud/actions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def wait_until_finished(self, max_retries=100):


class ActionsClient(ClientEntityBase):
results_list_attribute_name = 'actions'
results_list_attribute_name = "actions"

def get_by_id(self, id):
# type: (int) -> BoundAction
Expand All @@ -39,15 +39,18 @@ def get_by_id(self, id):
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
"""

response = self._client.request(url="/actions/{action_id}".format(action_id=id), method="GET")
return BoundAction(self, response['action'])

def get_list(self,
status=None, # type: Optional[List[str]]
sort=None, # type: Optional[List[str]]
page=None, # type: Optional[int]
per_page=None, # type: Optional[int]
):
response = self._client.request(
url="/actions/{action_id}".format(action_id=id), method="GET"
)
return BoundAction(self, response["action"])

def get_list(
self,
status=None, # type: Optional[List[str]]
sort=None, # type: Optional[List[str]]
page=None, # type: Optional[int]
per_page=None, # type: Optional[int]
):
# type: (...) -> PageResults[List[BoundAction]]
"""Get a list of actions from this account
Expand All @@ -72,7 +75,9 @@ def get_list(self,
params["per_page"] = per_page

response = self._client.request(url="/actions", method="GET", params=params)
actions = [BoundAction(self, action_data) for action_data in response['actions']]
actions = [
BoundAction(self, action_data) for action_data in response["actions"]
]
return self._add_meta_to_result(actions, response)

def get_all(self, status=None, sort=None):
Expand Down
Loading

0 comments on commit 593baef

Please sign in to comment.