-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add port mappings to container list output #14438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/wsl-for-apps
Are you sure you want to change the base?
Changes from all commits
aac55ae
8f9e2f3
1c3c77f
0a24110
fd8a3ff
f6a5ab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,33 @@ std::wstring ContainerService::ContainerStateToString(WSLAContainerState state, | |
| return std::format(L"{} {}", stateString, FormatRelativeTime(stateChangedAt)); | ||
| } | ||
|
|
||
| std::wstring ContainerService::FormatPorts(const std::vector<PortInformation>& ports) | ||
| { | ||
| if (ports.empty()) | ||
| { | ||
| return L""; | ||
| } | ||
|
|
||
| std::wstring result; | ||
| for (size_t i = 0; i < ports.size(); ++i) | ||
| { | ||
| const auto& port = ports[i]; | ||
|
|
||
| // AF_INET = 2, AF_INET6 = 23 | ||
| std::wstring hostIp = (port.Family == AF_INET6) ? L"[::]" : L"0.0.0.0"; | ||
| std::wstring protocol = (port.Protocol == IPPROTO_UDP) ? L"udp" : L"tcp"; | ||
|
|
||
| if (i > 0) | ||
| { | ||
| result += L", "; | ||
| } | ||
|
|
||
| result += std::format(L"{}:{}->{}/{}", hostIp, port.HostPort, port.ContainerPort, protocol); | ||
|
Comment on lines
+261
to
+270
|
||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| int ContainerService::Run(Session& session, const std::string& image, ContainerOptions runOptions, IProgressCallback* callback) | ||
| { | ||
| // Create the container | ||
|
|
@@ -323,6 +350,25 @@ std::vector<ContainerInformation> ContainerService::List(Session& session) | |
| entry.Id = current.Id; | ||
| entry.StateChangedAt = current.StateChangedAt; | ||
| entry.CreatedAt = current.CreatedAt; | ||
|
|
||
| // Extract ports | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend putting port extraction/processing into a common method, we probably want to use the same for argument validation. |
||
| for (ULONG i = 0; i < current.PortsCount; ++i) | ||
| { | ||
| PortInformation port; | ||
| port.HostPort = current.Ports[i].HostPort; | ||
| port.ContainerPort = current.Ports[i].ContainerPort; | ||
| port.Family = current.Ports[i].Family; | ||
| port.Protocol = static_cast<int>(current.Ports[i].Protocol); | ||
beena352 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| entry.Ports.push_back(port); | ||
| } | ||
|
|
||
| // Free nested ports array | ||
| for (ULONG i = 0; i < current.PortsCount; ++i) | ||
| { | ||
| CoTaskMemFree(const_cast<LPSTR>(current.Ports[i].BindingAddress)); | ||
| } | ||
| CoTaskMemFree(current.Ports); | ||
|
|
||
| result.emplace_back(std::move(entry)); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.