How to use the hcloud.servers.domain.Server 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
            {"status": [Server.STATUS_RUNNING],
             "sort": "status",
             "page": 1,
             "per_page": 10},
            {}

        ]
    )
    def test_get_actions_list(self, hetzner_client, bound_server, response_get_actions, params):
        hetzner_client.request.return_value = response_get_actions
        result = bound_server.get_actions_list(**params)
        hetzner_client.request.assert_called_with(url="/servers/14/actions", method="GET", params=params)

        actions = result.actions
        assert result.meta is None

        assert len(actions) == 1
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
            {"status": [Server.STATUS_RUNNING],
             "sort": "status"},
            {}

        ]
    )
    def test_get_actions(self, hetzner_client, bound_server, response_get_actions, params):
        hetzner_client.request.return_value = response_get_actions
        actions = bound_server.get_actions(**params)

        params.update({'page': 1, 'per_page': 50})

        hetzner_client.request.assert_called_with(url="/servers/14/actions", method="GET", params=params)

        assert len(actions) == 1
        assert isinstance(actions[0], BoundAction)
        assert actions[0].id == 13
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
    @pytest.mark.parametrize("server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))])
    @pytest.mark.parametrize("network", [Network(id=4711), BoundNetwork(mock.MagicMock(), dict(id=4711))])
    def test_change_alias_ips(self, servers_client, server, network, response_change_alias_ips):
        servers_client._client.request.return_value = response_change_alias_ips
        action = servers_client.change_alias_ips(server, network, ["10.0.1.2", "10.0.1.3"])
        servers_client._client.request.assert_called_with(url="/servers/1/actions/change_alias_ips", method="POST", json={"network": 4711, "alias_ips": ["10.0.1.2", "10.0.1.3"]})

        assert action.id == 1
        assert action.progress == 0
        assert action.command == "change_alias_ips"
github hetznercloud / hcloud-python / tests / integration / servers / test_servers.py View on Github external
    @pytest.mark.parametrize("server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))])
    def test_power_off(self, hetzner_client, server):
        action = hetzner_client.servers.power_off(server)

        assert action.id == 13
        assert action.command == "stop_server"
github hetznercloud / hcloud-python / tests / unit / floating_ips / test_client.py View on Github external
                             [(Server(id=1), FloatingIP(id=12)),
                              (BoundServer(mock.MagicMock(), dict(id=1)),
                               BoundFloatingIP(mock.MagicMock(), dict(id=12)))])
    def test_assign(self, floating_ips_client, server, floating_ip, generic_action):
        floating_ips_client._client.request.return_value = generic_action
        action = floating_ips_client.assign(floating_ip, server)
        floating_ips_client._client.request.assert_called_with(
            url="/floating_ips/12/actions/assign",
            method="POST",
            json={"server": 1}
        )
        assert action.id == 1
        assert action.progress == 0
github hetznercloud / hcloud-python / tests / integration / load_balancers / test_load_balancers.py View on Github external
def test_remove_target(self, hetzner_client, load_balancer):
        action = hetzner_client.load_balancers.remove_target(load_balancer,
                                                             LoadBalancerTarget(type="server", server=Server(id=1)))
        assert action.id == 13
        assert action.command == "remove_target"
github hetznercloud / hcloud-python / tests / unit / volumes / test_client.py View on Github external
                             [(Server(id=1), Volume(id=12)),
                              (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 / unit / load_balancers / test_client.py View on Github external
def test_add_target(self, hetzner_client, response_add_target, bound_load_balancer):
        hetzner_client.request.return_value = response_add_target
        target = LoadBalancerTarget(server=Server(id=1), use_private_ip=True)
        action = bound_load_balancer.add_target(target)
        hetzner_client.request.assert_called_with(json={'type': None, 'server': {"id": 1}, 'use_private_ip': True},
                                                  url="/load_balancers/14/actions/add_target", method="POST")

        assert action.id == 13
        assert action.progress == 100
        assert action.command == "add_target"
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_server.py View on Github external
def start_server(self):
        try:
            if self.hcloud_server.status != Server.STATUS_RUNNING:
                if not self.module.check_mode:
                    self.client.servers.power_on(self.hcloud_server).wait_until_finished()
                self._mark_as_changed()
            self._get_server()
        except APIException as e:
            self.module.fail_json(msg=e.message)
github ansible / ansible / lib / ansible / modules / cloud / hcloud / hcloud_server.py View on Github external
elif not self.module.params.get("backups") and self.hcloud_server.backup_window is not None:
                if not self.module.check_mode:
                    self.hcloud_server.disable_backup().wait_until_finished()
                self._mark_as_changed()

            labels = self.module.params.get("labels")
            if labels is not None and labels != self.hcloud_server.labels:
                if not self.module.check_mode:
                    self.hcloud_server.update(labels=labels)
                self._mark_as_changed()

            server_type = self.module.params.get("server_type")
            if server_type is not None and self.hcloud_server.server_type.name != server_type:
                previous_server_status = self.hcloud_server.status
                state = self.module.params.get("state")
                if previous_server_status == Server.STATUS_RUNNING:
                    if not self.module.check_mode:
                        if self.module.params.get("force_upgrade") or state == "stopped":
                            self.stop_server()  # Only stopped server can be upgraded
                        else:
                            self.module.warn(
                                "You can not upgrade a running instance %s. You need to stop the instance or use force_upgrade=yes."
                                % self.hcloud_server.name
                            )
                timeout = 100
                if self.module.params.get("upgrade_disk"):
                    timeout = (
                        1000
                    )  # When we upgrade the disk too the resize progress takes some more time.
                if not self.module.check_mode:
                    self.hcloud_server.change_type(
                        server_type=self.client.server_types.get_by_name(server_type),