Skip to content

Commit 188d126

Browse files
committed
add "new_address()" method
1 parent b892409 commit 188d126

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ip_pool/ip_pool.py

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def initialize(self, ipv4_cidr_address: str):
3939
self._prefix_len = prefix_len
4040
self._save()
4141

42+
def new_address(self, hostname: str):
43+
if hostname in self._hostnames:
44+
raise IPAddressPoolException(f"Hostname {hostname}")
45+
try:
46+
addr = self._ipaddr_pool.pop(0)
47+
except IndexError:
48+
raise IPAddressPoolException("Uninitialized address pool")
49+
self._hostnames[hostname] = addr
50+
self._save()
51+
return addr
52+
4253
def _to_dict(self):
4354
_dict = {
4455
"ip_version": self._ip_version,

0 commit comments

Comments
 (0)