-
Notifications
You must be signed in to change notification settings - Fork 162
/
recreate.go
70 lines (58 loc) · 1.84 KB
/
recreate.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
package cmd
import (
"errors"
. "github.com/cloudfoundry/bosh-cli/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type RecreateCmd struct {
ui boshui.UI
deployment boshdir.Deployment
}
func NewRecreateCmd(ui boshui.UI, deployment boshdir.Deployment) RecreateCmd {
return RecreateCmd{ui: ui, deployment: deployment}
}
func (c RecreateCmd) Run(opts RecreateOpts) error {
err := c.ui.AskForConfirmation()
if err != nil {
return err
}
recreateOpts, err := newRecreateOpts(opts)
if err != nil {
return err
}
return c.deployment.Recreate(opts.Args.Slug, recreateOpts)
}
func newRecreateOpts(opts RecreateOpts) (boshdir.RecreateOpts, error) {
if !opts.NoConverge { // converge is default, no-converge is opt-in
recreateOpts := boshdir.RecreateOpts{
SkipDrain: opts.SkipDrain,
Fix: opts.Fix,
DryRun: opts.DryRun,
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Converge: true,
}
return recreateOpts, nil
}
if opts.Converge {
return boshdir.RecreateOpts{}, errors.New("Can't set converge and no-converge")
}
if opts.Canaries != "" {
return boshdir.RecreateOpts{}, errors.New("Can't set canaries and no-converge")
}
if opts.MaxInFlight != "" {
return boshdir.RecreateOpts{}, errors.New("Can't set max-in-flight and no-converge")
}
if opts.DryRun {
return boshdir.RecreateOpts{}, errors.New("Can't set dry-run and no-converge")
}
if _, ok := opts.Args.Slug.InstanceSlug(); !ok {
return boshdir.RecreateOpts{}, errors.New("You are trying to run recreate with --no-converge on an entire instance group. This operation is not allowed. Trying using the --converge flag or running it against a specific instance.")
}
return boshdir.RecreateOpts{
Converge: false,
SkipDrain: opts.SkipDrain,
Fix: opts.Fix,
}, nil
}