-
Notifications
You must be signed in to change notification settings - Fork 160
/
update_cpi_config.go
43 lines (33 loc) · 1.07 KB
/
update_cpi_config.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
package cmd
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
. "github.com/cloudfoundry/bosh-cli/v7/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/v7/director"
boshtpl "github.com/cloudfoundry/bosh-cli/v7/director/template"
boshui "github.com/cloudfoundry/bosh-cli/v7/ui"
)
type UpdateCPIConfigCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewUpdateCPIConfigCmd(ui boshui.UI, director boshdir.Director) UpdateCPIConfigCmd {
return UpdateCPIConfigCmd{ui: ui, director: director}
}
func (c UpdateCPIConfigCmd) Run(opts UpdateCPIConfigOpts) error {
tpl := boshtpl.NewTemplate(opts.Args.CPIConfig.Bytes)
bytes, err := tpl.Evaluate(opts.VarFlags.AsVariables(), opts.OpsFlags.AsOp(), boshtpl.EvaluateOpts{})
if err != nil {
return bosherr.WrapErrorf(err, "Evaluating cpi config")
}
configDiff, err := c.director.DiffCPIConfig(bytes, opts.NoRedact)
if err != nil {
return err
}
diff := NewDiff(configDiff.Diff)
diff.Print(c.ui)
err = c.ui.AskForConfirmation()
if err != nil {
return err
}
return c.director.UpdateCPIConfig(bytes)
}