master
h 73 lines 4.38 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 ContainerService.h
8
9 Abstract:
10
11 This file contains the ContainerService definition
12
13 --*/
14 #pragma once
15 #include "SessionModel.h"
16 #include "ContainerModel.h"
17 #include "Terminal.h"
18 #include <docker_schema.h>
19 #include <wslc.h>
20 #include <wslc_schema.h>
21
22 namespace wsl::windows::wslc::services {
23 struct ContainerService
24 {
25 // Renders a container state with the time it last changed appended. Table output is localized;
26 // json output is invariant so its values do not vary by display language.
27 static std::wstring ContainerStateToString(WSLCContainerState state, LONGLONG stateChangedAt = 0, models::FormatType format = models::FormatType::Table);
28
29 // The bare state name, e.g. "running", without the relative time ContainerStateToString appends.
30 static std::wstring ContainerStateName(WSLCContainerState state);
31
32 // The display form of ContainerStateName, used for the table output.
33 static std::wstring LocalizedContainerStateName(WSLCContainerState state);
34
35 static std::wstring FormatPorts(WSLCContainerState state, const std::vector<models::PortInformation>& ports);
36
37 static std::wstring FormatCommand(const std::string& command, bool truncate);
38
39 // Renders the comma separated mount list. Docker shortens each name independently, so a long path
40 // never crowds out the mounts that follow it.
41 static std::wstring FormatMounts(const std::string& mounts, bool truncate);
42
43 // Renders a container status, preferring the description supplied by the runtime and falling back
44 // to a locally built one when it is unavailable. Only the fallback varies with the format, since
45 // the runtime supplied description is already invariant.
46 static std::wstring FormatStatus(
47 const std::string& status, WSLCContainerState state, LONGLONG stateChangedAt, models::FormatType format = models::FormatType::Table);
48
49 // Extracts the health status from a runtime supplied status description, which carries it as a
50 // parenthesized suffix. Containers without a health check report an empty string.
51 static std::string FormatHealthStatus(const std::string& status);
52 static int Attach(Terminal& terminal, models::Session& session, const std::string& id);
53 static int Run(Terminal& terminal, models::Session& session, const std::string& image, models::ContainerOptions options);
54 static models::CreateContainerResult Create(Terminal& terminal, models::Session& session, const std::string& image, models::ContainerOptions options);
55 static int Start(Terminal& terminal, models::Session& session, const std::string& id, bool attach = false);
56 static void Stop(models::Session& session, const std::string& id, models::StopContainerOptions options);
57 static void Restart(Terminal& terminal, models::Session& session, const std::string& id, models::StopContainerOptions options);
58 static void Kill(models::Session& session, const std::string& id, WSLCSignal signal = WSLCSignalSIGKILL);
59 static void Delete(models::Session& session, const std::string& id, bool force, bool deleteVolumes = false);
60 static std::vector<models::ContainerInformation> List(
61 models::Session& session, bool all = false, int limit = -1, const std::vector<std::pair<std::string, std::string>>& filters = {});
62
63 static int Exec(Terminal& terminal, models::Session& session, const std::string& id, models::ContainerOptions options);
64 static void Export(models::Session& session, const std::string& id, const std::wstring& outputPath);
65 static void Export(models::Session& session, const std::string& id, HANDLE outputHandle);
66 static void CopyToContainer(models::Session& session, const std::string& id, const std::string& destPath, HANDLE inputHandle, ULONGLONG contentSize);
67 static void CopyFromContainer(models::Session& session, const std::string& id, const std::string& srcPath, HANDLE outputHandle);
68 static wsl::windows::common::wslc_schema::InspectContainer Inspect(models::Session& session, const std::string& id, bool size = false);
69 static void Logs(models::Session& session, const std::string& id, bool follow, bool timestamps, LONGLONG since, LONGLONG until, ULONGLONG tail = 0);
70 static wsl::windows::common::docker_schema::ContainerStats Stats(models::Session& session, const std::string& id);
71 static models::PruneContainersResult Prune(models::Session& session);
72 };
73 } // namespace wsl::windows::wslc::services