11package main
22
33import (
4- "log "
5- "launchpad.net/goamz/aws "
6- "launchpad.net/goamz/ec2 "
4+ "launchpad.net/goamz/aws "
5+ "launchpad.net/goamz/ec2 "
6+ "log "
77)
88
99func getEC2Instances (config map [string ]string ) (instances Instances ) {
10- instances = make (Instances )
10+ instances = make (Instances )
1111
12- if _ ,ok := config ["access_key" ]; ! ok {
13- log .Fatal ("Missing access_key for " , config ["name" ], " AWS cloud" )
14- }
12+ if _ , ok := config ["access_key" ]; ! ok {
13+ log .Fatal ("Missing access_key for " , config ["name" ], " AWS cloud" )
14+ }
1515
16- if _ ,ok := config ["secret_key" ]; ! ok {
17- log .Fatal ("Missing secret_key for " , config ["name" ], " AWS cloud" )
18- }
16+ if _ , ok := config ["secret_key" ]; ! ok {
17+ log .Fatal ("Missing secret_key for " , config ["name" ], " AWS cloud" )
18+ }
1919
20- if _ ,ok := config ["region" ]; ! ok {
21- config ["region" ] = "us-east-1"
22- }
20+ if _ , ok := config ["region" ]; ! ok {
21+ config ["region" ] = "us-east-1"
22+ }
2323
24- auth := aws.Auth {config ["access_key" ], config ["secret_key" ]}
24+ auth := aws.Auth {config ["access_key" ], config ["secret_key" ]}
2525
26- e := ec2 .New (auth , aws .Regions [config ["region" ]])
27- resp , err := e .Instances (nil , nil )
26+ e := ec2 .New (auth , aws .Regions [config ["region" ]])
27+ resp , err := e .Instances (nil , nil )
2828
29- if err != nil {
30- log .Println (err )
31- return
32- }
29+ if err != nil {
30+ log .Println (err )
31+ return
32+ }
3333
34- for _ , res := range resp .Reservations {
35- for _ , inst := range res .Instances {
36-
37- if inst .DNSName != "" {
38- var tags []Tag
34+ for _ , res := range resp .Reservations {
35+ for _ , inst := range res .Instances {
3936
40- for _ , tag := range inst .Tags {
41- tags = append (tags , Tag {tag .Key , tag .Value })
42- }
37+ if inst .DNSName != "" {
38+ var tags []Tag
4339
44- for _ , sg := range inst .SecurityGroups {
45- tags = append (tags , Tag {"Security group" , sg . Name })
46- }
40+ for _ , tag := range inst .Tags {
41+ tags = append (tags , Tag {tag . Key , tag . Value })
42+ }
4743
48- instances [inst .DNSName ] = tags
49- }
50- }
51- }
44+ for _ , sg := range inst .SecurityGroups {
45+ tags = append (tags , Tag {"Security group" , sg .Name })
46+ }
5247
53- return
54- }
48+ instances [inst .DNSName ] = tags
49+ }
50+ }
51+ }
52+
53+ return
54+ }
0 commit comments