From a29e9ed6be83d329a4544383e5e3fb2851d13e23 Mon Sep 17 00:00:00 2001 From: MatthewHink Date: Tue, 15 Feb 2022 10:58:28 -0500 Subject: [PATCH 1/2] Remove unique settings from profile set. Warn if set in the node DB. IP address MAC address Asset Tag --- internal/app/wwctl/profile/set/main.go | 29 ++------------------------ internal/app/wwctl/profile/set/root.go | 6 ------ internal/pkg/node/constructors.go | 4 +++- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index 09d4c288..d0eddf4e 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -70,11 +70,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.Root.Set(SetRoot) } - if SetAssetKey != "" { - wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting asset key to: %s\n", p.Id.Get(), SetAssetKey) - p.AssetKey.Set(SetAssetKey) - } - if SetKernel != "" { wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel to: %s\n", p.Id.Get(), SetKernel) p.KernelVersion.Set(SetKernel) @@ -158,23 +153,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.NetDevs[SetNetName].Device.Set(SetNetDev) } - if SetIpaddr != "" { - if SetNetName == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") - os.Exit(1) - } - - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting IP address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) - p.NetDevs[SetNetName].Ipaddr.Set(SetIpaddr) - } - if SetNetmask != "" { if SetNetName == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") os.Exit(1) } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) + wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s\n", p.Id.Get(), SetNetName) p.NetDevs[SetNetName].Netmask.Set(SetNetmask) } @@ -184,20 +169,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) + wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s\n", p.Id.Get(), SetNetName) p.NetDevs[SetNetName].Gateway.Set(SetGateway) } - if SetHwaddr != "" { - if SetNetName == "" { - wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") - os.Exit(1) - } - - wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetName, SetHwaddr) - p.NetDevs[SetNetName].Hwaddr.Set(SetHwaddr) - } - if SetType != "" { if SetNetName == "" { wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n") diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index d8b08dc6..baa1b76b 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -52,10 +52,8 @@ var ( SetIpmiInterface string SetNetName string SetNetDev string - SetIpaddr string SetNetmask string SetGateway string - SetHwaddr string SetType string SetNetOnBoot string SetNetDefault string @@ -67,7 +65,6 @@ var ( SetKey string SetTags []string SetDelTags []string - SetAssetKey string ) func init() { @@ -91,7 +88,6 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container") baseCmd.PersistentFlags().StringVar(&SetRoot, "root", "", "Define the rootfs") - baseCmd.PersistentFlags().StringVar(&SetAssetKey, "assetkey", "", "Set the node's Asset tag (key)") baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") if err := baseCmd.RegisterFlagCompletionFunc("runtime", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -117,10 +113,8 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure") baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Set the node's network device") - baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address") baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask") baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway") - baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type") baseCmd.PersistentFlags().StringVar(&SetNetOnBoot, "onboot", "", "Enable/disable device (yes/no)") diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index ebf35397..410587ab 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -229,7 +229,9 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { p.RuntimeOverlay.Set(profile.RuntimeOverlay) p.SystemOverlay.Set(profile.SystemOverlay) p.Root.Set(profile.Root) - p.AssetKey.Set(profile.AssetKey) + if profile.AssetKey != "" { + wwlog.Printf(wwlog.WARN, "Ignoring asset key %v in profile %v\n", profile.AssetKey, name) + } p.Discoverable.Set(profile.Discoverable) for devname, netdev := range profile.NetDevs { From a01e8319d296d9865009f31b793c9d5d9b568869 Mon Sep 17 00:00:00 2001 From: MatthewHink Date: Wed, 16 Feb 2022 11:41:44 -0500 Subject: [PATCH 2/2] Allow asset tags in the profile. Warn and ignore ip addresses and hardware addresses. --- internal/app/wwctl/profile/set/main.go | 5 +++++ internal/app/wwctl/profile/set/root.go | 3 ++- internal/pkg/node/constructors.go | 14 +++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/app/wwctl/profile/set/main.go b/internal/app/wwctl/profile/set/main.go index d0eddf4e..81b1ed85 100644 --- a/internal/app/wwctl/profile/set/main.go +++ b/internal/app/wwctl/profile/set/main.go @@ -70,6 +70,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { p.Root.Set(SetRoot) } + if SetAssetKey != "" { + wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting asset key to: %s\n", p.Id.Get(), SetAssetKey) + p.AssetKey.Set(SetAssetKey) + } + if SetKernel != "" { wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel to: %s\n", p.Id.Get(), SetKernel) p.KernelVersion.Set(SetKernel) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index baa1b76b..f7a48be1 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -65,6 +65,7 @@ var ( SetKey string SetTags []string SetDelTags []string + SetAssetKey string ) func init() { @@ -88,7 +89,7 @@ func init() { baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container") baseCmd.PersistentFlags().StringVar(&SetRoot, "root", "", "Define the rootfs") - + baseCmd.PersistentFlags().StringVar(&SetAssetKey, "assetkey", "", "Set the node's Asset tag (key)") baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") if err := baseCmd.RegisterFlagCompletionFunc("runtime", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { list, _ := overlay.FindOverlays() diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 410587ab..927b479c 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -229,9 +229,7 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { p.RuntimeOverlay.Set(profile.RuntimeOverlay) p.SystemOverlay.Set(profile.SystemOverlay) p.Root.Set(profile.Root) - if profile.AssetKey != "" { - wwlog.Printf(wwlog.WARN, "Ignoring asset key %v in profile %v\n", profile.AssetKey, name) - } + p.AssetKey.Set(profile.AssetKey) p.Discoverable.Set(profile.Discoverable) for devname, netdev := range profile.NetDevs { @@ -243,13 +241,19 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) { wwlog.Printf(wwlog.DEBUG, "Updating profile netdev: %s\n", devname) p.NetDevs[devname].Device.Set(netdev.Device) - p.NetDevs[devname].Ipaddr.Set(netdev.Ipaddr) p.NetDevs[devname].Netmask.Set(netdev.Netmask) - p.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr) p.NetDevs[devname].Gateway.Set(netdev.Gateway) p.NetDevs[devname].Type.Set(netdev.Type) p.NetDevs[devname].OnBoot.Set(netdev.OnBoot) p.NetDevs[devname].Default.Set(netdev.Default) + + // The following should not be set in a profile. + if netdev.Ipaddr != "" { + wwlog.Printf(wwlog.WARN, "Ignoring ip address %v in profile %v\n", netdev.Ipaddr, name) + } + if netdev.Hwaddr != "" { + wwlog.Printf(wwlog.WARN, "Ignoring hardware address %v in profile %v\n", netdev.Hwaddr, name) + } } // Merge Keys into Tags for backwards compatibility