diff options
Diffstat (limited to 'libpod/network')
-rw-r--r-- | libpod/network/create.go | 7 | ||||
-rw-r--r-- | libpod/network/create_test.go | 3 | ||||
-rw-r--r-- | libpod/network/devices.go | 4 | ||||
-rw-r--r-- | libpod/network/files.go | 6 | ||||
-rw-r--r-- | libpod/network/netconflist.go | 2 | ||||
-rw-r--r-- | libpod/network/netconflist_test.go | 1 | ||||
-rw-r--r-- | libpod/network/network.go | 27 |
7 files changed, 31 insertions, 19 deletions
diff --git a/libpod/network/create.go b/libpod/network/create.go index deacf487a..1a5aa82fc 100644 --- a/libpod/network/create.go +++ b/libpod/network/create.go @@ -10,9 +10,9 @@ import ( "github.com/containernetworking/cni/pkg/version" "github.com/containers/common/pkg/config" - "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/containers/podman/v2/pkg/rootless" - "github.com/containers/podman/v2/pkg/util" + "github.com/containers/podman/v3/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/rootless" + "github.com/containers/podman/v3/pkg/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -75,7 +75,6 @@ func validateBridgeOptions(options entities.NetworkCreateOptions) error { } return nil - } // parseMTU parses the mtu option diff --git a/libpod/network/create_test.go b/libpod/network/create_test.go index 0b828e635..c3824bd91 100644 --- a/libpod/network/create_test.go +++ b/libpod/network/create_test.go @@ -4,11 +4,10 @@ import ( "net" "testing" - "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/domain/entities" ) func Test_validateBridgeOptions(t *testing.T) { - tests := []struct { name string subnet net.IPNet diff --git a/libpod/network/devices.go b/libpod/network/devices.go index a5d23fae4..de6bb4efc 100644 --- a/libpod/network/devices.go +++ b/libpod/network/devices.go @@ -5,8 +5,8 @@ import ( "os/exec" "github.com/containers/common/pkg/config" - "github.com/containers/podman/v2/pkg/util" - "github.com/containers/podman/v2/utils" + "github.com/containers/podman/v3/pkg/util" + "github.com/containers/podman/v3/utils" "github.com/sirupsen/logrus" ) diff --git a/libpod/network/files.go b/libpod/network/files.go index 33cf01064..fe483e25c 100644 --- a/libpod/network/files.go +++ b/libpod/network/files.go @@ -10,7 +10,7 @@ import ( "github.com/containernetworking/cni/libcni" "github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator" "github.com/containers/common/pkg/config" - "github.com/containers/podman/v2/libpod/define" + "github.com/containers/podman/v3/libpod/define" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -81,9 +81,9 @@ func GetCNIConfigPathByNameOrID(config *config.Config, name string) (string, err return "", errors.Wrap(define.ErrNoSuchNetwork, fmt.Sprintf("unable to find network configuration for %s", name)) } -// ReadRawCNIConfByName reads the raw CNI configuration for a CNI +// ReadRawCNIConfByNameOrID reads the raw CNI configuration for a CNI // network by name -func ReadRawCNIConfByName(config *config.Config, name string) ([]byte, error) { +func ReadRawCNIConfByNameOrID(config *config.Config, name string) ([]byte, error) { confFile, err := GetCNIConfigPathByNameOrID(config, name) if err != nil { return nil, err diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go index 9be98e78f..1a1583587 100644 --- a/libpod/network/netconflist.go +++ b/libpod/network/netconflist.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/containernetworking/cni/libcni" - "github.com/containers/podman/v2/pkg/util" + "github.com/containers/podman/v3/pkg/util" "github.com/pkg/errors" ) diff --git a/libpod/network/netconflist_test.go b/libpod/network/netconflist_test.go index 5ff733f0f..161764ed9 100644 --- a/libpod/network/netconflist_test.go +++ b/libpod/network/netconflist_test.go @@ -7,7 +7,6 @@ import ( ) func TestNewIPAMDefaultRoute(t *testing.T) { - tests := []struct { name string isIPv6 bool diff --git a/libpod/network/network.go b/libpod/network/network.go index cdaef6c13..f19a764ef 100644 --- a/libpod/network/network.go +++ b/libpod/network/network.go @@ -7,13 +7,14 @@ import ( "net" "os" + "github.com/containernetworking/cni/libcni" "github.com/containernetworking/cni/pkg/types" "github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator" "github.com/containers/common/pkg/config" - "github.com/containers/podman/v2/libpod/define" - "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/containers/podman/v2/pkg/rootless" - "github.com/containers/podman/v2/pkg/util" + "github.com/containers/podman/v3/libpod/define" + "github.com/containers/podman/v3/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/rootless" + "github.com/containers/podman/v3/pkg/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -222,7 +223,7 @@ func RemoveNetwork(config *config.Config, name string) error { // InspectNetwork reads a CNI config and returns its configuration func InspectNetwork(config *config.Config, name string) (map[string]interface{}, error) { - b, err := ReadRawCNIConfByName(config, name) + b, err := ReadRawCNIConfByNameOrID(config, name) if err != nil { return nil, err } @@ -234,7 +235,7 @@ func InspectNetwork(config *config.Config, name string) (map[string]interface{}, // Exists says whether a given network exists or not; it meant // specifically for restful responses so 404s can be used func Exists(config *config.Config, name string) (bool, error) { - _, err := ReadRawCNIConfByName(config, name) + _, err := ReadRawCNIConfByNameOrID(config, name) if err != nil { if errors.Cause(err) == define.ErrNoSuchNetwork { return false, nil @@ -277,3 +278,17 @@ func PruneNetworks(rtc *config.Config, usedNetworks map[string]bool) ([]*entitie } return reports, nil } + +// NormalizeName translates a network ID into a name. +// If the input is a name the name is returned. +func NormalizeName(config *config.Config, nameOrID string) (string, error) { + path, err := GetCNIConfigPathByNameOrID(config, nameOrID) + if err != nil { + return "", err + } + conf, err := libcni.ConfListFromFile(path) + if err != nil { + return "", err + } + return conf.Name, nil +} |