How to use hcloud - 10 common examples

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 / volumes / test_client.py View on Github external
def test_bound_volume_init(self, volume_response):
        bound_volume = BoundVolume(
            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)
github hetznercloud / hcloud-python / tests / unit / floating_ips / test_client.py View on Github external
def test_bound_floating_ip_init(self, floating_ip_response):
        bound_floating_ip = BoundFloatingIP(
            client=mock.MagicMock(),
            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
github hetznercloud / hcloud-python / tests / unit / images / test_client.py View on Github external
def test_bound_image_init(self, image_response):
        bound_image = BoundImage(
            client=mock.MagicMock(),
            data=image_response['image']
        )

        assert bound_image.id == 4711
        assert bound_image.type == "snapshot"
        assert bound_image.status == "available"
        assert bound_image.name == "ubuntu-20.04"
        assert bound_image.description == "Ubuntu 20.04 Standard 64 bit"
        assert bound_image.image_size == 2.3
        assert bound_image.disk_size == 10
        assert bound_image.created == datetime.datetime(2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0))
        assert bound_image.os_flavor == "ubuntu"
        assert bound_image.os_version == "16.04"
        assert bound_image.rapid_deploy is False
        assert bound_image.deprecated == datetime.datetime(2018, 2, 28, 0, 0, tzinfo=tzoffset(None, 0))
github hetznercloud / hcloud-python / tests / unit / ssh_keys / test_client.py View on Github external
def test_bound_ssh_key_init(self, ssh_key_response):
        bound_ssh_key = BoundSSHKey(
            client=mock.MagicMock(),
            data=ssh_key_response['ssh_key']
        )

        assert bound_ssh_key.id == 2323
        assert bound_ssh_key.name == "My ssh key"
        assert bound_ssh_key.fingerprint == "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f"
        assert bound_ssh_key.public_key == "ssh-rsa AAAjjk76kgf...Xt"
github hetznercloud / hcloud-python / tests / unit / load_balancers / test_client.py View on Github external
def test_bound_load_balancer_init(self, response_load_balancer):
        bound_load_balancer = BoundLoadBalancer(
            client=mock.MagicMock(),
            data=response_load_balancer['load_balancer']
        )

        assert bound_load_balancer.id == 4711
        assert bound_load_balancer.name == 'Web Frontend'
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 / servers / test_client.py View on Github external
"start_after_create": False
            }
        )

        bound_server = response.server
        bound_action = response.action
        next_actions = response.next_actions
        root_password = response.root_password

        assert root_password == "YItygq1v3GYjjMomLaKc"

        assert bound_server._client is servers_client
        assert bound_server.id == 1
        assert bound_server.name == "my-server"

        assert isinstance(bound_action, BoundAction)
        assert bound_action._client == servers_client._client.actions
        assert bound_action.id == 1
        assert bound_action.command == "create_server"

        assert next_actions[0].id == 13
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
            }
        )