Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,26 @@ For privacy information about this product please visit https://aka.ms/privacy.<
<value>Volume '{}' is in use.</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcNetworkNotFound" xml:space = "preserve" >
<value>Network not found: '{}'</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcInvalidNetworkDriver" xml:space = "preserve" >
<value>Unsupported network driver: '{}'</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcNetworkInUse" xml:space = "preserve" >
<value>Network '{}' has active endpoints.</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcNetworkAlreadyExists" xml:space = "preserve" >
<value>Network '{}' already exists.</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcInvalidNetworkOptions" xml:space = "preserve" >
<value>Invalid network options: '{}'</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name = "MessageWslcFailedToMountVolume" xml:space = "preserve" >
<value>Failed to create volume '{}': {}</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
Expand Down
50 changes: 50 additions & 0 deletions src/windows/inc/docker_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,56 @@ struct ListVolumesResponse
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ListVolumesResponse, Volumes);
};

struct IPAMConfig
{
std::string Subnet;
std::string Gateway;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(IPAMConfig, Subnet, Gateway);
Comment thread
beena352 marked this conversation as resolved.
};

struct IPAM
{
std::string Driver;
std::optional<std::vector<IPAMConfig>> Config;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(IPAM, Driver, Config);
};

struct CreateNetworkResponse
{
std::string Id;
std::string Warning;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateNetworkResponse, Id, Warning);
};

struct CreateNetwork
{
using TResponse = CreateNetworkResponse;

std::string Name;
std::string Driver;
bool Internal{};
std::optional<IPAM> IPAM;
std::map<std::string, std::string> Labels;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateNetwork, Name, Driver, Internal, IPAM, Labels);
};
Comment thread
beena352 marked this conversation as resolved.

struct Network
{
std::string Id;
std::string Name;
std::string Driver;
std::string Scope;
bool Internal{};
IPAM IPAM;
std::map<std::string, std::string> Labels;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Network, Id, Name, Driver, Scope, Internal, IPAM, Labels);
};

struct EmptyObject
{
};
Expand Down
24 changes: 24 additions & 0 deletions src/windows/service/inc/wslc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ cpp_quote("#endif")
#define WSLC_MAX_IMAGE_NAME_LENGTH 255
#define WSLC_MAX_VOLUME_NAME_LENGTH 255
#define WSLC_MAX_VOLUME_DRIVER_LENGTH 255
#define WSLC_MAX_NETWORK_NAME_LENGTH 255
#define WSLC_CONTAINER_ID_LENGTH 64
#define WSLC_MAX_BINDING_ADDRESS_LENGTH 45

cpp_quote("#define WSLC_MAX_CONTAINER_NAME_LENGTH 255")
cpp_quote("#define WSLC_MAX_IMAGE_NAME_LENGTH 255")
cpp_quote("#define WSLC_MAX_VOLUME_NAME_LENGTH 255")
cpp_quote("#define WSLC_MAX_VOLUME_DRIVER_LENGTH 255")
cpp_quote("#define WSLC_MAX_NETWORK_NAME_LENGTH 255")
cpp_quote("#define WSLC_CONTAINER_ID_LENGTH 64")
cpp_quote("#define WSLC_MAX_BINDING_ADDRESS_LENGTH 45")

Expand Down Expand Up @@ -591,6 +593,22 @@ typedef struct _WSLCPruneVolumesResults
ULONGLONG SpaceReclaimed;
} WSLCPruneVolumesResults;

typedef struct _WSLCNetworkOptions
{
LPCSTR Name;
LPCSTR Driver;
[unique] LPCSTR Options;
[unique, size_is(LabelsCount)] const WSLCLabel* Labels;
ULONG LabelsCount;
} WSLCNetworkOptions;

typedef struct _WSLCNetworkInformation
{
char Name[WSLC_MAX_NETWORK_NAME_LENGTH + 1];
char Id[WSLC_CONTAINER_ID_LENGTH + 1];
char Driver[64];
} WSLCNetworkInformation;

typedef struct _WSLCPruneLabelFilter
{
LPCSTR Key;
Expand Down Expand Up @@ -719,6 +737,11 @@ interface IWSLCSession : IUnknown
HRESULT Authenticate([in] LPCSTR ServerAddress, [in] LPCSTR Username, [in] LPCSTR Password, [out] LPSTR* IdentityToken);
HRESULT PushImage([in] LPCSTR Image, [in] LPCSTR RegistryAuthenticationInformation, [in, unique] IProgressCallback* ProgressCallback);
HRESULT PruneVolumes([in, unique] const WSLCPruneVolumesOptions* Options, [out] WSLCPruneVolumesResults* Results);

// Network management.
HRESULT CreateNetwork([in] const WSLCNetworkOptions* Options);
HRESULT DeleteNetwork([in] LPCSTR Name);
HRESULT ListNetworks([out, size_is(, *Count)] WSLCNetworkInformation** Networks, [out] ULONG* Count);
}

//
Expand Down Expand Up @@ -807,3 +830,4 @@ cpp_quote("#define WSLC_E_CONTAINER_NOT_RUNNING MAKE_HRESULT(SEVERITY_ERROR, FAC
cpp_quote("#define WSLC_E_CONTAINER_IS_RUNNING MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 6) /* 0x80040606 */")
cpp_quote("#define WSLC_E_SESSION_RESERVED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 7) /* 0x80040607 */")
cpp_quote("#define WSLC_E_INVALID_SESSION_NAME MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 8) /* 0x80040608 */")
cpp_quote("#define WSLC_E_NETWORK_NOT_FOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 9) /* 0x80040609 */")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new error should be added to g_commonErrors, in wslutil.cpp

15 changes: 15 additions & 0 deletions src/windows/wslcsession/DockerHTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,21 @@ std::vector<docker_schema::Volume> DockerHTTPClient::ListVolumes()
return response.Volumes;
}

docker_schema::CreateNetworkResponse DockerHTTPClient::CreateNetwork(const docker_schema::CreateNetwork& Request)
{
return Transaction(verb::post, URL::Create("/networks/create"), Request);
}

void DockerHTTPClient::RemoveNetwork(const std::string& Name)
{
Transaction(verb::delete_, URL::Create("/networks/{}", Name));
}

std::vector<docker_schema::Network> DockerHTTPClient::ListNetworks()
{
return Transaction<docker_schema::EmptyRequest, std::vector<docker_schema::Network>>(verb::get, URL::Create("/networks"));
}

wil::unique_socket DockerHTTPClient::ContainerLogs(const std::string& Id, WSLCLogsFlags Flags, ULONGLONG Since, ULONGLONG Until, ULONGLONG Tail)
{
auto url = URL::Create("/containers/{}/logs", Id);
Expand Down
5 changes: 5 additions & 0 deletions src/windows/wslcsession/DockerHTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class DockerHTTPClient
void RemoveVolume(const std::string& Name);
std::vector<common::docker_schema::Volume> ListVolumes();

// Network management.
common::docker_schema::CreateNetworkResponse CreateNetwork(const common::docker_schema::CreateNetwork& Request);
void RemoveNetwork(const std::string& Name);
std::vector<common::docker_schema::Network> ListNetworks();

// Image management.
struct ListImagesFilters
{
Expand Down
37 changes: 37 additions & 0 deletions src/windows/wslcsession/WSLCNetworkMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

WSLCNetworkMetadata.h

Abstract:

Constants and types for WSLC-managed Docker networks.

--*/

#pragma once

#include <string>

namespace wsl::windows::service::wslc {

// Label key used to identify WSLC-managed Docker networks.
constexpr auto WSLCNetworkManagedLabel = "com.microsoft.wsl.network.managed";
constexpr auto WSLCBridgeNetworkDriver = "bridge";

// Reserved Docker network names that cannot be used for custom networks.
inline bool IsReservedNetworkName(const std::string& name)
{
return name == "bridge" || name == "host" || name == "none";
}

struct NetworkEntry
{
std::string Id;
std::string Driver;
};

} // namespace wsl::windows::service::wslc
Loading