How to use the hcloud.APIException 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 / tests / unit / test_hcloud.py View on Github external
def test_request_fails(self, mocked_requests, client, fail_response):
        mocked_requests.request.return_value = fail_response
        with pytest.raises(APIException) as exception_info:
            client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
        error = exception_info.value
        assert error.code == "invalid_input"
        assert error.message == "invalid input in field 'broken_field': is too long"
        assert error.details['fields'][0]['name'] == "broken_field"
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_server_info.py View on Github external
try:
            if self.module.params.get("id") is not None:
                self.hcloud_server_info = [self.client.servers.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_server_info = [self.client.servers.get_by_name(
                    self.module.params.get("name")
                )]
            elif self.module.params.get("label_selector") is not None:
                self.hcloud_server_info = self.client.servers.get_all(
                    label_selector=self.module.params.get("label_selector"))
            else:
                self.hcloud_server_info = self.client.servers.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_volume_info.py View on Github external
try:
            if self.module.params.get("id") is not None:
                self.hcloud_volume_info = [self.client.volumes.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_volume_info = [self.client.volumes.get_by_name(
                    self.module.params.get("name")
                )]
            elif self.module.params.get("label_selector") is not None:
                self.hcloud_volume_info = self.client.volumes.get_all(
                    label_selector=self.module.params.get("label_selector"))
            else:
                self.hcloud_volume_info = self.client.volumes.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_image_info.py View on Github external
self.hcloud_image_info = [self.client.images.get_by_name(
                    self.module.params.get("name")
                )]
            else:
                params = {}
                label_selector = self.module.params.get("label_selector")
                if label_selector:
                    params["label_selector"] = label_selector

                image_type = self.module.params.get("type")
                if image_type:
                    params["type"] = image_type

                self.hcloud_image_info = self.client.images.get_all(**params)

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_server_type_info.py View on Github external
def get_server_types(self):
        try:
            if self.module.params.get("id") is not None:
                self.hcloud_server_type_info = [self.client.server_types.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_server_type_info = [self.client.server_types.get_by_name(
                    self.module.params.get("name")
                )]
            else:
                self.hcloud_server_type_info = self.client.server_types.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_datacenter_info.py View on Github external
def get_datacenters(self):
        try:
            if self.module.params.get("id") is not None:
                self.hcloud_datacenter_info = [self.client.datacenters.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_datacenter_info = [self.client.datacenters.get_by_name(
                    self.module.params.get("name")
                )]
            else:
                self.hcloud_datacenter_info = self.client.datacenters.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_location_info.py View on Github external
def get_locations(self):
        try:
            if self.module.params.get("id") is not None:
                self.hcloud_location_info = [self.client.locations.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_location_info = [self.client.locations.get_by_name(
                    self.module.params.get("name")
                )]
            else:
                self.hcloud_location_info = self.client.locations.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_ssh_key.py View on Github external
def _get_ssh_key(self):
        try:
            if self.module.params.get("id") is not None:
                self.hcloud_ssh_key = self.client.ssh_keys.get_by_id(
                    self.module.params.get("id")
                )
            elif self.module.params.get("fingerprint") is not None:
                self.hcloud_ssh_key = self.client.ssh_keys.get_by_fingerprint(
                    self.module.params.get("fingerprint")
                )
            elif self.module.params.get("name") is not None:
                self.hcloud_ssh_key = self.client.ssh_keys.get_by_name(
                    self.module.params.get("name")
                )

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_floating_ip_info.py View on Github external
def get_floating_ips(self):
        try:
            if self.module.params.get("id") is not None:
                self.hcloud_floating_ip_info = [self.client.floating_ips.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("label_selector") is not None:
                self.hcloud_floating_ip_info = self.client.floating_ips.get_all(
                    label_selector=self.module.params.get("label_selector"))
            else:
                self.hcloud_floating_ip_info = self.client.floating_ips.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_network_info.py View on Github external
try:
            if self.module.params.get("id") is not None:
                self.hcloud_network_info = [self.client.networks.get_by_id(
                    self.module.params.get("id")
                )]
            elif self.module.params.get("name") is not None:
                self.hcloud_network_info = [self.client.networks.get_by_name(
                    self.module.params.get("name")
                )]
            elif self.module.params.get("label_selector") is not None:
                self.hcloud_network_info = self.client.networks.get_all(
                    label_selector=self.module.params.get("label_selector"))
            else:
                self.hcloud_network_info = self.client.networks.get_all()

        except APIException as e:
            self.module.fail_json(msg=e.message)