Skip to content

Commit

Permalink
new network plugin architecture for agent
Browse files Browse the repository at this point in the history
  • Loading branch information
kyujin-cho committed Oct 8, 2024
1 parent e99ef2d commit 92eaede
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ai/backend/agent/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ python_distribution(
"ag": "ai.backend.agent.cli:main",
"ag.start-server": "ai.backend.agent.server:main",
},
"backendai_network_agent_v1": {
"overlay": "ai.backend.agent.docker.intrinsic:OverlayNetworkPlugin",
}
},
generate_setup=True,
tags=["wheel"],
Expand Down
30 changes: 30 additions & 0 deletions src/ai/backend/agent/docker/intrinsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
from aiodocker.docker import Docker, DockerContainer
from aiodocker.exceptions import DockerError

from ai.backend.agent.docker.kernel import DockerKernel
from ai.backend.agent.plugin.network import AbstractNetworkAgentPlugin
from ai.backend.agent.types import MountInfo
from ai.backend.common.netns import nsenter
from ai.backend.common.types import (
AcceleratorMetadata,
ClusterInfo,
DeviceId,
DeviceModelInfo,
DeviceName,
KernelCreationConfig,
MetricKey,
SlotName,
SlotTypes,
Expand Down Expand Up @@ -936,3 +940,29 @@ def get_metadata(self) -> AcceleratorMetadata:
"number_format": {"binary": True, "round_length": 0},
"display_icon": "ram",
}


class OverlayNetworkPlugin(AbstractNetworkAgentPlugin):
async def join_network(
self,
kernel_config: KernelCreationConfig,
cluster_info: ClusterInfo,
*,
network_name: str,
**options,
) -> dict[str, Any]:
return {
"HostConfig": {
"NetworkMode": network_name,
},
"NetworkingConfig": {
"EndpointsConfig": {
network_name: {
"Aliases": [kernel_config["cluster_hostname"]],
},
},
},
}

async def leave_network(self, kernel: DockerKernel) -> None:
pass
1 change: 1 addition & 0 deletions src/ai/backend/agent/plugin/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources(name="src")
34 changes: 34 additions & 0 deletions src/ai/backend/agent/plugin/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from abc import ABCMeta, abstractmethod
from typing import Any

from ai.backend.agent.kernel import AbstractKernel
from ai.backend.common.plugin import AbstractPlugin, BasePluginContext
from ai.backend.common.types import ClusterInfo, KernelCreationConfig


class AbstractNetworkAgentPlugin(AbstractPlugin, metaclass=ABCMeta):
@abstractmethod
async def join_network(
self,
kernel_config: KernelCreationConfig,
cluster_info: ClusterInfo,
**kwargs,
) -> dict[str, Any]:
"""
Returns required container config to attach container to network.
"""
raise NotImplementedError

@abstractmethod
async def leave_network(
self,
kernel: AbstractKernel,
) -> None:
"""
Performs extra step to make container leave from the network.
"""
raise NotImplementedError


class NetworkPluginContext(BasePluginContext[AbstractNetworkAgentPlugin]):
plugin_group = "backendai_network_client_v1"

0 comments on commit 92eaede

Please sign in to comment.