Support attaching and detaching containers to networks after creation#40549
Support attaching and detaching containers to networks after creation#40549beena352 wants to merge 2 commits into
Conversation
| HRESULT DeleteNetwork([in] LPCSTR Name); | ||
| HRESULT ListNetworks([out, size_is(, *Count)] WSLCNetworkInformation** Networks, [out] ULONG* Count); | ||
| HRESULT InspectNetwork([in] LPCSTR Name, [out] LPSTR* Output); | ||
| HRESULT AttachContainerToNetwork([in] LPCSTR ContainerId, [in] const WSLCNetworkAttachment* Attachment); |
There was a problem hiding this comment.
I would recommend moving those methods to WSLCContainer instead. That way we don't need to perform the container lookup in the method's implementation. That will also take care of container names and id prefixes for us
| THROW_HR_WITH_USER_ERROR_IF( | ||
| WSLC_E_CONTAINER_NOT_FOUND, Localization::MessageWslcContainerNotFound(containerId), containerIt == m_containers.end()); | ||
|
|
||
| auto networkIt = m_networks.find(networkName); |
There was a problem hiding this comment.
Could we just let docker handle the network not found error for us ? That would allow us to easily support the container:<id> case
…eenachauhan/wslc-attach-detach-network # Conflicts: # test/windows/WSLCTests.cpp
There was a problem hiding this comment.
Pull request overview
This PR adds WSLC APIs intended to attach and detach already-created containers from WSLC-managed Docker networks, plus tests for the new attach/detach behavior.
Changes:
- Adds session-level
AttachContainerToNetworkandDetachContainerFromNetworkdeclarations and implementations. - Adds Docker HTTP client helpers and request schema types for network connect/disconnect endpoints.
- Adds WSLC tests covering round-trip attach/detach and several validation paths.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/service/inc/wslc.idl |
Adds new network attach/detach methods to IWSLCSession. |
src/windows/wslcsession/WSLCSession.h |
Declares the new session methods. |
src/windows/wslcsession/WSLCSession.cpp |
Implements validation, lookup, Docker connect/disconnect calls, and logging. |
src/windows/wslcsession/WSLCContainer.h |
Exposes container network mode to session logic. |
src/windows/wslcsession/DockerHTTPClient.h |
Declares Docker network connect/disconnect helpers. |
src/windows/wslcsession/DockerHTTPClient.cpp |
Implements Docker network connect/disconnect endpoint calls. |
src/windows/inc/docker_schema.h |
Adds request payload schemas for Docker network connect/disconnect. |
test/windows/WSLCTests.cpp |
Adds tests for attach/detach network behavior and validation. |
Comments suppressed due to low confidence (4)
test/windows/WSLCTests.cpp:6293
- This call targets
IWSLCContainer::AttachToNetwork, but that method is not declared onIWSLCContainer; the added API isIWSLCSession::AttachContainerToNetwork. Update the test to call through the session with the launched container's ID.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6321
- This call will not compile because
AttachToNetworkis not part ofIWSLCContainer; the new attach method is onIWSLCSession. Use the session-level API with this container's ID.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6332
- This call will not compile because
AttachToNetworkis not declared onIWSLCContainer; call the session-level attach API with the container ID instead.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6347
- This call targets a non-existent
IWSLCContainer::AttachToNetworkmethod. The attach API added in this PR is session-level, so the test should useAttachContainerToNetworkon the session with the container ID.
VERIFY_ARE_EQUAL(E_NOTIMPL, container.Get().AttachToNetwork(&attachment));
|
|
||
| WSLCNetworkAttachment attachment{}; | ||
| attachment.NetworkName = networkName.c_str(); | ||
| VERIFY_SUCCEEDED(container.Get().AttachToNetwork(&attachment)); |
| VERIFY_IS_TRUE(inspect.NetworkSettings.Networks.contains(networkName)); | ||
| VERIFY_IS_FALSE(inspect.NetworkSettings.Networks.at(networkName).IPAddress.empty()); | ||
|
|
||
| VERIFY_SUCCEEDED(container.Get().DetachFromNetwork(networkName.c_str())); |
| @@ -790,6 +790,8 @@ interface IWSLCSession : IUnknown | |||
| HRESULT DeleteNetwork([in] LPCSTR Name); | |||
| HRESULT ListNetworks([out, size_is(, *Count)] WSLCNetworkInformation** Networks, [out] ULONG* Count); | |||
| HRESULT InspectNetwork([in] LPCSTR Name, [out] LPSTR* Output); | |||
Summary of the Pull Request
Implements AttachContainerToNetwork and DetachContainerFromNetwork methods on IWSLCSession, enabling containers to join/leave networks after they are created and running.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed