From be70ee69522dfd9275a300fbd913d70d1ad2bf87 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 1 Feb 2022 15:59:34 +0100 Subject: [PATCH 1/3] Add `wwctl container show` --- internal/app/wwctl/container/show/main.go | 36 +++++++++++++++++++++ internal/app/wwctl/container/show/root.go | 38 +++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 internal/app/wwctl/container/show/main.go create mode 100644 internal/app/wwctl/container/show/root.go diff --git a/internal/app/wwctl/container/show/main.go b/internal/app/wwctl/container/show/main.go new file mode 100644 index 00000000..5352b4a6 --- /dev/null +++ b/internal/app/wwctl/container/show/main.go @@ -0,0 +1,36 @@ +package list + +import ( + "fmt" + + "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/spf13/cobra" +) + +func CobraRunE(cmd *cobra.Command, args []string) error { + containerName := args[1] + if !container.ValidName(containerName) { + return fmt.Errorf("%s is not a valid container", containerName) + } + if !ShowAll { + fmt.Printf("%s\n", container.RootFsDir(containerName)) + } else { + fmt.Printf("Name: %s\n", containerName) + fmt.Printf("Rootsfs: %s\n", container.RootFsDir(containerName)) + nodeDB, _ := node.New() + + nodes, _ := nodeDB.FindAllNodes() + var nodeList []string + for _, n := range nodes { + if n.ContainerName.Get() == containerName { + + nodeList = append(nodeList, n.Id.Get()) + } + } + fmt.Printf("Nr nodes: %d\n", len(nodeList)) + fmt.Printf("Nodes: %s\n", nodeList) + + } + return nil +} diff --git a/internal/app/wwctl/container/show/root.go b/internal/app/wwctl/container/show/root.go new file mode 100644 index 00000000..015c1aa4 --- /dev/null +++ b/internal/app/wwctl/container/show/root.go @@ -0,0 +1,38 @@ +package list + +import ( + "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/spf13/cobra" +) + +var ( + baseCmd = &cobra.Command{ + DisableFlagsInUseLine: true, + Use: "show [OPTIONS] CONTAINER", + Short: "Show root fs dir for container", + Long: `Shows the base directory for the chroot of the given container. + More information about the conainer can be hosw with -a option.`, + RunE: CobraRunE, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + list, _ := container.ListSources() + return list, cobra.ShellCompDirectiveNoFileComp + }, + + Aliases: []string{"sh", "chroot"}, + Args: cobra.MinimumNArgs(1), + } + ShowAll bool +) + +func Init() { + baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all information about a container") + +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} From 099ad6771984230077b19caa37a1863d593a72a5 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 1 Feb 2022 16:05:34 +0100 Subject: [PATCH 2/3] Add to base conainer cmd --- internal/app/wwctl/container/root.go | 7 +++++-- internal/app/wwctl/container/show/main.go | 2 +- internal/app/wwctl/container/show/root.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/app/wwctl/container/root.go b/internal/app/wwctl/container/root.go index 02efc3b0..08c13ba5 100644 --- a/internal/app/wwctl/container/root.go +++ b/internal/app/wwctl/container/root.go @@ -6,14 +6,15 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/container/exec" "github.com/hpcng/warewulf/internal/app/wwctl/container/imprt" "github.com/hpcng/warewulf/internal/app/wwctl/container/list" + "github.com/hpcng/warewulf/internal/app/wwctl/container/show" "github.com/spf13/cobra" ) var ( baseCmd = &cobra.Command{ DisableFlagsInUseLine: true, - Use: "container COMMAND [OPTIONS]", - Short: "Container / VNFS image management", + Use: "container COMMAND [OPTIONS]", + Short: "Container / VNFS image management", Long: "Starting with version 4, Warewulf uses containers to build the bootable VNFS\n" + "node images. These commands will help you import, manage, and transform\n" + "containers into bootable Warewulf VNFS images.", @@ -27,6 +28,8 @@ func init() { baseCmd.AddCommand(imprt.GetCommand()) baseCmd.AddCommand(exec.GetCommand()) baseCmd.AddCommand(delete.GetCommand()) + baseCmd.AddCommand(show.GetCommand()) + } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/container/show/main.go b/internal/app/wwctl/container/show/main.go index 5352b4a6..acce6e02 100644 --- a/internal/app/wwctl/container/show/main.go +++ b/internal/app/wwctl/container/show/main.go @@ -1,4 +1,4 @@ -package list +package show import ( "fmt" diff --git a/internal/app/wwctl/container/show/root.go b/internal/app/wwctl/container/show/root.go index 015c1aa4..c4e44489 100644 --- a/internal/app/wwctl/container/show/root.go +++ b/internal/app/wwctl/container/show/root.go @@ -1,4 +1,4 @@ -package list +package show import ( "github.com/hpcng/warewulf/internal/pkg/container" From e57ea10df56ed4ab340cd520173b82cc5391881d Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 1 Feb 2022 16:10:48 +0100 Subject: [PATCH 3/3] fix index --- internal/app/wwctl/container/show/main.go | 4 ++-- internal/app/wwctl/container/show/root.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/app/wwctl/container/show/main.go b/internal/app/wwctl/container/show/main.go index acce6e02..a902eee2 100644 --- a/internal/app/wwctl/container/show/main.go +++ b/internal/app/wwctl/container/show/main.go @@ -9,7 +9,7 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - containerName := args[1] + containerName := args[0] if !container.ValidName(containerName) { return fmt.Errorf("%s is not a valid container", containerName) } @@ -17,7 +17,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("%s\n", container.RootFsDir(containerName)) } else { fmt.Printf("Name: %s\n", containerName) - fmt.Printf("Rootsfs: %s\n", container.RootFsDir(containerName)) + fmt.Printf("Rootfs: %s\n", container.RootFsDir(containerName)) nodeDB, _ := node.New() nodes, _ := nodeDB.FindAllNodes() diff --git a/internal/app/wwctl/container/show/root.go b/internal/app/wwctl/container/show/root.go index c4e44489..92db694b 100644 --- a/internal/app/wwctl/container/show/root.go +++ b/internal/app/wwctl/container/show/root.go @@ -11,7 +11,7 @@ var ( Use: "show [OPTIONS] CONTAINER", Short: "Show root fs dir for container", Long: `Shows the base directory for the chroot of the given container. - More information about the conainer can be hosw with -a option.`, +More information about the conainer can be shown with the '-a' option.`, RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { @@ -27,7 +27,7 @@ var ( ShowAll bool ) -func Init() { +func init() { baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all information about a container") }