def test_create(self, hetzner_client): response = hetzner_client.servers.create( "my-server", server_type=ServerType(name="cx11"), image=Image(name="ubuntu-16.04"), ssh_keys=[SSHKey(name="my-ssh-key")], volumes=[Volume(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 assert server.datacenter.id == 1 assert server.image.id == 4711 assert action.id == 1 assert action.command == "create_server" assert len(next_actions) == 1 assert next_actions[0].id == 13 assert next_actions[0].command == "start_server" assert root_password == "YItygq1v3GYjjMomLaKc"
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 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"
def test_create_with_location(self, volumes_client, volume_create_response): volumes_client._client.request.return_value = volume_create_response response = volumes_client.create( 100, "database-storage", location=Location(name="location"), automount=False, format="xfs" ) volumes_client._client.request.assert_called_with( url="/volumes", method="POST", json={ 'name': "database-storage", 'size': 100, 'location': "location", 'automount': False, 'format': "xfs" } ) bound_volume = response.volume action = response.action next_actions = response.next_actions assert bound_volume._client is volumes_client assert bound_volume.id == 4711 assert bound_volume.name == "database-storage" assert action.id == 13 assert next_actions[0].command == "start_server"
def test_create_negative_size(self, volumes_client): with pytest.raises(ValueError) as e: volumes_client.create(-100, "database-storage", location=Location(name="location")) assert str(e.value) == "size must be greater than 0" volumes_client._client.request.assert_not_called()
def do_create_new(self, defn: HcloudVolumeDefinition) -> BoundVolume: self.size = defn.config.size self.location = defn.config.location resp = self.entity_client().create( name=self.hcloud_name, size=self.size, location=Location(name=self.location)) resp.action.wait_until_finished() return resp.volume
def deploy_instance(self, name) -> None: log.info(f"hcloud: Deploying instance with name {name}") launch_config = self.launch.copy() labels = launch_config.get("labels", dict()) labels.update({"scalr": self.filter}) params = { "name": name, "labels": labels, "server_type": ServerType(launch_config["server_type"]), "image": Image(launch_config["image"]), "ssh_keys": [SSHKey(ssh_key) for ssh_key in launch_config["ssh_keys"]], "location": Location(launch_config["location"]), "user_data": launch_config["user_data"], } self.hcloud.servers.create(**params)
def create(): with open(data_file, "r") as file: data = json.load(file) client = Client(token=data["token"]) response = client.servers.create("win10-OCR", server_type=ServerType(name="cx41"), image=Image(id=22859215), networks=[Network(id=135205)], location=Location(id=2)) server = response.server data["server_id"] = f"{server.id}" with open(data_file, "w") as file: json.dump(data, file, indent=4) click.echo("creation complete")
async def start(self): if self.running == False: print("Starting " + self.name) response = self.client.servers.create( self.name, server_type=ServerType(name=self.servertype), image=Image(self.snapshot), location=Location(self.location), volumes=[Volume(self.volume)]) self.server = response.server #while self.server.status != Server.STATUS_RUNNING: # print(self.server.status) # time.sleep(2) # serv = self.client.servers.get_by_id(self.server.id) # self.server = serv #print("Server is now running") self.running = True else: print(self.name + " is already running")
def test_create(self, load_balancers_client, response_create_load_balancer): load_balancers_client._client.request.return_value = response_create_load_balancer response = load_balancers_client.create( "my-balancer", load_balancer_type=LoadBalancerType(name="lb11"), location=Location(id=1)) load_balancers_client._client.request.assert_called_with( url="/load_balancers", method="POST", json={ 'name': "my-balancer", 'load_balancer_type': "lb11", 'location': 1 }) bound_load_balancer = response.load_balancer assert bound_load_balancer._client is load_balancers_client assert bound_load_balancer.id == 1 assert bound_load_balancer.name == "my-balancer"
def test_create(self, hetzner_client, server): response = hetzner_client.volumes.create( 42, "test-database", location=Location(name="nbg1"), automount=False, format="xfs") volume = response.volume action = response.action next_actions = response.next_actions assert volume.id == 4711 assert volume.name == "database-storage" assert volume.size == 42 assert action.id == 13 assert action.command == "create_volume" assert len(next_actions) == 1 assert next_actions[0].id == 13 assert next_actions[0].command == "start_server"
def test_create_with_location(self, floating_ips_client, floating_ip_response): floating_ips_client._client.request.return_value = floating_ip_response response = floating_ips_client.create( "ipv6", "Web Frontend", home_location=Location(name="location"), ) floating_ips_client._client.request.assert_called_with( url="/floating_ips", method="POST", json={ 'description': "Web Frontend", 'type': "ipv6", 'home_location': "location" }) bound_floating_ip = response.floating_ip action = response.action assert bound_floating_ip._client is floating_ips_client assert bound_floating_ip.id == 4711 assert bound_floating_ip.description == "Web Frontend" assert action is None