Skip to content

Commit a6fda9c

Browse files
Merge pull request #317 from linode/dev
Release v5.7.1
2 parents 7fffe8c + 12c60ef commit a6fda9c

File tree

6 files changed

+81
-9
lines changed

6 files changed

+81
-9
lines changed

linode_api4/groups/group.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from linode_api4 import LinodeClient
7+
8+
19
class Group:
2-
def __init__(self, client: "LinodeClient"):
10+
def __init__(self, client: LinodeClient):
311
self.client = client

linode_api4/groups/networking.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,32 @@ def ips_share(self, linode, *ips):
284284

285285
def ip_addresses_share(self, ips, linode):
286286
"""
287-
Configure shared IPs. P sharing allows IP address reassignment
287+
Configure shared IPs. IP sharing allows IP address reassignment
288288
(also referred to as IP failover) from one Linode to another if the
289289
primary Linode becomes unresponsive. This means that requests to the primary Linode’s
290290
IP address can be automatically rerouted to secondary Linodes at the configured shared IP addresses.
291291
292+
API Documentation: https://www.linode.com/docs/api/networking/#ip-addresses-share
293+
292294
:param linode: The id of the Instance or the Instance to share the IPAddresses with.
293295
This Instance will be able to bring up the given addresses.
294296
:type: linode: int or Instance
295-
:param ips: Any number of IPAddresses to share to the Instance.
297+
:param ips: Any number of IPAddresses to share to the Instance. Enter an empty array to
298+
remove all shared IP addresses.
296299
:type ips: str or IPAddress
297300
"""
298301

302+
shared_ips = []
303+
for ip in ips:
304+
if isinstance(ip, str):
305+
shared_ips.append(ip)
306+
elif isinstance(ip, IPAddress):
307+
shared_ips.append(ip.address)
308+
else:
309+
shared_ips.append(str(ip)) # and hope that works
310+
299311
params = {
300-
"ips": ips
301-
if not isinstance(ips[0], IPAddress)
302-
else [ip.address for ip in ips],
312+
"ips": shared_ips,
303313
"linode_id": linode
304314
if not isinstance(linode, Instance)
305315
else linode.id,

linode_api4/linode_client.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,25 @@
1010
from requests.adapters import HTTPAdapter, Retry
1111

1212
from linode_api4.errors import ApiError, UnexpectedResponseError
13-
from linode_api4.groups import *
14-
from linode_api4.objects import *
13+
from linode_api4.groups import (
14+
AccountGroup,
15+
DatabaseGroup,
16+
DomainGroup,
17+
ImageGroup,
18+
LinodeGroup,
19+
LKEGroup,
20+
LongviewGroup,
21+
NetworkingGroup,
22+
NodeBalancerGroup,
23+
ObjectStorageGroup,
24+
PollingGroup,
25+
ProfileGroup,
26+
RegionGroup,
27+
SupportGroup,
28+
TagGroup,
29+
VolumeGroup,
30+
)
31+
from linode_api4.objects import Image, and_
1532
from linode_api4.objects.filtering import Filter
1633

1734
from .common import SSH_KEY_TYPES, load_and_validate_keys

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ line-length = 80
1111
target-version = ["py37", "py38", "py39", "py310", "py311"]
1212

1313
[tool.autoflake]
14-
expand-star-imports = false
14+
expand-star-imports = true
1515
ignore-init-module-imports = true
1616
ignore-pass-after-docstring = true
1717
in-place = true
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/integration/models/test_networking.py

+36
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,39 @@ def test_get_networking_rules(get_client, create_firewall):
1313
assert "inbound_policy" in str(rules)
1414
assert "outbound" in str(rules)
1515
assert "outbound_policy" in str(rules)
16+
17+
18+
@pytest.mark.smoke
19+
def test_ip_addresses_share(self):
20+
"""
21+
Test that you can share IP addresses with Linode.
22+
"""
23+
ip_share_url = "/networking/ips/share"
24+
ips = ["127.0.0.1"]
25+
linode_id = 12345
26+
with self.mock_post(ip_share_url) as m:
27+
result = self.client.networking.ip_addresses_share(ips, linode_id)
28+
29+
self.assertIsNotNone(result)
30+
self.assertEqual(m.call_url, ip_share_url)
31+
self.assertEqual(
32+
m.call_data,
33+
{
34+
"ips": ips,
35+
"linode": linode_id,
36+
},
37+
)
38+
39+
# Test that entering an empty IP array is allowed.
40+
with self.mock_post(ip_share_url) as m:
41+
result = self.client.networking.ip_addresses_share([], linode_id)
42+
43+
self.assertIsNotNone(result)
44+
self.assertEqual(m.call_url, ip_share_url)
45+
self.assertEqual(
46+
m.call_data,
47+
{
48+
"ips": [],
49+
"linode": linode_id,
50+
},
51+
)

0 commit comments

Comments
 (0)