package main import ( "fmt" "os" "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/errorhandling" "github.com/containers/libpod/pkg/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) var ( // Kernel namespaces shared by default within a pod podCreateCommand cliconfig.PodCreateValues podCreateDescription = `After creating the pod, the pod ID is printed to stdout. You can then start it at any time with the podman pod start command. The pod will be created with the initial state 'created'.` _podCreateCommand = &cobra.Command{ Use: "create", Args: noSubArgs, Short: "Create a new empty pod", Long: podCreateDescription, RunE: func(cmd *cobra.Command, args []string) error { podCreateCommand.InputArgs = args podCreateCommand.GlobalFlags = MainGlobalOpts podCreateCommand.Remote = remoteclient return podCreateCmd(&podCreateCommand) }, } ) func init() { podCreateCommand.Command = _podCreateCommand podCreateCommand.SetHelpTemplate(HelpTemplate()) podCreateCommand.SetUsageTemplate(UsageTemplate()) flags := podCreateCommand.Flags() flags.SetInterspersed(false) // When we are ready to add the network options to the create commmand, we need to uncomment // the following //flags.AddFlagSet(getNetFlags()) // Once this is uncommented, then the publish option below needs to be removed because it // conflicts with the publish in getNetFlags. Upon removal, the c.Publish will not work // anymore and needs to be cleaned up. I suggest starting with removing the Publish attribute // from PodCreateValues structure. Running make should then expose all areas that need to be // addressed. To get the value of publish (and other flags in getNetFlags, use the syntax: // c.(" 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 { podIdFile, err = util.OpenExclusiveFile(c.PodIDFile) if err != nil && os.IsExist(err) { return errors.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", c.PodIDFile) } if err != nil { return errors.Errorf("error opening pod-id-file %s", c.PodIDFile) } defer errorhandling.CloseQuiet(podIdFile) defer errorhandling.SyncQuiet(podIdFile) } labels, err := shared.GetAllLabels(c.LabelFile, c.Labels) if err != nil { return errors.Wrapf(err, "unable to process labels") } podID, err := runtime.CreatePod(getContext(), c, labels) if err != nil { return errors.Wrapf(err, "unable to create pod") } if podIdFile != nil { _, err = podIdFile.WriteString(podID) if err != nil { logrus.Error(err) } } fmt.Printf("%s\n", podID) return nil }