From a81cabbf7d800f5c216930a1daa4337b4ed8ffbc Mon Sep 17 00:00:00 2001 From: inho Date: Fri, 28 Jun 2024 10:57:10 +0900 Subject: [PATCH] Add path flag to loxicmd save to non default /etc/loxilb directory #706 in loxilb --- cmd/dump/save.go | 6 +++++- cmd/root.go | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/dump/save.go b/cmd/dump/save.go index dc00400..0b14d36 100644 --- a/cmd/dump/save.go +++ b/cmd/dump/save.go @@ -34,6 +34,7 @@ type SaveOptions struct { SaveEPConfig bool SaveBFDConfig bool SaveAllConfig bool + ConfigPath string } // saveCmd represents the save command @@ -46,6 +47,9 @@ func SaveCmd(saveOpts *SaveOptions, restOptions *api.RESTOptions) *cobra.Command _ = cmd _ = args dpath := "/etc/loxilb/" + if saveOpts.ConfigPath != "" { + dpath = saveOpts.ConfigPath + } if !saveOpts.SaveIpConfig && !saveOpts.SaveAllConfig && !saveOpts.SaveLBConfig && !saveOpts.SaveSessionConfig && !saveOpts.SaveUlClConfig && !saveOpts.SaveFWConfig && @@ -57,7 +61,7 @@ func SaveCmd(saveOpts *SaveOptions, restOptions *api.RESTOptions) *cobra.Command if _, err := os.Stat(dpath); errors.Is(err, os.ErrNotExist) { err := os.Mkdir(dpath, os.ModePerm) if err != nil { - fmt.Println("Can't create config dir /etc/loxilb/") + fmt.Println("Can't create config dir %v", dpath) return } } diff --git a/cmd/root.go b/cmd/root.go index 8bbfa79..91de712 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -102,13 +102,15 @@ loxicmd aim to provide all of the configuation for the loxilb.`, saveCmd.Flags().BoolVarP(&saveOptions.SaveFWConfig, "firewall", "", false, "Saves firewall configuration") saveCmd.Flags().BoolVarP(&saveOptions.SaveEPConfig, "endpoint", "", false, "Saves endpoint configuration") saveCmd.Flags().BoolVarP(&saveOptions.SaveBFDConfig, "bfd", "", false, "Saves BFD configuration") + saveCmd.Flags().StringVarP(&saveOptions.ConfigPath, "config-path", "c", "", "config file patch setting") saveCmd.MarkFlagsMutuallyExclusive("all", "ip", "lb", "session", "ulcl", "firewall", "endpoint", "bfd") applyCmd.Flags().StringVarP(&applyOptions.IpConfigFile, "ip", "i", "", "IP config file to apply") applyCmd.Flags().StringVarP(&applyOptions.Intf, "per-intf", "", "", "Apply configuration only for specific interface") applyCmd.Flags().BoolVarP(&applyOptions.Route, "ipv4route", "r", false, "Apply route configuration only for specific interface") - applyCmd.Flags().StringVarP(&applyOptions.ConfigPath, "config-path", "c", "/opt/loxilb/ipconfig/", "Configuration path only for applying per interface config") + + applyCmd.Flags().StringVarP(&applyOptions.ConfigPath, "config-path", "c", "/etc/loxilb/ipconfig/", "Configuration path only for applying per interface config") applyCmd.Flags().StringVarP(&applyOptions.LBConfigFile, "lb", "l", "", "Load Balancer config file to apply") applyCmd.Flags().StringVarP(&applyOptions.SessionConfigFile, "session", "", "", "Session config file to apply") applyCmd.Flags().StringVarP(&applyOptions.SessionUlClConfigFile, "ulcl", "", "", "Ulcl config file to apply")