How to use the hcloud.servers.client.BoundServer 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 / servers / test_client.py View on Github external
def test_bound_server_init(self, response_full_server):
        bound_server = BoundServer(
            client=mock.MagicMock(),
            data=response_full_server['server']
        )

        assert bound_server.id == 42
        assert bound_server.name == "my-server"
        assert isinstance(bound_server.public_net, PublicNetwork)
        assert isinstance(bound_server.public_net.ipv4, IPv4Address)
        assert bound_server.public_net.ipv4.ip == "1.2.3.4"
        assert bound_server.public_net.ipv4.blocked is False
        assert bound_server.public_net.ipv4.dns_ptr == "server01.example.com"

        assert isinstance(bound_server.public_net.ipv6, IPv6Network)
        assert bound_server.public_net.ipv6.ip == "2001:db8::/64"
        assert bound_server.public_net.ipv6.blocked is False
        assert bound_server.public_net.ipv6.network == "2001:db8::"
github hetznercloud / hcloud-python / tests / unit / networks / test_client.py View on Github external
def test_bound_network_init(self, network_response):
        bound_network = BoundNetwork(
            client=mock.MagicMock(),
            data=network_response['network']
        )

        assert bound_network.id == 1
        assert bound_network.created == isoparse("2016-01-30T23:50:11+00:00")
        assert bound_network.name == "mynet"
        assert bound_network.ip_range == "10.0.0.0/16"
        assert bound_network.protection['delete'] is False

        assert len(bound_network.servers) == 1
        assert isinstance(bound_network.servers[0], BoundServer)
        assert bound_network.servers[0].id == 42
        assert bound_network.servers[0].complete is False

        assert len(bound_network.subnets) == 2
        assert isinstance(bound_network.subnets[0], NetworkSubnet)
        assert bound_network.subnets[0].type == "cloud"
        assert bound_network.subnets[0].ip_range == "10.0.1.0/24"
        assert bound_network.subnets[0].network_zone == "eu-central"
        assert bound_network.subnets[0].gateway == "10.0.0.1"

        assert len(bound_network.routes) == 1
        assert isinstance(bound_network.routes[0], NetworkRoute)
        assert bound_network.routes[0].destination == "10.100.1.0/24"
        assert bound_network.routes[0].gateway == "10.0.1.1"
github hetznercloud / hcloud-python / tests / unit / floating_ips / test_client.py View on Github external
    @pytest.mark.parametrize("server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))])
    def test_create_with_server(self, floating_ips_client, server, floating_ip_create_response):
        floating_ips_client._client.request.return_value = floating_ip_create_response
        response = floating_ips_client.create(
            type="ipv6",
            description="Web Frontend",
            server=server
        )
        floating_ips_client._client.request.assert_called_with(
            url="/floating_ips",
            method="POST",
            json={
                'description': "Web Frontend",
                'type': "ipv6",
                'server': 1
            }
        )
github hetznercloud / hcloud-python / tests / unit / volumes / test_client.py View on Github external
                              (BoundServer(mock.MagicMock(), dict(id=1)), BoundVolume(mock.MagicMock(), dict(id=12)))])
    def test_attach(self, volumes_client, server, volume, generic_action):
        volumes_client._client.request.return_value = generic_action
        action = volumes_client.attach(volume, server)
        volumes_client._client.request.assert_called_with(
            url="/volumes/12/actions/attach",
            method="POST",
            json={"server": 1}
        )
        assert action.id == 1
        assert action.progress == 0
github hetznercloud / hcloud-python / tests / integration / servers / test_servers.py View on Github external
def bound_server(self, hetzner_client):
        return BoundServer(client=hetzner_client.servers, data=dict(id=42))
github hetznercloud / hcloud-python / tests / integration / floating_ips / test_floating_ips.py View on Github external
                              (BoundServer(mock.MagicMock(), dict(id=43)), BoundFloatingIP(mock.MagicMock(), dict(id=4711)))])
    def test_assign(self, hetzner_client, server, floating_ip):
        action = hetzner_client.floating_ips.assign(floating_ip, server)
        assert action.id == 13
        assert action.progress == 0
        assert action.command == "assign_floating_ip"
github hetznercloud / hcloud-python / hcloud / servers / client.py View on Github external
"""
        params = {}
        if name is not None:
            params['name'] = name
        if label_selector is not None:
            params['label_selector'] = label_selector
        if status is not None:
            params["status"] = status
        if page is not None:
            params['page'] = page
        if per_page is not None:
            params['per_page'] = per_page

        response = self._client.request(url="/servers", method="GET", params=params)

        ass_servers = [BoundServer(self, server_data) for server_data in response['servers']]
        return self._add_meta_to_result(ass_servers, 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 / servers / client.py View on Github external
data['ssh_keys'] = [ssh_key.id_or_name for ssh_key in ssh_keys]
        if volumes is not None:
            data['volumes'] = [volume.id for volume in volumes]
        if networks is not None:
            data['networks'] = [network.id for network in networks]
        if user_data is not None:
            data['user_data'] = user_data
        if labels is not None:
            data['labels'] = labels
        if automount is not None:
            data["automount"] = automount

        response = self._client.request(url="/servers", method="POST", json=data)

        result = CreateServerResponse(
            server=BoundServer(self, response['server']),
            action=BoundAction(self._client.actions, response['action']),
            next_actions=[BoundAction(self._client.actions, action) for action in response['next_actions']],
            root_password=response['root_password']
        )
        return result
github hetznercloud / hcloud-python / hcloud / images / client.py View on Github external
def __init__(self, client, data):
        from hcloud.servers.client import BoundServer
        created_from = data.get("created_from")
        if created_from is not None:
            data['created_from'] = BoundServer(client._client.servers, created_from, complete=False)
        bound_to = data.get("bound_to")
        if bound_to is not None:
            data['bound_to'] = BoundServer(client._client.servers, {"id": bound_to}, complete=False)

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