diff --git a/hcloud/images/client.py b/hcloud/images/client.py index f7425dfe..988cf716 100644 --- a/hcloud/images/client.py +++ b/hcloud/images/client.py @@ -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) @@ -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 `], :class:`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 `] """ - 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 @@ -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 ` or :class:`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) @@ -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: @@ -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 ` or :class:`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 `] """ - 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 @@ -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 @@ -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) @@ -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']] @@ -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 @@ -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 `] """ - 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 diff --git a/hcloud/servers/client.py b/hcloud/servers/client.py index 5677d3ef..75d5be4d 100644 --- a/hcloud/servers/client.py +++ b/hcloud/servers/client.py @@ -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 @@ -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) @@ -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: @@ -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 `] """ - 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 diff --git a/hcloud/volumes/client.py b/hcloud/volumes/client.py index b55434f1..1b8c2030 100644 --- a/hcloud/volumes/client.py +++ b/hcloud/volumes/client.py @@ -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) @@ -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: @@ -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 `] """ - 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 @@ -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 `] """ - 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