How to use the hcloud.floating_ips.client.BoundFloatingIP 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 / floating_ips / test_client.py View on Github external
def test_bound_floating_ip_init(self, floating_ip_response):
        bound_floating_ip = BoundFloatingIP(
            client=mock.MagicMock(),
            data=floating_ip_response['floating_ip']
        )

        assert bound_floating_ip.id == 4711
        assert bound_floating_ip.description == "Web Frontend"
        assert bound_floating_ip.name == "Web Frontend"
        assert bound_floating_ip.ip == "131.232.99.1"
        assert bound_floating_ip.type == "ipv4"
        assert bound_floating_ip.protection == {"delete": False}
        assert bound_floating_ip.labels == {}
        assert bound_floating_ip.blocked is False

        assert isinstance(bound_floating_ip.server, BoundServer)
        assert bound_floating_ip.server.id == 42
github hetznercloud / hcloud-python / tests / integration / floating_ips / test_floating_ips.py View on Github external
def bound_floating_ip(self, hetzner_client):
        return BoundFloatingIP(client=hetzner_client.floating_ips, data=dict(id=4711))
github hetznercloud / hcloud-python / tests / unit / servers / test_client.py View on Github external
assert bound_server.id == 42
        assert bound_server.name == "my-server"
        assert isinstance(bound_server.public_net, PublicNetwork)
        assert isinstance(bound_server.public_net.ipv4, IPv4Address)
        assert bound_server.public_net.ipv4.ip == "1.2.3.4"
        assert bound_server.public_net.ipv4.blocked is False
        assert bound_server.public_net.ipv4.dns_ptr == "server01.example.com"

        assert isinstance(bound_server.public_net.ipv6, IPv6Network)
        assert bound_server.public_net.ipv6.ip == "2001:db8::/64"
        assert bound_server.public_net.ipv6.blocked is False
        assert bound_server.public_net.ipv6.network == "2001:db8::"
        assert bound_server.public_net.ipv6.network_mask == "64"

        assert isinstance(bound_server.public_net.floating_ips[0], BoundFloatingIP)
        assert bound_server.public_net.floating_ips[0].id == 478
        assert bound_server.public_net.floating_ips[0].complete is False

        assert isinstance(bound_server.datacenter, BoundDatacenter)
        assert bound_server.datacenter._client == bound_server._client._client.datacenters
        assert bound_server.datacenter.id == 1
        assert bound_server.datacenter.complete is True

        assert isinstance(bound_server.server_type, BoundServerType)
        assert bound_server.server_type._client == bound_server._client._client.server_types
        assert bound_server.server_type.id == 1
        assert bound_server.server_type.complete is True

        assert len(bound_server.volumes) == 2
        assert isinstance(bound_server.volumes[0], BoundVolume)
        assert bound_server.volumes[0]._client == bound_server._client._client.volumes
github hetznercloud / hcloud-python / tests / unit / floating_ips / test_client.py View on Github external
    @pytest.mark.parametrize("floating_ip", [FloatingIP(id=1), BoundFloatingIP(mock.MagicMock(), dict(id=1))])
    def test_delete(self, floating_ips_client, floating_ip, generic_action):
        floating_ips_client._client.request.return_value = generic_action
        delete_success = floating_ips_client.delete(floating_ip)
        floating_ips_client._client.request.assert_called_with(url="/floating_ips/1", method="DELETE")

        assert delete_success is True
github hetznercloud / hcloud-python / hcloud / floating_ips / client.py View on Github external
def get_by_id(self, id):
        # type: (int) -> BoundFloatingIP
        """Returns a specific Floating IP object.

        :param id: int
        :return: :class:`BoundFloatingIP `
        """
        response = self._client.request(url="/floating_ips/{floating_ip_id}".format(floating_ip_id=id), method="GET")
        return BoundFloatingIP(self, response['floating_ip'])
github hetznercloud / hcloud-python / hcloud / servers / client.py View on Github external
if image is not None:
            data['image'] = BoundImage(client._client.images, image)

        iso = data.get("iso", None)
        if iso is not None:
            data['iso'] = BoundIso(client._client.isos, iso)

        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 / floating_ips / client.py View on Github external
data['labels'] = labels
        if home_location is not None:
            data['home_location'] = home_location.id_or_name
        if server is not None:
            data['server'] = server.id
        if name is not None:
            data['name'] = name

        response = self._client.request(url="/floating_ips", json=data, method="POST")

        action = None
        if response.get('action') is not None:
            action = BoundAction(self._client.actions, response['action'])

        result = CreateFloatingIPResponse(
            floating_ip=BoundFloatingIP(self, response['floating_ip']),
            action=action
        )
        return result
github hetznercloud / hcloud-python / hcloud / floating_ips / client.py View on Github external
Can be used to filter networks by their name.
        :return: (List[:class:`BoundFloatingIP `], :class:`Meta `)
        """
        params = {}

        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
        if name is not None:
            params['name'] = name

        response = self._client.request(url="/floating_ips", method="GET", params=params)
        floating_ips = [BoundFloatingIP(self, floating_ip_data) for floating_ip_data in response['floating_ips']]

        return self._add_meta_to_result(floating_ips, response)
github hetznercloud / hcloud-python / hcloud / floating_ips / client.py View on Github external
def __init__(self, client, data, complete=True):
        from hcloud.servers.client import BoundServer
        server = data.get("server")
        if server is not None:
            data['server'] = BoundServer(client._client.servers, {"id": server}, complete=False)

        home_location = data.get("home_location")
        if home_location is not None:
            data['home_location'] = BoundLocation(client._client.locations, home_location)

        super(BoundFloatingIP, self).__init__(client, data, complete)
github hetznercloud / hcloud-python / hcloud / floating_ips / client.py View on Github external
User-defined labels (key-value pairs)
        :param name: str (optional)
               New name to set
        :return: :class:`BoundFloatingIP `
        """
        data = {}
        if description is not None:
            data['description'] = description
        if labels is not None:
            data['labels'] = labels
        if name is not None:
            data['name'] = name

        response = self._client.request(url="/floating_ips/{floating_ip_id}".format(floating_ip_id=floating_ip.id),
                                        method="PUT", json=data)
        return BoundFloatingIP(self, response['floating_ip'])