-
Notifications
You must be signed in to change notification settings - Fork 114
/
prepare_network_change.go
66 lines (52 loc) · 1.59 KB
/
prepare_network_change.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
package action
import (
"errors"
"time"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type PrepareNetworkChangeAction struct {
fs boshsys.FileSystem
settingsService boshsettings.Service
waitToKillAgentInterval time.Duration
agentKiller Killer
}
func NewPrepareNetworkChange(
fs boshsys.FileSystem,
settingsService boshsettings.Service,
agentKiller Killer,
) (prepareAction PrepareNetworkChangeAction) {
prepareAction.fs = fs
prepareAction.settingsService = settingsService
prepareAction.waitToKillAgentInterval = 1 * time.Second
prepareAction.agentKiller = agentKiller
return
}
func (a PrepareNetworkChangeAction) IsAsynchronous(_ ProtocolVersion) bool {
return false
}
func (a PrepareNetworkChangeAction) IsPersistent() bool {
return false
}
func (a PrepareNetworkChangeAction) IsLoggable() bool {
return true
}
func (a PrepareNetworkChangeAction) Run() (interface{}, error) {
err := a.settingsService.InvalidateSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Invalidating settings")
}
err = a.fs.RemoveAll("/etc/udev/rules.d/70-persistent-net.rules")
if err != nil {
return nil, bosherr.WrapError(err, "Removing network rules file")
}
go a.agentKiller.KillAgent(a.waitToKillAgentInterval)
return "ok", nil
}
func (a PrepareNetworkChangeAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a PrepareNetworkChangeAction) Cancel() error {
return errors.New("not supported")
}