aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/pod_create.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-23 19:36:19 -0600
committerbaude <bbaude@redhat.com>2019-02-25 09:10:09 -0600
commit43a1686598c92c9e2a839909b8b5edb9f1b0f00f (patch)
treee1fb43b63b951dd4f298e93edc868a3dcf2eb371 /cmd/podman/pod_create.go
parent4bf973a9f61eae3b02925a42ccfa784baeb917dc (diff)
downloadpodman-43a1686598c92c9e2a839909b8b5edb9f1b0f00f.tar.gz
podman-43a1686598c92c9e2a839909b8b5edb9f1b0f00f.tar.bz2
podman-43a1686598c92c9e2a839909b8b5edb9f1b0f00f.zip
podman-remote create|ps
enable the podman-remote client to be able to create and list pods on a remote system. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/pod_create.go')
-rw-r--r--cmd/podman/pod_create.go77
1 files changed, 19 insertions, 58 deletions
diff --git a/cmd/podman/pod_create.go b/cmd/podman/pod_create.go
index d5ca5e13a..f1bbecb84 100644
--- a/cmd/podman/pod_create.go
+++ b/cmd/podman/pod_create.go
@@ -3,12 +3,10 @@ package main
import (
"fmt"
"os"
- "strings"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -56,20 +54,29 @@ func init() {
}
func podCreateCmd(c *cliconfig.PodCreateValues) error {
- var options []libpod.PodCreateOption
- var err error
+ var (
+ err error
+ podIdFile *os.File
+ )
if len(c.InputArgs) > 0 {
return errors.New("podman pod create does not accept any arguments")
}
-
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- var podIdFile *os.File
+ if len(c.Publish) > 0 {
+ if !c.Infra {
+ return errors.Errorf("you must have an infra container to publish port bindings to the host")
+ }
+ }
+
+ if !c.Infra && c.Flag("share").Changed && c.Share != "none" && c.Share != "" {
+ return errors.Errorf("You cannot share kernel namespaces on the pod level without an infra container")
+ }
if c.Flag("pod-id-file").Changed && os.Geteuid() == 0 {
podIdFile, err = libpod.OpenExclusiveFile(c.PodIDFile)
if err != nil && os.IsExist(err) {
@@ -82,67 +89,21 @@ func podCreateCmd(c *cliconfig.PodCreateValues) error {
defer podIdFile.Sync()
}
- if len(c.Publish) > 0 {
- if !c.Infra {
- return errors.Errorf("you must have an infra container to publish port bindings to the host")
- }
- }
-
- if !c.Infra && c.Flag("share").Changed && c.Share != "none" && c.Share != "" {
- return errors.Errorf("You cannot share kernel namespaces on the pod level without an infra container")
- }
-
- if c.Flag("cgroup-parent").Changed {
- options = append(options, libpod.WithPodCgroupParent(c.CgroupParent))
- }
-
labels, err := getAllLabels(c.LabelFile, c.Labels)
if err != nil {
return errors.Wrapf(err, "unable to process labels")
}
- if len(labels) != 0 {
- options = append(options, libpod.WithPodLabels(labels))
- }
-
- if c.Flag("name").Changed {
- options = append(options, libpod.WithPodName(c.Name))
- }
-
- if c.Infra {
- options = append(options, libpod.WithInfraContainer())
- nsOptions, err := shared.GetNamespaceOptions(strings.Split(c.Share, ","))
- if err != nil {
- return err
- }
- options = append(options, nsOptions...)
- }
- if len(c.Publish) > 0 {
- portBindings, err := shared.CreatePortBindings(c.Publish)
- if err != nil {
- return err
- }
- options = append(options, libpod.WithInfraContainerPorts(portBindings))
-
- }
- // always have containers use pod cgroups
- // User Opt out is not yet supported
- options = append(options, libpod.WithPodCgroups())
-
- ctx := getContext()
- pod, err := runtime.NewPod(ctx, options...)
+ podID, err := runtime.CreatePod(getContext(), c, labels)
if err != nil {
- return err
+ return errors.Wrapf(err, "unable to create pod")
}
-
if podIdFile != nil {
- _, err = podIdFile.WriteString(pod.ID())
+ _, err = podIdFile.WriteString(podID)
if err != nil {
logrus.Error(err)
}
}
-
- fmt.Printf("%s\n", pod.ID())
-
+ fmt.Printf("%s\n", podID)
return nil
}