/
stop.go
67 lines (54 loc) · 1.64 KB
/
stop.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
package cmd
import (
"errors"
. "github.com/cloudfoundry/bosh-cli/v7/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/v7/director"
boshui "github.com/cloudfoundry/bosh-cli/v7/ui"
)
type StopCmd struct {
ui boshui.UI
deployment boshdir.Deployment
}
func NewStopCmd(ui boshui.UI, deployment boshdir.Deployment) StopCmd {
return StopCmd{ui: ui, deployment: deployment}
}
func (c StopCmd) Run(opts StopOpts) error {
err := c.ui.AskForConfirmation()
if err != nil {
return err
}
stopOpts, err := newStopOpts(opts)
if err != nil {
return err
}
return c.deployment.Stop(opts.Args.Slug, stopOpts)
}
func newStopOpts(opts StopOpts) (boshdir.StopOpts, error) {
if !opts.NoConverge { // converge is default, no-converge is opt-in
stopOpts := boshdir.StopOpts{
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Hard: opts.Hard,
SkipDrain: opts.SkipDrain,
Converge: true,
}
return stopOpts, nil
}
if opts.Converge {
return boshdir.StopOpts{}, errors.New("Can't set converge and no-converge")
}
if opts.Canaries != "" {
return boshdir.StopOpts{}, errors.New("Can't set canaries and no-converge")
}
if opts.MaxInFlight != "" {
return boshdir.StopOpts{}, errors.New("Can't set max-in-flight and no-converge")
}
if _, ok := opts.Args.Slug.InstanceSlug(); !ok {
return boshdir.StopOpts{}, errors.New("You are trying to run stop 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.StopOpts{
Converge: false,
Hard: opts.Hard,
SkipDrain: opts.SkipDrain,
}, nil
}