1205b2761bbc7f4355c5536e48c5afd21271b200
[ealt-edge.git] / ocd / cli / ealt / cmd / setup / install.go
1 /*
2 Copyright 2020 Huawei Technologies Co., Ltd.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16 package setup
17
18 import (
19         "fmt"
20 )
21
22 //Function : Commands for all installation components.
23 //Depending on the option respective command will be executed.
24 func EaltInstall(component string) error {
25         var strEaltSetup string
26         switch component {
27         case "all":
28                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --extra-vars \"operation=install mode=dev\"")
29         // Production Mode : SSL Mode Installation Command.
30         case "sslall":
31                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --extra-vars \"operation=install mode=prod\"")
32         case "infra":
33                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"infra\" --extra-vars \"operation=install\"")
34         case "mecm":
35                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=install mode=dev\"")
36         case "sslmecm":
37                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=install mode=prod\"")
38         case "edge":
39                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=install mode=dev\"")
40         case "ssledge":
41                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=install mode=prod\"")
42         case "k8s":
43                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"k8s\" --extra-vars \"operation=install\"")
44         case "k3s":
45                 strEaltSetup = fmt.Sprintf("ansible-playbook ealt-all.yml -i ealt-inventory.ini --tags \"k3s\" --extra-vars \"operation=install\"")
46         default:
47                 fmt.Println("Provide subcommand for ealt init [all|infra|manager|edge|k8s|k3s]")
48         }
49
50         stdout, err := runCommandAtShell(strEaltSetup)
51         if err != nil {
52                 return err
53         }
54         fmt.Println(stdout)
55         return nil
56 }
57
58 func EaltReset(component string) error {
59         var strEaltReset string
60
61         switch component {
62         case "all":
63                 strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --extra-vars \"operation=uninstall\"")
64         case "infra":
65                 strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"infra\" --extra-vars \"operation=uninstall\"")
66         case "manager":
67                 strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"mecm\" --extra-vars \"operation=uninstall\"")
68         case "edge":
69                 strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"mep\" --extra-vars \"operation=uninstall\"")
70         case "k8s":
71                 strEaltReset = fmt.Sprintf("cd ~/kubespray && yes | ansible-playbook -i inventory/mycluster/hosts.yaml --user root reset.yml")
72         case "k3s":
73                 strEaltReset = fmt.Sprintf("ansible-playbook ealt-all-uninstall.yml -i ealt-inventory.ini --tags \"k3s\" --extra-vars \"operation=uninstall\"")
74         default:
75                 fmt.Println("Provide subcommand for ealt clean [all|infra|manager|edge|k8s|k3s]")
76         }
77
78         stdout, err := runCommandAtShell(strEaltReset)
79         if err != nil {
80                 return err
81         }
82         fmt.Println(stdout)
83         return nil
84 }