Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions linode_api4/groups/vpc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, Dict, List, Optional, Union

from linode_api4 import VPCSubnet
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import VPC, Base, Region
from linode_api4.objects import VPC, Region, VPCIPAddress
from linode_api4.paginated_list import PaginatedList


Expand Down Expand Up @@ -81,3 +80,25 @@ def create(

d = VPC(self.client, result["id"], result)
return d

def ips(self, *filters) -> PaginatedList:
"""
Retrieves all of the VPC IP addresses for the current account matching the given filters.

This is intended to be called from the :any:`LinodeClient`
class, like this::

vpc_ips = client.vpcs.ips()

API Documentation: TODO

:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.

:returns: A list of VPCIPAddresses the acting user can access.
:rtype: PaginatedList of VPCIPAddress
"""
return self.client._get_and_filter(
VPCIPAddress, *filters, endpoint="/vpcs/ips"
)
22 changes: 22 additions & 0 deletions test/fixtures/vpcs_ips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": [
{
"address": "10.0.0.2",
"address_range": null,
"vpc_id": 123,
"subnet_id": 456,
"region": "us-mia",
"linode_id": 123,
"config_id": 456,
"interface_id": 789,
"active": true,
"nat_1_1": "172.233.179.133",
"gateway": "10.0.0.1",
"prefix": 24,
"subnet_mask": "255.255.255.0"
}
],
"page": 1,
"pages": 1,
"results": 1
}
8 changes: 8 additions & 0 deletions test/integration/models/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from linode_api4 import VPCIPAddress
from linode_api4.errors import ApiError
from linode_api4.objects import (
Config,
Expand Down Expand Up @@ -595,6 +596,7 @@ def test_create_vlan(self, linode_for_network_interface_tests):

def test_create_vpc(
self,
test_linode_client,
linode_for_network_interface_tests,
create_vpc_with_subnet_and_linode,
):
Expand Down Expand Up @@ -635,6 +637,12 @@ def test_create_vpc(
assert vpc_range_ip.address_range == "10.0.0.5/32"
assert not vpc_range_ip.active

# Attempt to resolve the IP from /vpcs/ips
all_vpc_ips = test_linode_client.vpcs.ips(
VPCIPAddress.filters.linode_id == linode.id
)
assert all_vpc_ips[0].dict == vpc_ip.dict

def test_update_vpc(
self,
linode_for_network_interface_tests,
Expand Down
26 changes: 26 additions & 0 deletions test/unit/objects/vpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ def test_create_subnet(self):

self.validate_vpc_subnet_789(subnet)

def test_list_ips(self):
"""
Validates that all VPC IPs can be listed.
"""

with self.mock_get("/vpcs/ips") as m:
result = self.client.vpcs.ips()

assert m.call_url == "/vpcs/ips"
assert len(result) == 1

ip = result[0]
assert ip.address == "10.0.0.2"
assert ip.address_range == None
assert ip.vpc_id == 123
assert ip.subnet_id == 456
assert ip.region == "us-mia"
assert ip.linode_id == 123
assert ip.config_id == 456
assert ip.interface_id == 789
assert ip.active
assert ip.nat_1_1 == "172.233.179.133"
assert ip.gateway == "10.0.0.1"
assert ip.prefix == 24
assert ip.subnet_mask == "255.255.255.0"

def validate_vpc_123456(self, vpc: VPC):
expected_dt = datetime.datetime.strptime(
"2018-01-01T00:01:01", DATE_FORMAT
Expand Down