summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/build.go9
-rw-r--r--cmd/podman/cliconfig/config.go13
-rw-r--r--cmd/podman/common.go11
-rw-r--r--cmd/podman/network.go2
-rw-r--r--cmd/podman/network_create.go70
-rw-r--r--cmd/podman/shared/volumes_shared.go47
-rw-r--r--cmd/podman/varlink/io.podman.varlink2
-rw-r--r--cmd/podman/volume_rm.go18
8 files changed, 150 insertions, 22 deletions
diff --git a/cmd/podman/build.go b/cmd/podman/build.go
index 14ac51889..8eb12cacd 100644
--- a/cmd/podman/build.go
+++ b/cmd/podman/build.go
@@ -10,6 +10,7 @@ import (
"github.com/containers/buildah/imagebuildah"
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/libpod/cmd/podman/cliconfig"
+ "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
"github.com/docker/go-units"
"github.com/opencontainers/runtime-spec/specs-go"
@@ -225,6 +226,14 @@ func buildCmd(c *cliconfig.BuildValues) error {
for _, arg := range c.RuntimeFlags {
runtimeFlags = append(runtimeFlags, "--"+arg)
}
+
+ conf, err := runtime.GetConfig()
+ if err != nil {
+ return err
+ }
+ if conf != nil && conf.CgroupManager == libpod.SystemdCgroupsManager {
+ runtimeFlags = append(runtimeFlags, "--systemd-cgroup")
+ }
// end from buildah
defer runtime.DeferredShutdown(false)
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/common.go b/cmd/podman/common.go
index 32478bb51..9724d18c6 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -22,7 +22,8 @@ var (
)
const (
- idTruncLength = 12
+ idTruncLength = 12
+ sizeWithUnitFormat = "(format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))"
)
func splitCamelCase(src string) string {
@@ -302,7 +303,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
)
createFlags.String(
"kernel-memory", "",
- "Kernel memory limit (format: `<number>[<unit>]`, where unit = b, k, m or g)",
+ "Kernel memory limit "+sizeWithUnitFormat,
)
createFlags.StringArrayP(
"label", "l", []string{},
@@ -326,11 +327,11 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
)
createFlags.StringP(
"memory", "m", "",
- "Memory limit (format: <number>[<unit>], where unit = b, k, m or g)",
+ "Memory limit "+sizeWithUnitFormat,
)
createFlags.String(
"memory-reservation", "",
- "Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g)",
+ "Memory soft limit "+sizeWithUnitFormat,
)
createFlags.String(
"memory-swap", "",
@@ -422,7 +423,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
)
createFlags.String(
"shm-size", cliconfig.DefaultShmSize,
- "Size of `/dev/shm`. The format is `<number><unit>`",
+ "Size of /dev/shm "+sizeWithUnitFormat,
)
createFlags.String(
"stop-signal", "",
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
+}
diff --git a/cmd/podman/shared/volumes_shared.go b/cmd/podman/shared/volumes_shared.go
new file mode 100644
index 000000000..912615cad
--- /dev/null
+++ b/cmd/podman/shared/volumes_shared.go
@@ -0,0 +1,47 @@
+package shared
+
+import (
+ "context"
+
+ "github.com/containers/libpod/libpod"
+)
+
+// Remove given set of volumes
+func SharedRemoveVolumes(ctx context.Context, runtime *libpod.Runtime, vols []string, all, force bool) ([]string, map[string]error, error) {
+ var (
+ toRemove []*libpod.Volume
+ success []string
+ failed map[string]error
+ )
+
+ failed = make(map[string]error)
+
+ if all {
+ vols, err := runtime.Volumes()
+ if err != nil {
+ return nil, nil, err
+ }
+ toRemove = vols
+ } else {
+ for _, v := range vols {
+ vol, err := runtime.LookupVolume(v)
+ if err != nil {
+ failed[v] = err
+ continue
+ }
+ toRemove = append(toRemove, vol)
+ }
+ }
+
+ // We could parallelize this, but I haven't heard anyone complain about
+ // performance here yet, so hold off.
+ for _, vol := range toRemove {
+ if err := runtime.RemoveVolume(ctx, vol, force); err != nil {
+ failed[vol.Name()] = err
+ continue
+ }
+ success = append(success, vol.Name())
+ }
+
+ return success, failed, nil
+}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 0530b127b..4692525e3 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -1212,7 +1212,7 @@ method ReceiveFile(path: string, delete: bool) -> (len: int)
method VolumeCreate(options: VolumeCreateOpts) -> (volumeName: string)
# VolumeRemove removes a volume on a remote host
-method VolumeRemove(options: VolumeRemoveOpts) -> (volumeNames: []string)
+method VolumeRemove(options: VolumeRemoveOpts) -> (successes: []string, failures: [string]string)
# GetVolumes gets slice of the volumes on a remote host
method GetVolumes(args: []string, all: bool) -> (volumes: []Volume)
diff --git a/cmd/podman/volume_rm.go b/cmd/podman/volume_rm.go
index 0141d06da..2fa6a8d03 100644
--- a/cmd/podman/volume_rm.go
+++ b/cmd/podman/volume_rm.go
@@ -1,8 +1,6 @@
package main
import (
- "fmt"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
@@ -52,19 +50,9 @@ func volumeRmCmd(c *cliconfig.VolumeRmValues) error {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.DeferredShutdown(false)
- deletedVolumeNames, err := runtime.RemoveVolumes(getContext(), c)
+ deletedVolumeNames, deletedVolumeErrors, err := runtime.RemoveVolumes(getContext(), c)
if err != nil {
- if len(deletedVolumeNames) > 0 {
- printDeleteVolumes(deletedVolumeNames)
- return err
- }
- }
- printDeleteVolumes(deletedVolumeNames)
- return err
-}
-
-func printDeleteVolumes(volumes []string) {
- for _, v := range volumes {
- fmt.Println(v)
+ return err
}
+ return printCmdResults(deletedVolumeNames, deletedVolumeErrors)
}