-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathavailibiltyzones.go
73 lines (62 loc) · 1.93 KB
/
availibiltyzones.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
71
72
73
package main
import (
"encoding/json"
"log"
"github.com/aws/aws-sdk-go/service/ec2"
)
type availabilityZoneList struct {
*ec2.DescribeAvailabilityZonesOutput
}
type availabilityZoneNodes []availabilityZoneNode
type availabilityZoneNode struct {
UID string `json:"uid,omitempty"`
Type []string `json:"dgraph.type,omitempty"`
Name string `json:"name,omitempty"` // This field is only for Ratel Viz
Region string `json:"Region,omitempty"`
Service string `json:"Service,omitempty"`
State string `json:"State,omitempty"`
ZoneName string `json:"ZoneName,omitempty"`
ZoneID string `json:"ZoneId,omitempty"`
}
func (c *connector) listAvailabilityZones() availabilityZoneList {
defer c.waitGroup.Done()
log.Println("List AvailibiltyZones")
response, err := ec2.New(c.awsSession).DescribeAvailabilityZones(&ec2.DescribeAvailabilityZonesInput{})
if err != nil {
log.Fatal(err)
}
return availabilityZoneList{response}
}
func (list availabilityZoneList) addNodes(c *connector) {
defer c.waitGroup.Done()
if len(list.AvailabilityZones) == 0 {
return
}
log.Println("Add AvailibilityZones Nodes")
m := make(map[string]availabilityZoneNodes)
json.Unmarshal(c.dgraphQuery("AvailabilityZone"), &m)
a := make(availabilityZoneNodes, 0, len(list.AvailabilityZones))
for _, i := range list.AvailabilityZones {
var b availabilityZoneNode
for _, j := range m["list"] {
if *i.ZoneName == j.ZoneName {
b.UID = j.UID
}
}
b.Service = "ec2"
b.Type = []string{"AvailabilityZone"}
b.Region = c.awsRegion
b.Name = *i.ZoneName
b.ZoneName = *i.ZoneName
b.ZoneID = *i.ZoneId
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)
json.Unmarshal(c.dgraphQuery("AvailabilityZone"), &m)
n := make(map[string]string)
for _, i := range m["list"] {
n[i.ZoneName] = i.UID
}
c.ressources["AvailabilityZones"] = n
}