Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions hcloud/images/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def __init__(self, client, data):

super(BoundImage, self).__init__(client, data)

def get_actions_list(self, sort=None, page=None, per_page=None):
# type: (Optional[List[str]], Optional[int], Optional[int]) -> PageResult[BoundAction, Meta]
def get_actions_list(self, sort=None, page=None, per_page=None, status=None):
# type: (Optional[List[str]], Optional[int], Optional[int], Optional[List[str]]) -> PageResult[BoundAction, Meta]
"""Returns a list of action objects for the image.

: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` `id:asc` `id:desc` `command` `command:asc` `command:desc` `status` `status:asc` `status:desc` `progress` `progress:asc` `progress:desc` `started` `started:asc` `started:desc` `finished` `finished:asc` `finished:desc`
:param page: int (optional)
Expand All @@ -32,17 +34,19 @@ def get_actions_list(self, sort=None, page=None, per_page=None):
Specifies how many results are returned by page
:return: (List[:class:`BoundAction <hcloud.actions.client.BoundAction>`], :class:`Meta <hcloud.core.domain.Meta>`)
"""
return self._client.get_actions_list(self, sort, page, per_page)
return self._client.get_actions_list(self, sort=sort, page=page, per_page=per_page, status=status)

def get_actions(self, sort=None):
# type: (Optional[List[str]]) -> List[BoundAction]
def get_actions(self, sort=None, status=None):
# type: (Optional[List[str]], Optional[List[str]]) -> List[BoundAction]
"""Returns all action objects for the image.

: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` `id:asc` `id:desc` `command` `command:asc` `command:desc` `status` `status:asc` `status:desc` `progress` `progress:asc` `progress:desc` `started` `started:asc` `started:desc` `finished` `finished:asc` `finished:desc`
:return: List[:class:`BoundAction <hcloud.actions.client.BoundAction>`]
"""
return self._client.get_actions(self, sort)
return self._client.get_actions(self, status=status, sort=sort)

def update(self, description=None, type=None, labels=None):
# type: (Optional[str], Optional[Dict[str, str]]) -> BoundImage
Expand Down Expand Up @@ -85,12 +89,15 @@ def get_actions_list(self,
image, # type: Image
sort=None, # type: Optional[List[str]]
page=None, # type: Optional[int]
per_page=None # type: Optional[int]
per_page=None, # type: Optional[int]
status=None, # type: Optional[List[str]]
):
# type: (...) -> PageResults[List[BoundAction], Meta]
"""Returns a list of action objects for an image.

:param image: :class:`BoundImage <hcloud.images.client.BoundImage>` or :class:`Image <hcloud.images.domain.Image>`
: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` `id:asc` `id:desc` `command` `command:asc` `command:desc` `status` `status:asc` `status:desc` `progress` `progress:asc` `progress:desc` `started` `started:asc` `started:desc` `finished` `finished:asc` `finished:desc`
:param page: int (optional)
Expand All @@ -102,6 +109,8 @@ def get_actions_list(self,
params = {}
if sort is not None:
params["sort"] = sort
if status is not None:
params["status"] = status
if page is not None:
params["page"] = page
if per_page is not None:
Expand All @@ -112,17 +121,20 @@ def get_actions_list(self,

def get_actions(self,
image, # type: Image
sort=None, # type: Optional[List[str]]
sort=None, # type: Optional[List[str]]
status=None, # type: Optional[List[str]]
):
# type: (...) -> List[BoundAction]
"""Returns all action objects for an image.

:param image: :class:`BoundImage <hcloud.images.client.BoundImage>` or :class:`Image <hcloud.images.domain.Image>`
: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(ImagesClient, self).get_actions(image, sort=sort)
return super(ImagesClient, self).get_actions(image, sort=sort, status=status)

def get_by_id(self, id):
# type: (int) -> BoundImage
Expand All @@ -141,7 +153,8 @@ def get_list(self,
type=None, # type: Optional[List[str]]
sort=None, # type: Optional[List[str]]
page=None, # type: Optional[int]
per_page=None # type: Optional[int]
per_page=None, # type: Optional[int]
status=None # type: Optional[List[str]]
):
# type: (...) -> PageResults[List[BoundImage]]
"""Get all images
Expand All @@ -154,6 +167,8 @@ def get_list(self,
Server Id linked to the image. Only available for images of type backup
:param type: List[str] (optional)
Choices: system snapshot backup
:param status: List[str] (optional)
Can be used to filter images by their status. The response will only contain images matching the status.
:param sort: List[str] (optional)
Choices: id id:asc id:desc name name:asc name:desc created created:asc created:desc
:param page: int (optional)
Expand All @@ -177,6 +192,8 @@ def get_list(self,
params['page'] = page
if per_page:
params['per_page'] = per_page
if status:
params['status'] = per_page

response = self._client.request(url="/images", method="GET", params=params)
images = [BoundImage(self, image_data) for image_data in response['images']]
Expand All @@ -189,6 +206,7 @@ def get_all(self,
bound_to=None, # type: Optional[List[str]]
type=None, # type: Optional[List[str]]
sort=None, # type: Optional[List[str]]
status=None, # type: Optional[List[str]]
):
# type: (...) -> List[BoundImage]
"""Get all images
Expand All @@ -201,11 +219,13 @@ def get_all(self,
Server Id linked to the image. Only available for images of type backup
:param type: List[str] (optional)
Choices: system snapshot backup
:param status: List[str] (optional)
Can be used to filter images by their status. The response will only contain images matching the status.
:param sort: List[str] (optional)
Choices: id name created (You can add one of ":asc", ":desc" to modify sort order. ( ":asc" is default))
:return: List[:class:`BoundImage <hcloud.images.client.BoundImage>`]
"""
return super(ImagesClient, self).get_all(name=name, label_selector=label_selector, bound_to=bound_to, type=type, sort=sort)
return super(ImagesClient, self).get_all(name=name, label_selector=label_selector, bound_to=bound_to, type=type, sort=sort, status=status)

def get_by_name(self, name):
# type: (str) -> BoundImage
Expand Down
15 changes: 11 additions & 4 deletions hcloud/servers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def get_list(self,
name=None, # type: Optional[str]
label_selector=None, # type: Optional[str]
page=None, # type: Optional[int]
per_page=None # type: Optional[int]
per_page=None, # type: Optional[int]
status=None, # type: Optional[List[str]]
):
# type: (...) -> PageResults[List[BoundServer], Meta]
"""Get a list of servers from this account
Expand All @@ -296,6 +297,8 @@ def get_list(self,
Can be used to filter servers by their name.
:param label_selector: str (optional)
Can be used to filter servers by labels. The response will only contain servers matching the label selector.
:param status: List[str] (optional)
Can be used to filter servers by their status. The response will only contain servers matching the status.
:param page: int (optional)
Specifies the page to fetch
:param per_page: int (optional)
Expand All @@ -307,6 +310,8 @@ def get_list(self,
params['name'] = name
if label_selector:
params['label_selector'] = label_selector
if status:
params["status"] = status
if page:
params['page'] = page
if per_page:
Expand All @@ -317,17 +322,19 @@ def get_list(self,
ass_servers = [BoundServer(self, server_data) for server_data in response['servers']]
return self._add_meta_to_result(ass_servers, response)

def get_all(self, name=None, label_selector=None):
# type: (Optional[str], Optional[str]) -> List[BoundServer]
def get_all(self, name=None, label_selector=None, status=None):
# type: (Optional[str], Optional[str], Optional[List[str]]) -> List[BoundServer]
"""Get all servers from this account

:param name: str (optional)
Can be used to filter servers by their name.
:param label_selector: str (optional)
Can be used to filter servers by labels. The response will only contain servers matching the label selector.
:param status: List[str] (optional)
Can be used to filter servers by their status. The response will only contain servers matching the status.
:return: List[:class:`BoundServer <hcloud.servers.client.BoundServer>`]
"""
return super(ServersClient, self).get_all(name=name, label_selector=label_selector)
return super(ServersClient, self).get_all(name=name, label_selector=label_selector, status=status)

def get_by_name(self, name):
# type: (str) -> BoundServer
Expand Down
19 changes: 13 additions & 6 deletions hcloud/volumes/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ def get_by_id(self, id):
response = self._client.request(url="/volumes/{volume_id}".format(volume_id=id), method="GET")
return BoundVolume(self, response['volume'])

def get_list(self, name=None, label_selector=None, page=None, per_page=None):
# type: (Optional[str], Optional[str], Optional[int], Optional[int]) -> PageResults[List[BoundVolume], Meta]
def get_list(self, name=None, label_selector=None, page=None, per_page=None, status=None):
# type: (Optional[str], Optional[str], Optional[int], Optional[int], Optional[List[str]]) -> PageResults[List[BoundVolume], Meta]
"""Get a list of volumes from this account

:param name: str (optional)
Can be used to filter volumes by their name.
:param label_selector: str (optional)
Can be used to filter volumes by labels. The response will only contain volumes matching the label selector.
:param status: List[str] (optional)
Can be used to filter volumes by their status. The response will only contain volumes matching the status.
:param page: int (optional)
Specifies the page to fetch
:param per_page: int (optional)
Expand All @@ -140,6 +142,8 @@ def get_list(self, name=None, label_selector=None, page=None, per_page=None):
params['name'] = name
if label_selector:
params['label_selector'] = label_selector
if status:
params["status"] = status
if page is not None:
params['page'] = page
if per_page is not None:
Expand All @@ -149,14 +153,17 @@ def get_list(self, name=None, label_selector=None, page=None, per_page=None):
volumes = [BoundVolume(self, volume_data) for volume_data in response['volumes']]
return self._add_meta_to_result(volumes, response)

def get_all(self, label_selector=None):
# type: (Optional[str]) -> List[BoundVolume]
def get_all(self, label_selector=None, status=None):
# type: (Optional[str], Optional[List[str]]) -> List[BoundVolume]
"""Get all volumes from this account

:param label_selector:
Can be used to filter volumes by labels. The response will only contain volumes matching the label selector.
:param status: List[str] (optional)
Can be used to filter volumes by their status. The response will only contain volumes matching the status.
:return: List[:class:`BoundVolume <hcloud.volumes.client.BoundVolume>`]
"""
return super(VolumesClient, self).get_all(label_selector=label_selector)
return super(VolumesClient, self).get_all(label_selector=label_selector, status=status)

def get_by_name(self, name):
# type: (str) -> BoundVolume
Expand Down Expand Up @@ -267,7 +274,7 @@ def get_actions(self, volume, status=None, sort=None):
Specify how the results are sorted. Choices: `id` `id:asc` `id:desc` `command` `command:asc` `command:desc` `status` `status:asc` `status:desc` `progress` `progress:asc` `progress:desc` `started` `started:asc` `started:desc` `finished` `finished:asc` `finished:desc`
:return: List[:class:`BoundAction <hcloud.actions.client.BoundAction>`]
"""
return super(VolumesClient, self).get_actions(volume, sort=sort)
return super(VolumesClient, self).get_actions(volume, status=status, sort=sort)

def update(self, volume, name=None, labels=None):
# type:(Union[Volume, BoundVolume], Optional[str], Optional[Dict[str, str]]) -> BoundVolume
Expand Down