Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rebuild(self, hetzner_client, server):
action = hetzner_client.servers.rebuild(server, Image(name="ubuntu-20.04"))
assert action.id == 13
assert action.command == "rebuild_server"
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
bound_action = response.action
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
def test_create_with_networks(self, servers_client, response_create_simple_server):
servers_client._client.request.return_value = response_create_simple_server
networks = [Network(id=1), BoundNetwork(mock.MagicMock(), dict(id=2))]
response = servers_client.create(
"my-server",
server_type=ServerType(name="cx11"),
image=Image(id=4711),
networks=networks,
start_after_create=False
)
servers_client._client.request.assert_called_with(
url="/servers",
method="POST",
json={
'name': "my-server",
'server_type': "cx11",
'image': 4711,
'networks': [1, 2],
"start_after_create": False
}
)
bound_server = response.server
def test_rebuild(self, hetzner_client, bound_server, generic_action):
hetzner_client.request.return_value = generic_action
action = bound_server.rebuild(Image(name="ubuntu-20.04"))
hetzner_client.request.assert_called_with(url="/servers/14/actions/rebuild", method="POST", json={"image": "ubuntu-20.04"})
assert action.id == 1
assert action.progress == 0
def test_rebuild(self, servers_client, server, generic_action):
servers_client._client.request.return_value = generic_action
action = servers_client.rebuild(server, Image(name="ubuntu-20.04"))
servers_client._client.request.assert_called_with(url="/servers/1/actions/rebuild", method="POST", json={"image": "ubuntu-20.04"})
assert action.id == 1
assert action.progress == 0
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
}
)
bound_server = response.server
def test_create(self, hetzner_client):
response = hetzner_client.servers.create(
"my-server",
server_type=ServerType(name="cx11"),
image=Image(name="ubuntu-20.04"),
ssh_keys=[SSHKey(name="my-ssh-key")],
volumes=[Volume(id=1)],
networks=[Network(id=1)],
user_data="#cloud-config\\nruncmd:\\n- [touch, /root/cloud-init-worked]\\n",
location=Location(name="nbg1"),
automount=False
)
server = response.server
action = response.action
next_actions = response.next_actions
root_password = response.root_password
assert server.id == 42
assert server.volumes == []
assert server.server_type.id == 1
from hcloud import Client
from hcloud.images.domain import Image
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