-
Notifications
You must be signed in to change notification settings - Fork 162
/
vm_repo.go
65 lines (52 loc) · 1.45 KB
/
vm_repo.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
package config
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type VMRepo interface {
FindCurrent() (cid string, found bool, err error)
UpdateCurrent(cid string) error
ClearCurrent() error
}
type vMRepo struct {
deploymentStateService DeploymentStateService
}
func NewVMRepo(deploymentStateService DeploymentStateService) VMRepo {
return vMRepo{
deploymentStateService: deploymentStateService,
}
}
func (r vMRepo) FindCurrent() (string, bool, error) {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return "", false, bosherr.WrapError(err, "Loading existing config")
}
currentVMCID := deploymentState.CurrentVMCID
if currentVMCID != "" {
return currentVMCID, true, nil
}
return "", false, nil
}
func (r vMRepo) UpdateCurrent(cid string) error {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return bosherr.WrapError(err, "Loading existing config")
}
deploymentState.CurrentVMCID = cid
err = r.deploymentStateService.Save(deploymentState)
if err != nil {
return bosherr.WrapError(err, "Saving new config")
}
return nil
}
func (r vMRepo) ClearCurrent() error {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return bosherr.WrapError(err, "Loading existing config")
}
deploymentState.CurrentVMCID = ""
err = r.deploymentStateService.Save(deploymentState)
if err != nil {
return bosherr.WrapError(err, "Saving new config")
}
return nil
}