How to use the hcloud.locations.client.BoundLocation 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 / datacenters / test_client.py View on Github external
def test_bound_datacenter_init(self, datacenter_response):
        bound_datacenter = BoundDatacenter(
            client=mock.MagicMock(),
            data=datacenter_response['datacenter']
        )

        assert bound_datacenter.id == 1
        assert bound_datacenter.name == "fsn1-dc8"
        assert bound_datacenter.description == "Falkenstein 1 DC 8"
        assert bound_datacenter.complete is True

        assert isinstance(bound_datacenter.location, BoundLocation)
        assert bound_datacenter.location.id == 1
        assert bound_datacenter.location.name == "fsn1"
        assert bound_datacenter.location.complete is True

        assert isinstance(bound_datacenter.server_types, DatacenterServerTypes)
        assert len(bound_datacenter.server_types.supported) == 3
        assert bound_datacenter.server_types.supported[0].id == 1
        assert bound_datacenter.server_types.supported[0].complete is False
        assert bound_datacenter.server_types.supported[1].id == 2
        assert bound_datacenter.server_types.supported[1].complete is False
        assert bound_datacenter.server_types.supported[2].id == 3
        assert bound_datacenter.server_types.supported[2].complete is False

        assert len(bound_datacenter.server_types.available) == 3
        assert bound_datacenter.server_types.available[0].id == 1
        assert bound_datacenter.server_types.available[0].complete is False
github hetznercloud / hcloud-python / tests / unit / volumes / test_client.py View on Github external
client=mock.MagicMock(),
            data=volume_response['volume']
        )

        assert bound_volume.id == 1
        assert bound_volume.created == isoparse("2016-01-30T23:50:11+00:00")
        assert bound_volume.name == "database-storage"
        assert isinstance(bound_volume.server, BoundServer)
        assert bound_volume.server.id == 12
        assert bound_volume.size == 42
        assert bound_volume.linux_device == "/dev/disk/by-id/scsi-0HC_Volume_4711"
        assert bound_volume.protection == {"delete": False}
        assert bound_volume.labels == {}
        assert bound_volume.status == "available"

        assert isinstance(bound_volume.location, BoundLocation)
        assert bound_volume.location.id == 1
        assert bound_volume.location.name == "fsn1"
        assert bound_volume.location.description == "Falkenstein DC Park 1"
        assert bound_volume.location.country == "DE"
        assert bound_volume.location.city == "Falkenstein"
        assert bound_volume.location.latitude == 50.47612
        assert bound_volume.location.longitude == 12.370071
github hetznercloud / hcloud-python / tests / unit / floating_ips / test_client.py View on Github external
data=floating_ip_response['floating_ip']
        )

        assert bound_floating_ip.id == 4711
        assert bound_floating_ip.description == "Web Frontend"
        assert bound_floating_ip.name == "Web Frontend"
        assert bound_floating_ip.ip == "131.232.99.1"
        assert bound_floating_ip.type == "ipv4"
        assert bound_floating_ip.protection == {"delete": False}
        assert bound_floating_ip.labels == {}
        assert bound_floating_ip.blocked is False

        assert isinstance(bound_floating_ip.server, BoundServer)
        assert bound_floating_ip.server.id == 42

        assert isinstance(bound_floating_ip.home_location, BoundLocation)
        assert bound_floating_ip.home_location.id == 1
        assert bound_floating_ip.home_location.name == "fsn1"
        assert bound_floating_ip.home_location.description == "Falkenstein DC Park 1"
        assert bound_floating_ip.home_location.country == "DE"
        assert bound_floating_ip.home_location.city == "Falkenstein"
        assert bound_floating_ip.home_location.latitude == 50.47612
        assert bound_floating_ip.home_location.longitude == 12.370071
github hetznercloud / hcloud-python / hcloud / locations / client.py View on Github external
: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:`BoundLocation `], :class:`Meta `)
        """
        params = {}
        if name is not None:
            params["name"] = name
        if page is not None:
            params["page"] = page
        if per_page is not None:
            params["per_page"] = per_page

        response = self._client.request(url="/locations", method="GET", params=params)
        locations = [BoundLocation(self, location_data) for location_data in response['locations']]
        return self._add_meta_to_result(locations, response)
github hetznercloud / hcloud-python / hcloud / floating_ips / client.py View on Github external
def __init__(self, client, data, complete=True):
        from hcloud.servers.client import BoundServer
        server = data.get("server")
        if server is not None:
            data['server'] = BoundServer(client._client.servers, {"id": server}, complete=False)

        home_location = data.get("home_location")
        if home_location is not None:
            data['home_location'] = BoundLocation(client._client.locations, home_location)

        super(BoundFloatingIP, self).__init__(client, data, complete)
github hetznercloud / hcloud-python / hcloud / datacenters / client.py View on Github external
def __init__(self, client, data):
        location = data.get("location")
        if location is not None:
            data['location'] = BoundLocation(client._client.locations, location)

        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)
github hetznercloud / hcloud-python / hcloud / locations / client.py View on Github external
def get_by_id(self, id):
        # type: (int) -> locations.client.BoundLocation
        """Get a specific location by its ID.

        :param id: int
        :return: :class:`BoundLocation `
        """
        response = self._client.request(url="/locations/{location_id}".format(location_id=id), method="GET")
        return BoundLocation(self, response['location'])
github hetznercloud / hcloud-python / hcloud / volumes / client.py View on Github external
def __init__(self, client, data, complete=True):
        location = data.get("location")
        if location is not None:
            data['location'] = BoundLocation(client._client.locations, location)

        from hcloud.servers.client import BoundServer
        server = data.get("server")
        if server is not None:
            data['server'] = BoundServer(client._client.servers, {"id": server}, complete=False)
        super(BoundVolume, self).__init__(client, data, complete)
github hetznercloud / hcloud-python / hcloud / load_balancers / client.py View on Github external
if tmp_service.health_check.protocol != "tcp":
                    tmp_service.health_check.http = LoadBalancerHealtCheckHttp(
                        domain=service['health_check']['http']['domain'], path=service['health_check']['http']['path'],
                        response=service['health_check']['http']['response'],
                        tls=service['health_check']['http']['tls'],
                        status_codes=service['health_check']['http']['status_codes'])
                tmp_services.append(tmp_service)
            data['services'] = tmp_services

        load_balancer_type = data.get("load_balancer_type")
        if load_balancer_type is not None:
            data['load_balancer_type'] = BoundLoadBalancerType(client._client.load_balancer_types, load_balancer_type)

        location = data.get("location")
        if location is not None:
            data['location'] = BoundLocation(client._client.locations, location)

        super(BoundLoadBalancer, self).__init__(client, data, complete)