forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_cmd.go
94 lines (78 loc) · 2.65 KB
/
deployment_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cmd
import (
"fmt"
"path/filepath"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
boshsys "github.com/cloudfoundry/bosh-agent/system"
boshuuid "github.com/cloudfoundry/bosh-agent/uuid"
bmconfig "github.com/cloudfoundry/bosh-micro-cli/config"
bmui "github.com/cloudfoundry/bosh-micro-cli/ui"
)
type deploymentCmd struct {
ui bmui.UI
userConfig bmconfig.UserConfig
userConfigService bmconfig.UserConfigService
fs boshsys.FileSystem
uuidGenerator boshuuid.Generator
logger boshlog.Logger
logTag string
}
func NewDeploymentCmd(
ui bmui.UI,
userConfig bmconfig.UserConfig,
userConfigService bmconfig.UserConfigService,
fs boshsys.FileSystem,
uuidGenerator boshuuid.Generator,
logger boshlog.Logger,
) Cmd {
return &deploymentCmd{
ui: ui,
userConfig: userConfig,
userConfigService: userConfigService,
fs: fs,
uuidGenerator: uuidGenerator,
logger: logger,
logTag: "deploymentCmd",
}
}
func (c *deploymentCmd) Name() string {
return "deployment"
}
func (c *deploymentCmd) Run(args []string) error {
if args == nil || len(args) < 1 {
_, err := getDeploymentManifest(c.userConfig, c.ui, c.fs)
if err != nil {
return bosherr.WrapErrorf(err, "Running deployment cmd")
}
return nil
}
manifestFilePath := args[0]
return c.setDeployment(manifestFilePath)
}
func (c *deploymentCmd) setDeployment(manifestFilePath string) error {
manifestAbsFilePath, err := filepath.Abs(manifestFilePath)
if err != nil {
c.ui.Error(fmt.Sprintf("Failed getting absolute path to deployment file '%s'", manifestFilePath))
return bosherr.WrapErrorf(err, "Getting absolute path to deployment file '%s'", manifestFilePath)
}
if !c.fs.FileExists(manifestAbsFilePath) {
c.ui.Error(fmt.Sprintf("Deployment '%s' does not exist", manifestAbsFilePath))
return bosherr.Errorf("Verifying that the deployment '%s' exists", manifestAbsFilePath)
}
c.userConfig.DeploymentManifestPath = manifestAbsFilePath
err = c.userConfigService.Save(c.userConfig)
if err != nil {
return bosherr.WrapError(err, "Saving user config")
}
c.ui.Sayln(fmt.Sprintf("Deployment manifest set to '%s'", manifestAbsFilePath))
deploymentConfigPath := c.userConfig.DeploymentConfigPath()
deploymentConfigService := bmconfig.NewFileSystemDeploymentConfigService(deploymentConfigPath, c.fs, c.uuidGenerator, c.logger)
// initialize defaults
_, err = deploymentConfigService.Load()
if err != nil {
return err
}
c.ui.Sayln(fmt.Sprintf("Deployment state set to '%s'", deploymentConfigPath))
return nil
}