Skip to content

Commit

Permalink
recycle IP addresses for terminated services
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeofblue committed Nov 16, 2022
1 parent d876107 commit 054f068
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions yapapi/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ async def add_node(self, node_id: str, ip: Optional[str] = None) -> Node:

return node

async def remove_node(self, node_id: str) -> None:
"""Remove the node from the network.
:param node_id: Node ID within the Golem network of the VPN node to be removed.
"""

await self._net_api.remove_node(self.network_id, node_id)

async with self._nodes_lock:
del self._nodes[node_id]

async def _refresh_node(self, node: Node):
logger.debug("refreshing node %s", node)
try:
Expand Down
3 changes: 3 additions & 0 deletions yapapi/rest/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ async def add_address(self, network_id: str, ip: str):

async def add_node(self, network_id: str, node_id: str, ip: str):
await self._api.add_node(network_id, yan.Node(node_id, ip))

async def remove_node(self, network_id: str, node_id: str):
await self._api.remove_node(network_id, node_id)
3 changes: 3 additions & 0 deletions yapapi/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def _set_ctx(self, ctx: WorkContext) -> None:
def _set_network_node(self, node: Node) -> None:
self._network_node = node

def _clear_network_node(self) -> None:
self._network_node = None

def __repr__(self):
class_name = type(self).__name__
state = self.state.value
Expand Down
3 changes: 3 additions & 0 deletions yapapi/services/service_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ async def _worker(work_context: WorkContext) -> None:
work_context.emit(events.WorkerFinished, exc_info=sys.exc_info())
raise
finally:
if network and service.network_node:
await network.remove_node(work_context.provider_id)
service._clear_network_node()
await self._job.engine.accept_payments_for_agreement(self._job.id, agreement.id)
await self._job.agreements_pool.release_agreement(agreement.id, allow_reuse=False)

Expand Down

0 comments on commit 054f068

Please sign in to comment.