Add wwctl container show
This commit is contained in:
36
internal/app/wwctl/container/show/main.go
Normal file
36
internal/app/wwctl/container/show/main.go
Normal 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
|
||||
}
|
||||
38
internal/app/wwctl/container/show/root.go
Normal file
38
internal/app/wwctl/container/show/root.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user