AIO and MUNO mode upgrade for EG 1.5.0 version
[eliot.git] / blueprints / common / elcli / elcli / cmd / util / dockerinstaller.go
1 /*
2 Copyright 2019 The Kubeedge Authors.
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
17 package util
18
19 import (
20         "fmt"
21
22         types "elcli/cmd/common"
23 )
24
25 //DockerInstTool embedes Common struct and contains the default docker version
26 //It implements ToolsInstaller interface
27 type DockerInstTool struct {
28         Common
29         DefaultToolVer string
30 }
31
32 //InstallTools sets the OS interface, checks if docker installation is required or not.
33 //If required then install the said version.
34 func (d *DockerInstTool) InstallTools() error {
35         d.SetOSInterface(GetOSInterface())
36         d.SetDockerVersion(d.ToolVersion)
37
38         action, err := d.IsDockerInstalled(d.DefaultToolVer)
39         if err != nil {
40                 return err
41         }
42         switch action {
43         case types.VersionNAInRepo:
44                 return fmt.Errorf("Expected Docker version is not available in OS repo")
45         case types.AlreadySameVersionExist:
46                 fmt.Println("Same version of docker already installed in this host")
47                 return nil
48         case types.DefVerInstallRequired:
49                 d.SetDockerVersion(d.DefaultToolVer)
50                 fallthrough
51         case types.NewInstallRequired:
52                 err := d.InstallDocker()
53                 if err != nil {
54                         return err
55                 }
56         default:
57                 return fmt.Errorf("Error in getting the docker version from host")
58         }
59
60         return nil
61 }
62
63 //TearDown shoud uninstall docker, but it is not required either for cloud or edge node.
64 //It is defined so that DockerInstTool implements ToolsInstaller interface
65 func (d *DockerInstTool) TearDown() error {
66         return nil
67 }