How to use the hcloud.networks.client.BoundNetwork 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 / integration / servers / test_servers.py View on Github external
    @pytest.mark.parametrize("network", [Network(id=4711), BoundNetwork(mock.MagicMock(), dict(id=4711))])
    def test_detach_from_network(self, bound_server, network):
        action = bound_server.detach_from_network(network)

        assert action.id == 13
        assert action.command == "detach_from_network"
github hetznercloud / hcloud-python / tests / unit / networks / test_client.py View on Github external
    @pytest.mark.parametrize("network", [Network(id=1), BoundNetwork(mock.MagicMock(), dict(id=1))])
    def test_delete(self, networks_client, network, generic_action):
        networks_client._client.request.return_value = generic_action
        delete_success = networks_client.delete(network)
        networks_client._client.request.assert_called_with(url="/networks/1", method="DELETE")

        assert delete_success is True
github hetznercloud / hcloud-python / tests / unit / networks / test_client.py View on Github external
def bound_network(self, hetzner_client):
        return BoundNetwork(client=hetzner_client.networks, data=dict(id=14))
github hetznercloud / hcloud-python / tests / integration / networks / test_networks.py View on Github external
    @pytest.mark.parametrize("network", [Network(id=4711), BoundNetwork(mock.MagicMock(), dict(id=4711))])
    def test_update(self, hetzner_client, network):
        network = hetzner_client.networks.update(network, name="new-name", labels={})

        assert network.id == 4711
        assert network.name == "new-name"
github hetznercloud / hcloud-python / tests / integration / networks / test_networks.py View on Github external
def bound_network(self, hetzner_client):
        return BoundNetwork(client=hetzner_client.networks, data=dict(id=4711))
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
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
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
    @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 / hcloud / networks / client.py View on Github external
:return: (List[:class:`BoundNetwork `], :class:`Meta `)
        """
        params = {}
        if name is not None:
            params["name"] = name
        if label_selector is not None:
            params["label_selector"] = label_selector
        if page is not None:
            params["page"] = page
        if per_page is not None:
            params["per_page"] = per_page

        response = self._client.request(url="/networks", method="GET", params=params)

        ass_networks = [
            BoundNetwork(self, network_data) for network_data in response["networks"]
        ]
        return self._add_meta_to_result(ass_networks, response)
github hetznercloud / hcloud-python / hcloud / servers / client.py View on Github external
server_type = data.get("server_type")
        if server_type is not None:
            data['server_type'] = BoundServerType(client._client.server_types, server_type)

        public_net = data.get("public_net")
        if public_net:
            ipv4_address = IPv4Address(**public_net['ipv4'])
            ipv6_network = IPv6Network(**public_net['ipv6'])
            floating_ips = [BoundFloatingIP(client._client.floating_ips, {"id": floating_ip}, complete=False) for
                            floating_ip in public_net['floating_ips']]
            data['public_net'] = PublicNetwork(ipv4=ipv4_address, ipv6=ipv6_network, floating_ips=floating_ips)

        private_nets = data.get("private_net")
        if private_nets:
            private_nets = [PrivateNet(network=BoundNetwork(client._client.networks, {"id": private_net['network']}, complete=False), ip=private_net['ip'], alias_ips=private_net['alias_ips'], mac_address=private_net['mac_address']) for private_net in private_nets]
            data['private_net'] = private_nets

        super(BoundServer, self).__init__(client, data, complete)
github hetznercloud / hcloud-python / hcloud / networks / client.py View on Github external
if subnets is not None:
            subnets = [NetworkSubnet.from_dict(subnet) for subnet in subnets]
            data['subnets'] = subnets

        routes = data.get("routes", [])
        if routes is not None:
            routes = [NetworkRoute.from_dict(route) for route in routes]
            data['routes'] = routes

        from hcloud.servers.client import BoundServer
        servers = data.get("servers", [])
        if servers is not None:
            servers = [BoundServer(client._client.servers, {"id": server}, complete=False) for server in servers]
            data['servers'] = servers

        super(BoundNetwork, self).__init__(client, data, complete)