Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation of network create. we only support bridging networks with this first pass. Signed-off-by: baude <bbaude@redhat.com>
- Loading branch information
Showing
47 changed files
with
4,677 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
% podman-network-create(1) | ||
|
||
## NAME | ||
podman\-network-create - Create a Podman CNI network | ||
|
||
## SYNOPSIS | ||
**podman network create** [*options*] name | ||
|
||
## DESCRIPTION | ||
Create a CNI-network configuration for use with Podman. At the time of this writing, the only network | ||
type that can be created is a *bridge* network. | ||
|
||
If no options are provided, Podman will assign a free subnet and name for your network. | ||
|
||
Upon completion of creating the network, Podman will display the path to the newly added network file. | ||
|
||
## OPTIONS | ||
**-d**, , **--driver** | ||
|
||
Driver to manage the network (default "bridge"). Currently on `bridge` is supported. | ||
|
||
**--gateway** | ||
|
||
Define a gateway for the subnet. If you want to provide a gateway address, you must also provide a | ||
*subnet* option. | ||
|
||
**--internal** | ||
|
||
Restrict external access of this network | ||
|
||
**--ip-range** | ||
|
||
Allocate container IP from a range. The range must be a complete subnet and in CIDR notation. The *ip-range* option | ||
must be used with a *subnet* option. | ||
|
||
**--subnet** | ||
|
||
The subnet in CIDR notation. | ||
|
||
## EXAMPLE | ||
|
||
Create a network with no options | ||
``` | ||
# podman network create | ||
/etc/cni/net.d/cni-podman-4.conflist | ||
``` | ||
|
||
Create a network named *newnet* that uses *192.5.0.0/16* for its subnet. | ||
``` | ||
# podman network create --subnet 192.5.0.0/16 newnet | ||
/etc/cni/net.d/newnet.conflist | ||
``` | ||
|
||
Create a network named *newnet* that uses *192.168.33.0/24* and defines a gateway as *192.168.133.3* | ||
``` | ||
# podman network create --subnet 192.168.33.0/24 --gateway 192.168.33.3 newnet | ||
/etc/cni/net.d/newnet.conflist | ||
``` | ||
|
||
Create a network that uses a *192.168.55.0/24** subnet and has an IP address range of *192.168.55.129 - 192.168.55.254*. | ||
``` | ||
# podman network create --subnet 192.168.55.0/24 --ip-range 192.168.55.128/25 | ||
/etc/cni/net.d/cni-podman-5.conflist | ||
``` | ||
|
||
## SEE ALSO | ||
podman(1), podman-network(1), podman-network-inspect(1) | ||
|
||
## HISTORY | ||
August 2019, Originally compiled by Brent Baude <bbaude@redhat.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.