From 71f905b5dc16080e04852c88a01838acafc12935 Mon Sep 17 00:00:00 2001 From: Srinivasan Date: Mon, 9 Nov 2020 13:04:23 +0530 Subject: [PATCH] CLI updated for init and clean Signed-off-by: Srinivasan Change-Id: Ic7c629dcfdedf2de07ae9e412edee18f2afbe796 --- ocd/cli/ealt/cmd/clean.go | 9 +------- ocd/cli/ealt/cmd/clean/infra.go | 38 ------------------------------- ocd/cli/ealt/cmd/clean/k3s.go | 39 -------------------------------- ocd/cli/ealt/cmd/clean/k8s.go | 39 -------------------------------- ocd/cli/ealt/cmd/clean/mecm.go | 39 -------------------------------- ocd/cli/ealt/cmd/init.go | 9 +------- ocd/cli/ealt/cmd/init/all.go | 8 +------ ocd/cli/ealt/cmd/init/edge.go | 8 +------ ocd/cli/ealt/cmd/init/infra.go | 38 ------------------------------- ocd/cli/ealt/cmd/init/k3s.go | 39 -------------------------------- ocd/cli/ealt/cmd/init/k8s.go | 39 -------------------------------- ocd/cli/ealt/cmd/init/mecm.go | 47 --------------------------------------- ocd/cli/ealt/cmd/setup/install.go | 33 +++++---------------------- 13 files changed, 9 insertions(+), 376 deletions(-) delete mode 100644 ocd/cli/ealt/cmd/clean/infra.go delete mode 100644 ocd/cli/ealt/cmd/clean/k3s.go delete mode 100644 ocd/cli/ealt/cmd/clean/k8s.go delete mode 100644 ocd/cli/ealt/cmd/clean/mecm.go delete mode 100644 ocd/cli/ealt/cmd/init/infra.go delete mode 100644 ocd/cli/ealt/cmd/init/k3s.go delete mode 100644 ocd/cli/ealt/cmd/init/k8s.go delete mode 100644 ocd/cli/ealt/cmd/init/mecm.go diff --git a/ocd/cli/ealt/cmd/clean.go b/ocd/cli/ealt/cmd/clean.go index 78f3b5d..9e94d4b 100644 --- a/ocd/cli/ealt/cmd/clean.go +++ b/ocd/cli/ealt/cmd/clean.go @@ -29,16 +29,9 @@ var cleanCmd = &cobra.Command{ func init() { cleanCmd.AddCommand(cleancmds.NewAllCommand()) - //ealt init infra - cleanCmd.AddCommand(cleancmds.NewInfraCommand()) - //ealt init manager - cleanCmd.AddCommand(cleancmds.NewMecmCommand()) + //ealt init edge cleanCmd.AddCommand(cleancmds.NewEdgeCommand()) - //ealt init k8s - cleanCmd.AddCommand(cleancmds.NewK8SCommand()) - //ealt init k3s - cleanCmd.AddCommand(cleancmds.NewK3SCommand()) //Add init subcommand to root command. rootCmd.AddCommand(cleanCmd) diff --git a/ocd/cli/ealt/cmd/clean/infra.go b/ocd/cli/ealt/cmd/clean/infra.go deleted file mode 100644 index 453cb65..0000000 --- a/ocd/cli/ealt/cmd/clean/infra.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - setup "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -func NewInfraCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "infra", - Short: "Uninstall only infrastructure components on MECM and Edge Node", - Long: `Command to Uninstall only infrastructure components on MECM and Edge Node For Example : ealt clean infra`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltReset("infra") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/clean/k3s.go b/ocd/cli/ealt/cmd/clean/k3s.go deleted file mode 100644 index 9c17898..0000000 --- a/ocd/cli/ealt/cmd/clean/k3s.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - setup "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewK3SCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "k3s", - Short: "Command to uninstall K3S cluster on Edge Node", - Long: `Command to uninstall K3S cluster on Edge Node`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltReset("k3s") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/clean/k8s.go b/ocd/cli/ealt/cmd/clean/k8s.go deleted file mode 100644 index db49da9..0000000 --- a/ocd/cli/ealt/cmd/clean/k8s.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewK8SCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "k8s", - Short: "Command to uninstall K8S cluster on MECM Node", - Long: `Command to uninstall K8S cluster on MECM Node`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltReset("k8s") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/clean/mecm.go b/ocd/cli/ealt/cmd/clean/mecm.go deleted file mode 100644 index fe29e1a..0000000 --- a/ocd/cli/ealt/cmd/clean/mecm.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - setup "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewMecmCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "manager", - Short: "Command to install MECM Controller", - Long: `Command to Install MECM Controller Node`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltReset("manager") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/init.go b/ocd/cli/ealt/cmd/init.go index cf8fcdb..843146c 100644 --- a/ocd/cli/ealt/cmd/init.go +++ b/ocd/cli/ealt/cmd/init.go @@ -36,16 +36,9 @@ func init() { //Adding the various sub-commands of init command //Adding all subcommand to init initCmd.AddCommand(initCmds.NewAllCommand()) - //ealt init infra - initCmd.AddCommand(initCmds.NewInfraCommand()) - //ealt init manager - initCmd.AddCommand(initCmds.NewMecmCommand()) + //ealt init edge initCmd.AddCommand(initCmds.NewEdgeCommand()) - //ealt init k8s - initCmd.AddCommand(initCmds.NewK8SCommand()) - //ealt init k3s - initCmd.AddCommand(initCmds.NewK3SCommand()) //Add init subcommand to root command. rootCmd.AddCommand(initCmd) diff --git a/ocd/cli/ealt/cmd/init/all.go b/ocd/cli/ealt/cmd/init/all.go index 061c629..72b2b7f 100644 --- a/ocd/cli/ealt/cmd/init/all.go +++ b/ocd/cli/ealt/cmd/init/all.go @@ -17,7 +17,6 @@ package init import ( setup "ealt/cmd/setup" - "strings" "github.com/spf13/cobra" ) @@ -29,13 +28,8 @@ func NewAllCommand() *cobra.Command { Short: "Install Complete EALT Deployment Environment", Long: `Install Complete EALT Deployment Environment`, RunE: func(cmd *cobra.Command, args []string) error { - setupModeFlag := strings.ToLower(cmd.Flag("mode").Value.String()) var err error - if setupModeFlag == "dev" { - err = setup.EaltInstall("all") - } else if setupModeFlag == "prod" { - err = setup.EaltInstall("secure") - } + err = setup.EaltInstall("all") if err != nil { return err } diff --git a/ocd/cli/ealt/cmd/init/edge.go b/ocd/cli/ealt/cmd/init/edge.go index 3b16f93..3349c70 100644 --- a/ocd/cli/ealt/cmd/init/edge.go +++ b/ocd/cli/ealt/cmd/init/edge.go @@ -17,7 +17,6 @@ package init import ( "fmt" - "strings" setup "ealt/cmd/setup" @@ -31,13 +30,8 @@ func NewEdgeCommand() *cobra.Command { Long: `Command to Install Edge Node only For Example : ealt init edge`, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("Installation of Edge components") - setupModeFlag := strings.ToLower(cmd.Flag("mode").Value.String()) var err error - if setupModeFlag == "dev" { - err = setup.EaltInstall("edge") - } else if setupModeFlag == "prod" { - err = setup.EaltInstall("ssledge") - } + err = setup.EaltInstall("edge") if err != nil { return err } diff --git a/ocd/cli/ealt/cmd/init/infra.go b/ocd/cli/ealt/cmd/init/infra.go deleted file mode 100644 index f25c61f..0000000 --- a/ocd/cli/ealt/cmd/init/infra.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - setup "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -func NewInfraCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "infra", - Short: "Install only infrastructure components on MECM and Edge Node", - Long: `Command to install only infrastructure components on MECM and Edge Node For Example : ealt init infra`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltInstall("infra") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/init/k3s.go b/ocd/cli/ealt/cmd/init/k3s.go deleted file mode 100644 index 4b3f080..0000000 --- a/ocd/cli/ealt/cmd/init/k3s.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewK3SCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "k3s", - Short: "Command to install K3S cluster on Edge Node", - Long: `Command to install K3S cluster on Edge Node`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltInstall("k3s") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/init/k8s.go b/ocd/cli/ealt/cmd/init/k8s.go deleted file mode 100644 index c92c9e4..0000000 --- a/ocd/cli/ealt/cmd/init/k8s.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - "ealt/cmd/setup" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewK8SCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "k8s", - Short: "Command to install K8S cluster on MECM Node", - Long: `Command to install K8S cluster on MECM Node`, - RunE: func(cmd *cobra.Command, args []string) error { - err := setup.EaltInstall("k8s") - if err != nil { - return err - } - return nil - }, - } - return cmd -} diff --git a/ocd/cli/ealt/cmd/init/mecm.go b/ocd/cli/ealt/cmd/init/mecm.go deleted file mode 100644 index d67e1c6..0000000 --- a/ocd/cli/ealt/cmd/init/mecm.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2020 Huawei Technologies Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package init - -import ( - "ealt/cmd/setup" - "strings" - - "github.com/spf13/cobra" -) - -// allCmd represents the all command -func NewMecmCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "manager", - Short: "Command to install MECM Controller", - Long: `Command to Install MECM Controller Node`, - RunE: func(cmd *cobra.Command, args []string) error { - setupModeFlag := strings.ToLower(cmd.Flag("mode").Value.String()) - var err error - if setupModeFlag == "dev" { - err = setup.EaltInstall("mecm") - } else if setupModeFlag == "prod" { - err = setup.EaltInstall("sslmecm") - } - if err != nil { - return err - } - return nil - }, - } - cmd.Flags().StringP("mode", "m", "dev", "Deployment Mode") - return cmd -} diff --git a/ocd/cli/ealt/cmd/setup/install.go b/ocd/cli/ealt/cmd/setup/install.go index 1205b27..add8100 100644 --- a/ocd/cli/ealt/cmd/setup/install.go +++ b/ocd/cli/ealt/cmd/setup/install.go @@ -25,26 +25,11 @@ func EaltInstall(component string) error { var strEaltSetup string switch component { case "all": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --extra-vars \"operation=install mode=dev\"") - // Production Mode : SSL Mode Installation Command. - case "sslall": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --extra-vars \"operation=install mode=prod\"") - case "infra": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"infra\" --extra-vars \"operation=install\"") - case "mecm": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=install mode=dev\"") - case "sslmecm": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=install mode=prod\"") + strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --extra-vars \"operation=install\"") case "edge": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=install mode=dev\"") - case "ssledge": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=install mode=prod\"") - case "k8s": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"k8s\" --extra-vars \"operation=install\"") - case "k3s": - strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"k3s\" --extra-vars \"operation=install\"") + strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"edge\" --extra-vars \"operation=install\"") default: - fmt.Println("Provide subcommand for ealt init [all|infra|manager|edge|k8s|k3s]") + fmt.Println("Provide subcommand for ealt init [all|edge]") } stdout, err := runCommandAtShell(strEaltSetup) @@ -61,18 +46,10 @@ func EaltReset(component string) error { switch component { case "all": strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --extra-vars \"operation=uninstall\"") - case "infra": - strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"infra\" --extra-vars \"operation=uninstall\"") - case "manager": - strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=uninstall\"") case "edge": - strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=uninstall\"") - case "k8s": - strEaltReset = fmt.Sprintf("cd ~/kubespray && yes | ansible-playbook -i inventory/mycluster/hosts.yaml --user root reset.yml") - case "k3s": - strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"k3s\" --extra-vars \"operation=uninstall\"") + strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"edge\" --extra-vars \"operation=uninstall\"") default: - fmt.Println("Provide subcommand for ealt clean [all|infra|manager|edge|k8s|k3s]") + fmt.Println("Provide subcommand for ealt clean [all|edge]") } stdout, err := runCommandAtShell(strEaltReset) -- 2.16.6