From a3e0b7d117251944375fd32449f6b26d65edf367 Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 11 Nov 2020 09:45:07 -0600 Subject: add network connect|disconnect compat endpoints this enables the ability to connect and disconnect a container from a given network. it is only for the compatibility layer. some code had to be refactored to avoid circular imports. additionally, tests are being deferred temporarily due to some incompatibility/bug in either docker-py or our stack. Signed-off-by: baude --- libpod/container.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libpod/container.go') diff --git a/libpod/container.go b/libpod/container.go index 9009a4ec8..4b9e6a5ba 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -206,6 +206,10 @@ type ContainerState struct { // and not delegated to the OCI runtime. ExtensionStageHooks map[string][]spec.Hook `json:"extensionStageHooks,omitempty"` + // NetInterfaceDescriptions describe the relationship between a CNI + // network and an interface names + NetInterfaceDescriptions ContainerNetworkDescriptions `json:"networkDescriptions,omitempty"` + // containerPlatformState holds platform-specific container state. containerPlatformState } @@ -244,6 +248,10 @@ type ContainerImageVolume struct { ReadWrite bool `json:"rw"` } +// ContainerNetworkDescriptions describes the relationship between the CNI +// network and the ethN where N is an integer +type ContainerNetworkDescriptions map[string]int + // Config accessors // Unlocked @@ -1102,3 +1110,19 @@ func (c *Container) networksByNameIndex() (map[string]int, error) { } return networkNamesByIndex, nil } + +// add puts the new given CNI network name into the tracking map +// and assigns it a new integer based on the map length +func (d ContainerNetworkDescriptions) add(networkName string) { + d[networkName] = len(d) +} + +// getInterfaceByName returns a formatted interface name for a given +// network along with a bool as to whether the network existed +func (d ContainerNetworkDescriptions) getInterfaceByName(networkName string) (string, bool) { + val, exists := d[networkName] + if !exists { + return "", exists + } + return fmt.Sprintf("eth%d", val), exists +} -- cgit v1.2.3-54-g00ecf