default profile needs to have a container
Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
a36cb23319
commit
2fe98e5f55
@@ -2,10 +2,15 @@ package delete
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/util"
|
||||
apiutil "github.com/hpcng/warewulf/internal/pkg/api/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -13,8 +18,23 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
cdp := &wwapiv1.ContainerDeleteParameter{
|
||||
ContainerNames: args,
|
||||
}
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Error("Failed to open node database: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
profiles, err := nodeDB.MapAllProfiles()
|
||||
if err != nil {
|
||||
wwlog.Error("Could not load all profiles: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if util.InSlice(args, profiles["default"].ContainerName.Get()) {
|
||||
return fmt.Errorf("can't delete container which is in the default profile")
|
||||
}
|
||||
if !SetYes {
|
||||
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to delete container %s", args))
|
||||
yes := apiutil.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to delete container %s", args))
|
||||
if !yes {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package imprt
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
|
||||
apicontainer "github.com/hpcng/warewulf/internal/pkg/api/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -13,6 +15,9 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(args) == 2 {
|
||||
name = args[1]
|
||||
}
|
||||
if list, _ := container.ListSources(); len(list) == 0 {
|
||||
SetDefault = true
|
||||
}
|
||||
|
||||
cip := &wwapiv1.ContainerImportParameter{
|
||||
Source: args[0],
|
||||
@@ -23,6 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
Default: SetDefault,
|
||||
SyncUser: SyncUser,
|
||||
}
|
||||
_, err = container.ContainerImport(cip)
|
||||
|
||||
_, err = apicontainer.ContainerImport(cip)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,6 +14,9 @@ import (
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
var count int
|
||||
if util.InSlice(args, "default") {
|
||||
return fmt.Errorf("can't delete the `default` profile ")
|
||||
}
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
|
||||
@@ -10,5 +10,4 @@ type WarewulfConf struct {
|
||||
EnableHostOverlay bool `yaml:"host overlay" default:"true"`
|
||||
Syslog bool `yaml:"syslog" default:"false"`
|
||||
DataStore string `yaml:"datastore" default:"/var/lib/warewulf"`
|
||||
DefaultBoot string `yaml:"boot method" default:"ipxe"`
|
||||
}
|
||||
|
||||
@@ -307,6 +307,36 @@ func (config *NodeYaml) ListAllProfiles() []string {
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
return a map where the key is the profile id
|
||||
*/
|
||||
func (config *NodeYaml) MapAllProfiles() (retMap map[string]*NodeInfo, err error) {
|
||||
retMap = make(map[string]*NodeInfo)
|
||||
profileList, err := config.FindAllProfiles()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, pr := range profileList {
|
||||
retMap[pr.Id.Get()] = &pr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
return a map where the key is the node id
|
||||
*/
|
||||
func (config *NodeYaml) MapAllNodes() (retMap map[string]*NodeInfo, err error) {
|
||||
retMap = make(map[string]*NodeInfo)
|
||||
nodeList, err := config.FindAllNodes()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, nd := range nodeList {
|
||||
retMap[nd.Id.Get()] = &nd
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
FindDiscoverableNode returns the first discoverable node and an
|
||||
interface to associate with the discovered interface. If the node has
|
||||
|
||||
52
internal/pkg/warewulfd/copyshim.go
Normal file
52
internal/pkg/warewulfd/copyshim.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package warewulfd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
warewulfconf "github.com/hpcng/warewulf/internal/pkg/config"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
/*
|
||||
Copies the default shim, which is the shim located in the default container
|
||||
to the tftp directory
|
||||
*/
|
||||
|
||||
func CopyShimGrub() (err error) {
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf := warewulfconf.Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profiles, err := nodeDB.MapAllProfiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := profiles["default"]; ok {
|
||||
return fmt.Errorf("default profile doesn't exist")
|
||||
}
|
||||
if profiles["default"].BootMethod.Get() == "ipxe" {
|
||||
return
|
||||
}
|
||||
shimPath := container.ShimFind("default")
|
||||
if shimPath == "" {
|
||||
return fmt.Errorf("no shim found in the default profile")
|
||||
}
|
||||
err = util.CopyFile(shimPath, path.Join(conf.TFTP.TftpRoot, "shim.efi"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
grubPath := container.GrubFind("default")
|
||||
if shimPath == "" {
|
||||
return fmt.Errorf("no grub found in the default profile")
|
||||
}
|
||||
err = util.CopyFile(grubPath, path.Join(conf.TFTP.TftpRoot, "grub.efi"))
|
||||
return
|
||||
}
|
||||
@@ -49,6 +49,11 @@ func RunServer() error {
|
||||
wwlog.Error("Could not prepopulate node status DB: %s", err)
|
||||
}
|
||||
|
||||
err = CopyShimGrub()
|
||||
if err != nil {
|
||||
wwlog.Warn("couldn't copy default shim: %s", err)
|
||||
}
|
||||
|
||||
http.HandleFunc("/provision/", ProvisionSend)
|
||||
http.HandleFunc("/ipxe/", ProvisionSend)
|
||||
http.HandleFunc("/kernel/", ProvisionSend)
|
||||
|
||||
Reference in New Issue
Block a user