Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Sep 12, 2024
1 parent b30a650 commit 451025d
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build:

clean:
go clean
rm ${BINARY_NAME}
rm -f ${BINARY_NAME}
rm -rf config/completions/*

cleandoc: ## Cleans the docs directory.
Expand Down
41 changes: 28 additions & 13 deletions cmd/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ package cmd

import (
"fmt"
cobbler "github.com/cobbler/cobblerclient"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

cobbler "github.com/cobbler/cobblerclient"
)

func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
inPlace, err := cmd.Flags().GetBool("in-place")
printErrAndExitIfNotNil(err)
var inPlace bool
var err error
if cmd.Flags().Lookup("in-place") != nil {
inPlace, err = cmd.Flags().GetBool("in-place")
printErrAndExitIfNotNil(err)
}
cmd.Flags().Visit(func(flag *pflag.Flag) {
switch flag.Name {
// The rename & copy operations are special operations as such we cannot blindly set this inside here.
Expand All @@ -32,7 +35,7 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
err = Client.ModifyItemInPlace(
"distro",
distro.Name,
"autoinstall-meta",
"autoinstall_meta",
convertMapStringToMapInterface(distroNewAutoinstallMeta),
)
printErrAndExitIfNotNil(err)
Expand Down Expand Up @@ -88,7 +91,7 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
err = Client.ModifyItemInPlace(
"distro",
distro.Name,
"fetchable-files",
"fetchable_files",
convertMapStringToMapInterface(newFetchableFiles),
)
printErrAndExitIfNotNil(err)
Expand Down Expand Up @@ -127,7 +130,7 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
err = Client.ModifyItemInPlace(
"distro",
distro.Name,
"kernel-options",
"kernel_options",
convertMapStringToMapInterface(newKernelOptions),
)
printErrAndExitIfNotNil(err)
Expand All @@ -150,7 +153,7 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
err = Client.ModifyItemInPlace(
"distro",
distro.Name,
"kernel-options-post",
"kernel_options_post",
convertMapStringToMapInterface(newKernelOptionsPost),
)
printErrAndExitIfNotNil(err)
Expand Down Expand Up @@ -207,7 +210,7 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
err = Client.ModifyItemInPlace(
"distro",
distro.Name,
"template-files",
"template_files",
convertMapStringToMapInterface(newTemplateFiles),
)
printErrAndExitIfNotNil(err)
Expand All @@ -218,6 +221,10 @@ func updateDistroFromFlags(cmd *cobra.Command, distro *cobbler.Distro) {
}
}
})
if inPlace {
// Update distro in case we did modify the distro
distro.Meta.IsDirty = true
}
}

// distroCmd represents the distro command
Expand All @@ -237,7 +244,7 @@ var distroAddCmd = &cobra.Command{
Long: `Adds a distribution.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newDistro cobbler.Distro
newDistro := cobbler.NewDistro()
var err error

// internal fields (ctime, mtime, depth, uid, source-repos, tree-build-time) cannot be modified
Expand All @@ -248,7 +255,7 @@ var distroAddCmd = &cobra.Command{
// Now create the distro via XML-RPC
distro, err := Client.CreateDistro(newDistro)
printErrAndExitIfNotNil(err)
fmt.Printf("Distro %s created", distro.Name)
fmt.Printf("Distro %s created\n", distro.Name)
},
}

Expand Down Expand Up @@ -292,6 +299,14 @@ var distroEditCmd = &cobra.Command{
printErrAndExitIfNotNil(err)
// Update distro in-memory
updateDistroFromFlags(cmd, updateDistro)
if updateDistro.Meta.IsDirty {
updateDistro, err = Client.GetDistro(
updateDistro.Name,
updateDistro.Meta.IsFlattened,
updateDistro.Meta.IsResolved,
)
printErrAndExitIfNotNil(err)
}
// Now update distro via XML-RPC
err = Client.UpdateDistro(updateDistro)
printErrAndExitIfNotNil(err)
Expand Down Expand Up @@ -370,9 +385,9 @@ var distroRenameCmd = &cobra.Command{

func reportDistros(distroNames []string) {
for _, itemName := range distroNames {
system, err := Client.GetDistro(itemName, false, false)
distro, err := Client.GetDistro(itemName, false, false)
printErrAndExitIfNotNil(err)
printStructured(system)
printStructured(distro)
fmt.Println("")
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var fileAddCmd = &cobra.Command{
Long: `Adds a file.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newFile cobbler.File
newFile := cobbler.NewFile()
var err error

// Get special name flag
Expand All @@ -101,7 +101,7 @@ var fileAddCmd = &cobra.Command{
// Now create the file via XML-RPC
file, err := Client.CreateFile(newFile)
printErrAndExitIfNotNil(err)
fmt.Printf("File %s created", file.Name)
fmt.Printf("File %s created\n", file.Name)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var imageAddCmd = &cobra.Command{
Long: `Adds a image.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newImage cobbler.Image
newImage := cobbler.NewImage()
var err error
newImage.Name, err = cmd.Flags().GetString("name")
printErrAndExitIfNotNil(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var menuAddCmd = &cobra.Command{
Long: `Adds a menu.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newMenu cobbler.Menu
newMenu := cobbler.NewMenu()
var err error
newMenu.Name, err = cmd.Flags().GetString("name")
printErrAndExitIfNotNil(err)
Expand All @@ -42,7 +42,7 @@ var menuAddCmd = &cobra.Command{

menu, err := Client.CreateMenu(newMenu)
printErrAndExitIfNotNil(err)
fmt.Printf("Menu %s created", menu.Name)
fmt.Printf("Menu %s created\n", menu.Name)
},
}

Expand Down
37 changes: 21 additions & 16 deletions cmd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var distroStringFlagMetadata = map[string]FlagMetadata[string]{
},
"arch": {
Name: "arch",
DefaultValue: "",
DefaultValue: "x86_64",
Usage: "Architecture",
},
"breed": {
Expand Down Expand Up @@ -249,14 +249,16 @@ var profileStringSliceFlagMetadata = map[string]FlagMetadata[[]string]{
Usage: "repos to auto-assign to this profile",
},
"name-servers": {
Name: "name-servers",
DefaultValue: []string{},
Usage: "name servers (comma delimited)",
Name: "name-servers",
DefaultValue: []string{},
Usage: "name servers (comma delimited)",
IsInheritable: true,
},
"name-servers-search": {
Name: "name-servers-search",
DefaultValue: []string{},
Usage: "name servers search path (comma delimited)",
Name: "name-servers-search",
DefaultValue: []string{},
Usage: "name servers search path (comma delimited)",
IsInheritable: true,
},
}

Expand Down Expand Up @@ -368,19 +370,22 @@ var systemStringFlagMetadata = map[string]FlagMetadata[string]{

var systemBoolFlagMetadata = map[string]FlagMetadata[bool]{
"enable-ipxe": {
Name: "enable-ipxe",
DefaultValue: false,
Usage: "enable iPXE? (use iPXE instead of PXELINUX for advanced booting options)",
Name: "enable-ipxe",
DefaultValue: false,
Usage: "enable iPXE? (use iPXE instead of PXELINUX for advanced booting options)",
IsInheritable: true,
},
"enable-menu": {
Name: "enable-menu",
DefaultValue: false,
Usage: "enable PXE Menu? (show this profile in the PXE menu?)",
Name: "enable-menu",
DefaultValue: false,
Usage: "enable PXE Menu? (show this profile in the PXE menu?)",
IsInheritable: true,
},
"virt-auto-boot": {
Name: "virt-auto-boot",
DefaultValue: false,
Usage: "auto boot this VM?",
Name: "virt-auto-boot",
DefaultValue: false,
Usage: "auto boot this VM?",
IsInheritable: true,
},
"netboot-enabled": {
Name: "netboot-enabled",
Expand Down
2 changes: 1 addition & 1 deletion cmd/mgmtclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var mgmtclassAddCmd = &cobra.Command{
Long: `Adds a mgmtclass.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newMgmtClass cobbler.MgmtClass
newMgmtClass := cobbler.NewMgmtClass()
var err error

// Get special name flag
Expand Down
4 changes: 2 additions & 2 deletions cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var packageAddCmd = &cobra.Command{
Long: `Adds a package.`,
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()
var newPackage cobbler.Package
newPackage := cobbler.NewPackage()
var err error

// internal fields (ctime, mtime, depth, uid) cannot be modified
Expand All @@ -79,7 +79,7 @@ var packageAddCmd = &cobra.Command{
// Create package via XML-RPC
linuxpackage, err := Client.CreatePackage(newPackage)
printErrAndExitIfNotNil(err)
fmt.Printf("Package %s created", linuxpackage.Name)
fmt.Printf("Package %s created\n", linuxpackage.Name)
},
}

Expand Down
73 changes: 55 additions & 18 deletions cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,29 @@ func updateProfileFromFlags(cmd *cobra.Command, profile *cobbler.Profile) {
profile.MgmtParameters.Data = convertMapStringToMapInterface(profileNewMgmtParameters)
}
case "name-servers":
profileNewNameServers, err := cmd.Flags().GetStringSlice("name-servers")
printErrAndExitIfNotNil(err)
profile.NameServers = profileNewNameServers
fallthrough
case "name-servers-inherit":
if cmd.Flags().Lookup("name-servers-inherit").Changed {
profile.NameServers.Data = make([]string, 0)
profile.NameServers.IsInherited = true
} else {
profileNewNameServers, err := cmd.Flags().GetStringSlice("name-servers")
printErrAndExitIfNotNil(err)
profile.NameServers.Data = profileNewNameServers
profile.NameServers.IsInherited = false
}
case "name-servers-search":
profileNewNameServersSearch, err := cmd.Flags().GetStringSlice("name-servers-search")
printErrAndExitIfNotNil(err)
profile.NameServersSearch = profileNewNameServersSearch
fallthrough
case "name-servers-search-inherit":
if cmd.Flags().Lookup("name-servers-search-inherit").Changed {
profile.NameServersSearch.Data = make([]string, 0)
profile.NameServersSearch.IsInherited = true
} else {
profileNewNameServersSearch, err := cmd.Flags().GetStringSlice("name-servers-search")
printErrAndExitIfNotNil(err)
profile.NameServersSearch.Data = profileNewNameServersSearch
profile.NameServersSearch.IsInherited = false
}
case "next-server-v4":
profileNewNextServerV4, err := cmd.Flags().GetString("next-server-v4")
printErrAndExitIfNotNil(err)
Expand Down Expand Up @@ -240,33 +256,54 @@ func updateProfileFromFlags(cmd *cobra.Command, profile *cobbler.Profile) {
printErrAndExitIfNotNil(err)
profile.Menu = profileNewMenu
case "virt-auto-boot":
profileNewVirtAutoBoot, err := cmd.Flags().GetString("virt-auto-boot")
printErrAndExitIfNotNil(err)
profile.VirtAutoBoot = profileNewVirtAutoBoot
fallthrough
case "virt-auto-boot-inherit":
if cmd.Flags().Lookup("virt-auto-boot-inherit").Changed {
profile.VirtAutoBoot.IsInherited = true
} else {
profileNewVirtAutoBoot, err := cmd.Flags().GetBool("virt-auto-boot")
printErrAndExitIfNotNil(err)
profile.VirtAutoBoot.Data = profileNewVirtAutoBoot
profile.VirtAutoBoot.IsInherited = false
}
case "virt-bridge":
profileNewVirtBridge, err := cmd.Flags().GetString("virt-bridge")
printErrAndExitIfNotNil(err)
profile.VirtBridge = profileNewVirtBridge
case "virt-cpus":
profileNewVirtCpus, err := cmd.Flags().GetString("virt-cpus")
profileNewVirtCpus, err := cmd.Flags().GetInt("virt-cpus")
printErrAndExitIfNotNil(err)
profile.VirtCPUs = profileNewVirtCpus
case "virt-disk-driver":
profileNewVirtDiskDriver, err := cmd.Flags().GetString("virt-disk-driver")
printErrAndExitIfNotNil(err)
profile.VirtDiskDriver = profileNewVirtDiskDriver
case "virt-file-size":
profileNewVirtFileSize, err := cmd.Flags().GetString("virt-file-size")
printErrAndExitIfNotNil(err)
profile.VirtFileSize = profileNewVirtFileSize
fallthrough
case "virt-file-size-inherit":
if cmd.Flags().Lookup("virt-auto-boot-inherit").Changed {
profile.VirtAutoBoot.IsInherited = true
} else {
profileNewVirtFileSize, err := cmd.Flags().GetFloat64("virt-file-size")
printErrAndExitIfNotNil(err)
profile.VirtFileSize.Data = profileNewVirtFileSize
profile.VirtFileSize.IsInherited = false
}
case "virt-path":
profileNewVirtPath, err := cmd.Flags().GetString("virt-path")
printErrAndExitIfNotNil(err)
profile.VirtPath = profileNewVirtPath
case "virt-ram":
profileNewVirtRam, err := cmd.Flags().GetString("virt-ram")
printErrAndExitIfNotNil(err)
profile.VirtRAM = profileNewVirtRam
fallthrough
case "virt-ram-inherit":
if cmd.Flags().Lookup("virt-auto-boot-inherit").Changed {
profile.VirtRAM.IsInherited = true
} else {
profileNewVirtRam, err := cmd.Flags().GetInt("virt-ram")
printErrAndExitIfNotNil(err)
profile.VirtRAM.Data = profileNewVirtRam
profile.VirtRAM.IsInherited = false
}
case "virt-type":
profileNewVirtType, err := cmd.Flags().GetString("virt-type")
printErrAndExitIfNotNil(err)
Expand All @@ -293,14 +330,14 @@ var profileAddCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
generateCobblerClient()

var newProfile cobbler.Profile
newProfile := cobbler.NewProfile()
var err error
// internal fields (ctime, mtime, uid, depth, repos-enabled) cannot be modified
newProfile.Name, _ = cmd.Flags().GetString("name")
updateProfileFromFlags(cmd, &newProfile)
profile, err := Client.CreateProfile(newProfile)
printErrAndExitIfNotNil(err)
fmt.Printf("Profile %s created", profile.Name)
fmt.Printf("Profile %s created\n", profile.Name)
},
}

Expand Down
Loading

0 comments on commit 451025d

Please sign in to comment.