Skip to content

Commit 4d14bbe

Browse files
authored
Merge pull request #102 from akx/floating-ip
Add basic floating IP support
2 parents 11d8a1d + 407297c commit 4d14bbe

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

test/json_data/ip_address_post.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"address": "10.1.0.101",
55
"family": "IPv4",
66
"ptr_record": "a.ptr.record",
7-
"server": "00798b85-efdc-41ca-8021-f6ef457b8531"
7+
"server": "00798b85-efdc-41ca-8021-f6ef457b8531",
8+
"floating": "yes",
9+
"zone": "fi-hel2"
810
}
9-
}
11+
}

test/test_ip_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ def test_ip_delete(self, manager):
4444
Mock.mock_delete('ip_address/10.1.0.101')
4545
res = manager.release_ip('10.1.0.101')
4646
assert res == {}
47+
48+
@responses.activate
49+
def test_create_floating_ip(self, manager):
50+
Mock.mock_post('ip_address')
51+
floating_ip = manager.create_floating_ip('fi-hel2')
52+
assert type(floating_ip).__name__ == 'IPAddress'
53+
assert floating_ip.floating == 'yes'
54+
assert floating_ip.zone == 'fi-hel2'

upcloud_api/cloud_manager/ip_address_mixin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ def release_ip(self, ip_addr):
5555
Accepts an IPAddress instance (object) or its address (string).
5656
"""
5757
return self.api.delete_request('/ip_address/' + str(ip_addr))
58+
59+
def create_floating_ip(self, zone: str, mac: str = '', family: str = 'IPv4') -> IPAddress:
60+
"""
61+
Create a floating IP and returns an IPAddress object.
62+
Specify MAC address of network interface to attach the floating IP when it is created
63+
"""
64+
body = {'ip_address': {'family': family, 'floating': 'yes', 'zone': zone}}
65+
if mac:
66+
body['ip_address']['mac'] = mac
67+
68+
res = self.api.post_request('/ip_address', body)
69+
return IPAddress(cloud_manager=self, **res['ip_address'])

0 commit comments

Comments
 (0)