How to use the hcloud.server_types.domain.ServerType 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_create_with_datacenter(self, servers_client, response_create_simple_server):
        servers_client._client.request.return_value = response_create_simple_server
        response = servers_client.create(
            "my-server",
            server_type=ServerType(name="cx11"),
            image=Image(id=4711),
            datacenter=Datacenter(id=1)
        )
        servers_client._client.request.assert_called_with(
            url="/servers",
            method="POST",
            json={
                'name': "my-server",
                'server_type': "cx11",
                'image': 4711,
                'datacenter': 1,
                "start_after_create": True
            }
        )

        bound_server = response.server
github hetznercloud / hcloud-python / tests / integration / servers / test_servers.py View on Github external
def test_change_type(self, bound_server):
        action = bound_server.change_type(ServerType(name="cx11"), upgrade_disk=True)
        assert action.id == 13
        assert action.command == "change_server_type"
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
def test_change_type_with_server_type_id(self, servers_client, server, generic_action):
        servers_client._client.request.return_value = generic_action
        action = servers_client.change_type(server, ServerType(id=1), upgrade_disk=True)
        servers_client._client.request.assert_called_with(url="/servers/1/actions/change_type", method="POST",
                                                          json={"server_type": 1, "upgrade_disk": True})

        assert action.id == 1
        assert action.progress == 0
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
def test_create_with_location(self, servers_client, response_create_simple_server):
        servers_client._client.request.return_value = response_create_simple_server
        response = servers_client.create(
            "my-server",
            server_type=ServerType(name="cx11"),
            image=Image(name="ubuntu-20.04"),
            location=Location(name="fsn1")
        )
        servers_client._client.request.assert_called_with(
            url="/servers",
            method="POST",
            json={
                'name': "my-server",
                'server_type': "cx11",
                'image': "ubuntu-20.04",
                'location': "fsn1",
                "start_after_create": True
            }
        )

        bound_server = response.server
github hetznercloud / hcloud-python / tests / integration / servers / test_servers.py View on Github external
def test_change_type(self, hetzner_client, server):
        action = hetzner_client.servers.change_type(server, ServerType(name="cx11"), upgrade_disk=True)

        assert action.id == 13
        assert action.command == "change_server_type"
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
def test_change_type_with_blank_server_type(self, servers_client, server):
        with pytest.raises(ValueError) as e:
            servers_client.change_type(server, ServerType(), upgrade_disk=True)
        assert str(e.value) == "id or name must be set"
        servers_client._client.request.assert_not_called()
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
def test_create_with_volumes(self, servers_client, response_create_simple_server):
        servers_client._client.request.return_value = response_create_simple_server
        volumes = [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=2))]
        response = servers_client.create(
            "my-server",
            server_type=ServerType(name="cx11"),
            image=Image(id=4711),
            volumes=volumes,
            start_after_create=False
        )
        servers_client._client.request.assert_called_with(
            url="/servers",
            method="POST",
            json={
                'name': "my-server",
                'server_type': "cx11",
                'image': 4711,
                'volumes': [1, 2],
                "start_after_create": False
            }
        )
github hetznercloud / hcloud-python / examples / create_server.py View on Github external
from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType

client = Client(token="{YOUR_API_TOKEN}")  # Please paste your API token here between the quotes
response = client.servers.create(name="my-server", server_type=ServerType("cx11"), image=Image(name="ubuntu-20.04"))
server = response.server
print(server)
print("Root Password" + response.root_password)
github hetznercloud / hcloud-python / examples / usage_procedurale.py View on Github external
from hcloud.servers.domain import Server
from hcloud.server_types.domain import ServerType
from hcloud.volumes.domain import Volume

client = Client(token="project-token")

# Create 2 servers
response1 = client.servers.create(
    name="Server1",
    server_type=ServerType(name="cx11"),
    image=Image(id=4711)
)

response2 = client.servers.create(
    "Server2",
    server_type=ServerType(name="cx11"),
    image=Image(id=4711)
)

server1 = response1.server
server2 = response2.server

# Get all servers

servers = client.servers.get_all()

assert servers[0].id == server1.id
assert servers[1].id == server2.id

# Create 2 volumes

response1 = client.volumes.create(
github hetznercloud / hcloud-python / examples / usage_oop.py View on Github external
from hcloud.server_types.domain import ServerType

# Create a client
client = Client(token="project-token")

# Create 2 servers
# Create 2 servers
response1 = client.servers.create(
    "Server1",
    server_type=ServerType(name="cx11"),
    image=Image(id=4711)
)

response2 = client.servers.create(
    "Server2",
    server_type=ServerType(name="cx11"),
    image=Image(id=4711)
)
# Get all servers
server1 = response1.server
server2 = response2.server

servers = client.servers.get_all()

assert servers[0].id == server1.id
assert servers[1].id == server2.id
# Create 2 volumes

response1 = client.volumes.create(
    size=15,
    name="Volume1",
    location=server1.location