How to use the hcloud.core.client.ClientEntityBase function in hcloud

To help you get started, we’ve selected a few hcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hetznercloud / hcloud-python / hcloud / datacenters / client.py View on Github external
server_types = data.get("server_types")
        if server_types is not None:
            available = [BoundServerType(client._client.server_types, {"id": server_type}, complete=False) for
                         server_type in server_types['available']]
            supported = [BoundServerType(client._client.server_types, {"id": server_type}, complete=False) for
                         server_type in server_types['supported']]
            available_for_migration = [BoundServerType(client._client.server_types, {"id": server_type}, complete=False)
                                       for server_type in server_types['available_for_migration']]
            data['server_types'] = DatacenterServerTypes(available=available, supported=supported,
                                                         available_for_migration=available_for_migration)

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


class DatacentersClient(ClientEntityBase):
    results_list_attribute_name = 'datacenters'

    def get_by_id(self, id):
        # type: (int) -> BoundDatacenter
        """Get a specific datacenter by its ID.

        :param id: int
        :return: :class:`BoundDatacenter `
        """
        response = self._client.request(url="/datacenters/{datacenter_id}".format(datacenter_id=id), method="GET")
        return BoundDatacenter(self, response['datacenter'])

    def get_list(self,
                 name=None,  # type: Optional[str]
                 page=None,  # type: Optional[int]
                 per_page=None  # type: Optional[int]
github hetznercloud / hcloud-python / hcloud / actions / client.py View on Github external
: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 `
        """

        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]]