summaryrefslogtreecommitdiff
path: root/cmd/podmanV2
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-04-13 16:04:05 -0500
committerBrent Baude <bbaude@redhat.com>2020-04-13 19:51:20 -0500
commitd8d1aa49d27d51f914a0858ab99c57d7dc929926 (patch)
tree715f035f049b161b55932fa9586f24c1876f11a5 /cmd/podmanV2
parent5cf64aee11063bc8e7ff22f1365b0bf6b3ab0900 (diff)
downloadpodman-d8d1aa49d27d51f914a0858ab99c57d7dc929926.tar.gz
podman-d8d1aa49d27d51f914a0858ab99c57d7dc929926.tar.bz2
podman-d8d1aa49d27d51f914a0858ab99c57d7dc929926.zip
v2podman add container init
add the ability to init a container both local and remote Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podmanV2')
-rw-r--r--cmd/podmanV2/containers/init.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/cmd/podmanV2/containers/init.go b/cmd/podmanV2/containers/init.go
new file mode 100644
index 000000000..dd1e1d21b
--- /dev/null
+++ b/cmd/podmanV2/containers/init.go
@@ -0,0 +1,60 @@
+package containers
+
+import (
+ "fmt"
+
+ "github.com/containers/libpod/cmd/podmanV2/parse"
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/cmd/podmanV2/utils"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ initDescription = `Initialize one or more containers, creating the OCI spec and mounts for inspection. Container names or IDs can be used.`
+
+ initCommand = &cobra.Command{
+ Use: "init [flags] CONTAINER [CONTAINER...]",
+ Short: "Initialize one or more containers",
+ Long: initDescription,
+ PreRunE: preRunE,
+ RunE: initContainer,
+ Args: func(cmd *cobra.Command, args []string) error {
+ return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ },
+ Example: `podman init --latest
+ podman init 3c45ef19d893
+ podman init test1`,
+ }
+)
+
+var (
+ initOptions entities.ContainerInitOptions
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: initCommand,
+ })
+ flags := initCommand.Flags()
+ flags.BoolVarP(&initOptions.All, "all", "a", false, "Initialize all containers")
+ flags.BoolVarP(&initOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+ _ = flags.MarkHidden("latest")
+}
+
+func initContainer(cmd *cobra.Command, args []string) error {
+ var errs utils.OutputErrors
+ report, err := registry.ContainerEngine().ContainerInit(registry.GetContext(), args, initOptions)
+ if err != nil {
+ return err
+ }
+ for _, r := range report {
+ if r.Err == nil {
+ fmt.Println(r.Id)
+ } else {
+ errs = append(errs, r.Err)
+ }
+ }
+ return errs.PrintErrors()
+}