-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vendor hcloud python dependency (#244)
* chore: ignore venv directories * chore: ignore integration test generated inventory * feat: vendor hcloud package * import https://github.com/hetznercloud/hcloud-python * use vendored hcloud in modules * update integration test requirements * make vendor script self contained * chore: add check-hcloud-vendor pre-commit hook * pin hcloud version to v.1.24.0 * move vendored __version__.py file to _version.py * update comment about galaxy-importer filename lint
- Loading branch information
Showing
84 changed files
with
8,432 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SHELL := bash | ||
.PHONY: vendor clean | ||
|
||
vendor: | ||
python3 scripts/vendor.py | ||
|
||
clean: | ||
git clean -xdf \ | ||
-e tests/integration/cloud-config-hcloud.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
release_summary: | | ||
This release bundles the hcloud dependency in the collection, this allows us to ship | ||
new features or bug fixes without having to release new major versions and require the | ||
users to upgrade their version of the hcloud dependency. | ||
minor_changes: | ||
- Bundle hcloud python dependency inside the collection. | ||
- > | ||
python-dateutil >= 2.7.5 is now required by the collection. If you already have the | ||
hcloud package installed, this dependency should also be installed. | ||
- > | ||
requests >= 2.20 is now required by the collection. If you already have the hcloud | ||
package installed, this dependency should also be installed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from ._exceptions import APIException, HCloudException # noqa | ||
from .hcloud import Client # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class HCloudException(Exception): | ||
"""There was an error while using the hcloud library""" | ||
|
||
|
||
class APIException(HCloudException): | ||
"""There was an error while performing an API Request""" | ||
|
||
def __init__(self, code, message, details): | ||
self.code = code | ||
self.message = message | ||
self.details = details | ||
|
||
def __str__(self): | ||
return self.message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION = "1.24.0" # x-release-please-version |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import time | ||
|
||
from ..core.client import BoundModelBase, ClientEntityBase | ||
from .domain import Action, ActionFailedException, ActionTimeoutException | ||
|
||
|
||
class BoundAction(BoundModelBase): | ||
model = Action | ||
|
||
def wait_until_finished(self, max_retries=100): | ||
"""Wait until the specific action has status="finished" (set Client.poll_interval to specify a delay between checks) | ||
:param max_retries: int | ||
Specify how many retries will be performed before an ActionTimeoutException will be raised | ||
:raises: ActionFailedException when action is finished with status=="error" | ||
:raises: ActionTimeoutException when Action is still in "running" state after max_retries reloads. | ||
""" | ||
while self.status == Action.STATUS_RUNNING: | ||
if max_retries > 0: | ||
self.reload() | ||
time.sleep(self._client._client.poll_interval) | ||
max_retries = max_retries - 1 | ||
else: | ||
raise ActionTimeoutException(action=self) | ||
|
||
if self.status == Action.STATUS_ERROR: | ||
raise ActionFailedException(action=self) | ||
|
||
|
||
class ActionsClient(ClientEntityBase): | ||
results_list_attribute_name = "actions" | ||
|
||
def get_by_id(self, id): | ||
# type: (int) -> BoundAction | ||
"""Get a specific action by its ID. | ||
:param id: int | ||
:return: :class:`BoundAction <hcloud.actions.client.BoundAction>` | ||
""" | ||
|
||
response = self._client.request(url=f"/actions/{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 | ||
:param status: List[str] (optional) | ||
Response will have only actions with specified statuses. Choices: `running` `success` `error` | ||
:param sort: List[str] (optional) | ||
Specify how the results are sorted. Choices: `id` `command` `status` `progress` `started` `finished` . You can add one of ":asc", ":desc" to modify sort order. ( ":asc" is default) | ||
:param page: int (optional) | ||
Specifies the page to fetch | ||
:param per_page: int (optional) | ||
Specifies how many results are returned by page | ||
:return: (List[:class:`BoundAction <hcloud.actions.client.BoundAction>`], :class:`Meta <hcloud.core.domain.Meta>`) | ||
""" | ||
params = {} | ||
if status is not None: | ||
params["status"] = status | ||
if sort is not None: | ||
params["sort"] = sort | ||
if page is not None: | ||
params["page"] = page | ||
if per_page is not None: | ||
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"] | ||
] | ||
return self._add_meta_to_result(actions, response) | ||
|
||
def get_all(self, status=None, sort=None): | ||
# type: (Optional[List[str]], Optional[List[str]]) -> List[BoundAction] | ||
"""Get all actions of the account | ||
:param status: List[str] (optional) | ||
Response will have only actions with specified statuses. Choices: `running` `success` `error` | ||
:param sort: List[str] (optional) | ||
Specify how the results are sorted. Choices: `id` `command` `status` `progress` `started` `finished` . You can add one of ":asc", ":desc" to modify sort order. ( ":asc" is default) | ||
:return: List[:class:`BoundAction <hcloud.actions.client.BoundAction>`] | ||
""" | ||
return super().get_all(status=status, sort=sort) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
try: | ||
from dateutil.parser import isoparse | ||
except ImportError: | ||
isoparse = None | ||
|
||
from .._exceptions import HCloudException | ||
from ..core.domain import BaseDomain | ||
|
||
|
||
class Action(BaseDomain): | ||
"""Action Domain | ||
:param id: int ID of an action | ||
:param command: Command executed in the action | ||
:param status: Status of the action | ||
:param progress: Progress of action in percent | ||
:param started: Point in time when the action was started | ||
:param datetime,None finished: Point in time when the action was finished. Only set if the action is finished otherwise None | ||
:param resources: Resources the action relates to | ||
:param error: Error message for the action if error occurred, otherwise None. | ||
""" | ||
|
||
STATUS_RUNNING = "running" | ||
"""Action Status running""" | ||
STATUS_SUCCESS = "success" | ||
"""Action Status success""" | ||
STATUS_ERROR = "error" | ||
"""Action Status error""" | ||
|
||
__slots__ = ( | ||
"id", | ||
"command", | ||
"status", | ||
"progress", | ||
"resources", | ||
"error", | ||
"started", | ||
"finished", | ||
) | ||
|
||
def __init__( | ||
self, | ||
id, | ||
command=None, | ||
status=None, | ||
progress=None, | ||
started=None, | ||
finished=None, | ||
resources=None, | ||
error=None, | ||
): | ||
self.id = id | ||
self.command = command | ||
|
||
self.status = status | ||
self.progress = progress | ||
self.started = isoparse(started) if started else None | ||
self.finished = isoparse(finished) if finished else None | ||
self.resources = resources | ||
self.error = error | ||
|
||
|
||
class ActionException(HCloudException): | ||
"""A generic action exception""" | ||
|
||
def __init__(self, action): | ||
self.action = action | ||
|
||
|
||
class ActionFailedException(ActionException): | ||
"""The Action you were waiting for failed""" | ||
|
||
|
||
class ActionTimeoutException(ActionException): | ||
"""The Action you were waiting for timed out""" |
Empty file.
Oops, something went wrong.