-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_cc_vms.go
60 lines (49 loc) · 1.1 KB
/
get_cc_vms.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
package cfbackup
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strings"
)
type (
VMObject struct {
Job string
Index int
}
CloudControllerDeploymentParser struct {
vms []CCJob
}
)
func GetCCVMs(jsonObj []VMObject) ([]CCJob, error) {
parser := &CloudControllerDeploymentParser{}
return parser.Parse(jsonObj)
}
func (s *CloudControllerDeploymentParser) Parse(jsonObj []VMObject) ([]CCJob, error) {
err := s.setupAndRun(jsonObj)
return s.vms, err
}
func (s *CloudControllerDeploymentParser) setupAndRun(jsonObj []VMObject) (err error) {
var ccjobs = make([]CCJob, 0)
for _, vmObject := range jsonObj {
if strings.Contains(vmObject.Job, "cloud_controller-partition") {
ccJob := CCJob{
Job: vmObject.Job,
Index: vmObject.Index,
}
ccjobs = append(ccjobs, ccJob)
}
}
if len(ccjobs) == 0 {
return fmt.Errorf("no cc jobs found")
}
s.vms = ccjobs
return nil
}
func ReadAndUnmarshalVMObjects(src io.Reader) (jsonObj []VMObject, err error) {
var contents []byte
if contents, err = ioutil.ReadAll(src); err == nil {
err = json.Unmarshal(contents, &jsonObj)
}
return
}