mirror of
https://github.com/containers/podman.git
synced 2025-05-23 18:17:53 +08:00
add macvlan as a supported network driver
instead of using the --macvlan to indicate that you want to make a macvlan network, podman network create now honors the driver name of *macvlan*. Any options to macvlan, like the parent device, should be specified as a -o option. For example, -o parent=eth0. the --macvlan option was marked as deprecated in the man page but is still supported for the duration of 3.0. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -7,8 +7,9 @@ podman\-network-create - Create a Podman CNI network
|
|||||||
**podman network create** [*options*] name
|
**podman network create** [*options*] name
|
||||||
|
|
||||||
## DESCRIPTION
|
## DESCRIPTION
|
||||||
Create a CNI-network configuration for use with Podman. By default, Podman creates a bridge connection. A
|
Create a CNI-network configuration for use with Podman. By default, Podman creates a bridge connection.
|
||||||
*Macvlan* connection can be created with the *macvlan* option. In the case of *Macvlan* connections, the
|
A *Macvlan* connection can be created with the *-d macvlan* option. A parent device for macvlan can
|
||||||
|
be designated with the *-o parent=<device>* option. In the case of *Macvlan* connections, the
|
||||||
CNI *dhcp* plugin needs to be activated or the container image must have a DHCP client to interact
|
CNI *dhcp* plugin needs to be activated or the container image must have a DHCP client to interact
|
||||||
with the host network's DHCP server.
|
with the host network's DHCP server.
|
||||||
|
|
||||||
@ -55,6 +56,8 @@ Set metadata for a network (e.g., --label mykey=value).
|
|||||||
|
|
||||||
#### **--macvlan**
|
#### **--macvlan**
|
||||||
|
|
||||||
|
*This option is being deprecated*
|
||||||
|
|
||||||
Create a *Macvlan* based connection rather than a classic bridge. You must pass an interface name from the host for the
|
Create a *Macvlan* based connection rather than a classic bridge. You must pass an interface name from the host for the
|
||||||
Macvlan connection.
|
Macvlan connection.
|
||||||
|
|
||||||
@ -101,7 +104,7 @@ Create a network that uses a *192.168.55.0/24** subnet and has an IP address ran
|
|||||||
|
|
||||||
Create a Macvlan based network using the host interface eth0
|
Create a Macvlan based network using the host interface eth0
|
||||||
```
|
```
|
||||||
# podman network create --macvlan eth0 newnet
|
# podman network create -d macvlan -o parent=eth0 newnet
|
||||||
/etc/cni/net.d/newnet.conflist
|
/etc/cni/net.d/newnet.conflist
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func Create(name string, options entities.NetworkCreateOptions, runtimeConfig *c
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer l.releaseCNILock()
|
defer l.releaseCNILock()
|
||||||
if len(options.MacVLAN) > 0 {
|
if len(options.MacVLAN) > 0 || options.Driver == MacVLANNetworkDriver {
|
||||||
fileName, err = createMacVLAN(name, options, runtimeConfig)
|
fileName, err = createMacVLAN(name, options, runtimeConfig)
|
||||||
} else {
|
} else {
|
||||||
fileName, err = createBridge(name, options, runtimeConfig)
|
fileName, err = createBridge(name, options, runtimeConfig)
|
||||||
@ -256,9 +256,17 @@ func createMacVLAN(name string, options entities.NetworkCreateOptions, runtimeCo
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the host-device exists
|
// The parent can be defined with --macvlan or as an option (-o parent:device)
|
||||||
if !util.StringInSlice(options.MacVLAN, liveNetNames) {
|
parentNetworkDevice := options.MacVLAN
|
||||||
return "", errors.Errorf("failed to find network interface %q", options.MacVLAN)
|
if len(parentNetworkDevice) < 1 {
|
||||||
|
if parent, ok := options.Options["parent"]; ok {
|
||||||
|
parentNetworkDevice = parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the host-device exists if provided
|
||||||
|
if len(parentNetworkDevice) > 0 && !util.StringInSlice(parentNetworkDevice, liveNetNames) {
|
||||||
|
return "", errors.Errorf("failed to find network interface %q", parentNetworkDevice)
|
||||||
}
|
}
|
||||||
if len(name) > 0 {
|
if len(name) > 0 {
|
||||||
netNames, err := GetNetworkNamesFromFileSystem(runtimeConfig)
|
netNames, err := GetNetworkNamesFromFileSystem(runtimeConfig)
|
||||||
@ -275,7 +283,7 @@ func createMacVLAN(name string, options entities.NetworkCreateOptions, runtimeCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ncList := NewNcList(name, version.Current(), options.Labels)
|
ncList := NewNcList(name, version.Current(), options.Labels)
|
||||||
macvlan := NewMacVLANPlugin(options.MacVLAN)
|
macvlan := NewMacVLANPlugin(parentNetworkDevice)
|
||||||
plugins = append(plugins, macvlan)
|
plugins = append(plugins, macvlan)
|
||||||
ncList["plugins"] = plugins
|
ncList["plugins"] = plugins
|
||||||
b, err := json.MarshalIndent(ncList, "", " ")
|
b, err := json.MarshalIndent(ncList, "", " ")
|
||||||
|
@ -177,9 +177,13 @@ func NewMacVLANPlugin(device string) MacVLANConfig {
|
|||||||
|
|
||||||
m := MacVLANConfig{
|
m := MacVLANConfig{
|
||||||
PluginType: "macvlan",
|
PluginType: "macvlan",
|
||||||
Master: device,
|
|
||||||
IPAM: i,
|
IPAM: i,
|
||||||
}
|
}
|
||||||
|
// CNI is supposed to use the default route if a
|
||||||
|
// parent device is not provided
|
||||||
|
if len(device) > 0 {
|
||||||
|
m.Master = device
|
||||||
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,11 +17,17 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultNetworkDriver is the default network type used
|
var (
|
||||||
var DefaultNetworkDriver = "bridge"
|
// BridgeNetworkDriver defines the bridge cni driver
|
||||||
|
BridgeNetworkDriver = "bridge"
|
||||||
|
// DefaultNetworkDriver is the default network type used
|
||||||
|
DefaultNetworkDriver = BridgeNetworkDriver
|
||||||
|
// MacVLANNetworkDriver defines the macvlan cni driver
|
||||||
|
MacVLANNetworkDriver = "macvlan"
|
||||||
|
)
|
||||||
|
|
||||||
// SupportedNetworkDrivers describes the list of supported drivers
|
// SupportedNetworkDrivers describes the list of supported drivers
|
||||||
var SupportedNetworkDrivers = []string{DefaultNetworkDriver}
|
var SupportedNetworkDrivers = []string{BridgeNetworkDriver, MacVLANNetworkDriver}
|
||||||
|
|
||||||
// isSupportedDriver checks if the user provided driver is supported
|
// isSupportedDriver checks if the user provided driver is supported
|
||||||
func isSupportedDriver(driver string) error {
|
func isSupportedDriver(driver string) error {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -794,3 +795,12 @@ func (p *PodmanTestIntegration) removeCNINetwork(name string) {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(BeNumerically("<=", 1))
|
Expect(session.ExitCode()).To(BeNumerically("<=", 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PodmanSessionIntegration) jq(jqCommand string) (string, error) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd := exec.Command("jq", jqCommand)
|
||||||
|
cmd.Stdin = strings.NewReader(p.OutputToString())
|
||||||
|
cmd.Stdout = &out
|
||||||
|
err := cmd.Run()
|
||||||
|
return strings.TrimRight(out.String(), "\n"), err
|
||||||
|
}
|
||||||
|
@ -457,6 +457,47 @@ var _ = Describe("Podman network", func() {
|
|||||||
Expect(nc.ExitCode()).To(Equal(0))
|
Expect(nc.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman network create/remove macvlan as driver (-d) no device name", func() {
|
||||||
|
net := "macvlan" + stringid.GenerateNonCryptoID()
|
||||||
|
nc := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", net})
|
||||||
|
nc.WaitWithDefaultTimeout()
|
||||||
|
defer podmanTest.removeCNINetwork(net)
|
||||||
|
Expect(nc.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"network", "inspect", net})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect.ExitCode()).To(BeZero())
|
||||||
|
|
||||||
|
out, err := inspect.jq(".[0].plugins[0].master")
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(out).To(Equal("\"\""))
|
||||||
|
|
||||||
|
nc = podmanTest.Podman([]string{"network", "rm", net})
|
||||||
|
nc.WaitWithDefaultTimeout()
|
||||||
|
Expect(nc.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman network create/remove macvlan as driver (-d) with device name", func() {
|
||||||
|
net := "macvlan" + stringid.GenerateNonCryptoID()
|
||||||
|
nc := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", "-o", "parent=lo", net})
|
||||||
|
nc.WaitWithDefaultTimeout()
|
||||||
|
defer podmanTest.removeCNINetwork(net)
|
||||||
|
Expect(nc.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"network", "inspect", net})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect.ExitCode()).To(BeZero())
|
||||||
|
fmt.Println(inspect.OutputToString())
|
||||||
|
|
||||||
|
out, err := inspect.jq(".[0].plugins[0].master")
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(out).To(Equal("\"lo\""))
|
||||||
|
|
||||||
|
nc = podmanTest.Podman([]string{"network", "rm", net})
|
||||||
|
nc.WaitWithDefaultTimeout()
|
||||||
|
Expect(nc.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman network exists", func() {
|
It("podman network exists", func() {
|
||||||
net := "net" + stringid.GenerateNonCryptoID()
|
net := "net" + stringid.GenerateNonCryptoID()
|
||||||
session := podmanTest.Podman([]string{"network", "create", net})
|
session := podmanTest.Podman([]string{"network", "create", net})
|
||||||
|
Reference in New Issue
Block a user