aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-08-08 06:01:00 -0500
committerbaude <bbaude@redhat.com>2019-09-09 09:32:43 -0500
commitee432cf2792c5dbe81953007f1fd5c87beb3ebd5 (patch)
treedc0646e4b2faeadf9cca58bf80f1e90d98c50165 /cmd
parent30cbb0091515a7f802f0f3f3ee486be6ff98f645 (diff)
downloadpodman-ee432cf2792c5dbe81953007f1fd5c87beb3ebd5.tar.gz
podman-ee432cf2792c5dbe81953007f1fd5c87beb3ebd5.tar.bz2
podman-ee432cf2792c5dbe81953007f1fd5c87beb3ebd5.zip
podman network create
initial implementation of network create. we only support bridging networks with this first pass. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/cliconfig/config.go13
-rw-r--r--cmd/podman/network.go2
-rw-r--r--cmd/podman/network_create.go70
3 files changed, 84 insertions, 1 deletions
diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go
index 98e7aed4b..812cc1f51 100644
--- a/cmd/podman/cliconfig/config.go
+++ b/cmd/podman/cliconfig/config.go
@@ -1,6 +1,8 @@
package cliconfig
import (
+ "net"
+
"github.com/spf13/cobra"
)
@@ -259,6 +261,17 @@ type MountValues struct {
Latest bool
}
+type NetworkCreateValues struct {
+ PodmanCommand
+ Driver string
+ Gateway net.IP
+ Internal bool
+ IPamDriver string
+ IPRange net.IPNet
+ IPV6 bool
+ Network net.IPNet
+}
+
type NetworkListValues struct {
PodmanCommand
Filter []string
diff --git a/cmd/podman/network.go b/cmd/podman/network.go
index 83a5e71ab..702593e5c 100644
--- a/cmd/podman/network.go
+++ b/cmd/podman/network.go
@@ -17,8 +17,8 @@ var networkcheckCommand = cliconfig.PodmanCommand{
},
}
-// Commands that are universally implemented
var networkcheckCommands = []*cobra.Command{
+ _networkCreateCommand,
_networkinspectCommand,
_networklistCommand,
_networkrmCommand,
diff --git a/cmd/podman/network_create.go b/cmd/podman/network_create.go
new file mode 100644
index 000000000..378a92568
--- /dev/null
+++ b/cmd/podman/network_create.go
@@ -0,0 +1,70 @@
+// +build !remoteclient
+
+package main
+
+import (
+ "fmt"
+ "github.com/containers/libpod/pkg/network"
+ "net"
+
+ "github.com/containers/libpod/cmd/podman/cliconfig"
+ "github.com/containers/libpod/pkg/adapter"
+ "github.com/containers/libpod/pkg/rootless"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ networkCreateCommand cliconfig.NetworkCreateValues
+ networkCreateDescription = `create CNI networks for containers and pods`
+ _networkCreateCommand = &cobra.Command{
+ Use: "create [flags] [NETWORK]",
+ Short: "network create",
+ Long: networkCreateDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ networkCreateCommand.InputArgs = args
+ networkCreateCommand.GlobalFlags = MainGlobalOpts
+ networkCreateCommand.Remote = remoteclient
+ return networkcreateCmd(&networkCreateCommand)
+ },
+ Example: `podman network create podman1`,
+ }
+)
+
+func init() {
+ networkCreateCommand.Command = _networkCreateCommand
+ networkCreateCommand.SetHelpTemplate(HelpTemplate())
+ networkCreateCommand.SetUsageTemplate(UsageTemplate())
+ flags := networkCreateCommand.Flags()
+ flags.StringVarP(&networkCreateCommand.Driver, "driver", "d", "bridge", "driver to manage the network")
+ flags.IPVar(&networkCreateCommand.Gateway, "gateway", nil, "IPv4 or IPv6 gateway for the subnet")
+ flags.BoolVar(&networkCreateCommand.Internal, "internal", false, "restrict external access from this network")
+ flags.IPNetVar(&networkCreateCommand.IPRange, "ip-range", net.IPNet{}, "allocate container IP from range")
+ // TODO not supported yet
+ //flags.StringVar(&networkCreateCommand.IPamDriver, "ipam-driver", "", "IP Address Management Driver")
+ // TODO enable when IPv6 is working
+ //flags.BoolVar(&networkCreateCommand.IPV6, "IPv6", false, "enable IPv6 networking")
+ flags.IPNetVar(&networkCreateCommand.Network, "subnet", net.IPNet{}, "subnet in CIDR format")
+
+}
+
+func networkcreateCmd(c *cliconfig.NetworkCreateValues) error {
+ if err := network.IsSupportedDriver(c.Driver); err != nil {
+ return err
+ }
+ if rootless.IsRootless() && !remoteclient {
+ return errors.New("network create is not supported for rootless mode")
+ }
+ if len(c.InputArgs) > 1 {
+ return errors.Errorf("only one network can be created at a time")
+ }
+ runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand)
+ if err != nil {
+ return err
+ }
+ fileName, err := runtime.NetworkCreate(c)
+ if err == nil {
+ fmt.Println(fileName)
+ }
+ return err
+}