Add wwctl container show

This commit is contained in:
Christian Goll
2022-02-01 15:59:34 +01:00
parent 255d8c9252
commit be70ee6952
2 changed files with 74 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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
}