forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupervisor_status.go
More file actions
98 lines (80 loc) · 2.2 KB
/
Copy pathsupervisor_status.go
File metadata and controls
98 lines (80 loc) · 2.2 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// This script makes it easier to manage workers on different instances.
// Supervisor comes with a web ui, however it's only for a single instance,
// so we create a new html page that contains the iframe of all the
// instances in that environment.
package main
import (
"fmt"
"io/ioutil"
"koding/tools/config"
"log"
"os"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb"
)
// elasticbeanstalk load balancer names
var environments = map[string]string{
"production": "awseb-e-x-AWSEBLoa-2AG3XORA8JXC",
"latest": "awseb-e-3-AWSEBLoa-1S2VPBAQXDRW9",
"sandbox": "awseb-e-2-AWSEBLoa-Z9CEV6ZDEFMC",
}
var region = aws.USEast
func main() {
if len(os.Args) < 2 {
log.Fatal("No environment. Please pass: production, latest, sandbox")
}
env := os.Args[1]
loadBalancerName, ok := environments[env]
if !ok {
log.Fatal("Unknown environment. Please pick: production, latest, sandbox")
}
conf := config.MustConfig("dev")
auth, err := aws.GetAuth(conf.Aws.Key, conf.Aws.Secret)
if err != nil {
log.Fatal(err)
}
// get list of instances in a load balancer
elbClient := elb.New(auth, region)
options := &elb.DescribeLoadBalancer{
Names: []string{loadBalancerName},
}
elbResp, err := elbClient.DescribeLoadBalancers(options)
if err != nil {
log.Fatal(err)
}
elbInstances := elbResp.LoadBalancers[0].Instances
instances := []string{}
for _, instance := range elbInstances {
instances = append(instances, instance.InstanceId)
}
// get the ipaddress of the instances
ec2Client := ec2.New(auth, region)
resp, err := ec2Client.Instances(instances, nil)
if err != nil {
log.Fatal(err)
}
ips := []string{}
for _, reservation := range resp.Reservations {
for _, instance := range reservation.Instances {
ips = append(ips, instance.PublicIpAddress)
}
}
// generate html
var output string = fmt.Sprintf("Environment: %s", env)
for _, ip := range ips {
output += fmt.Sprintf(template, ip)
}
bites := []byte(output)
err = ioutil.WriteFile("supervisor.html", bites, 0644)
if err != nil {
log.Fatal(err)
}
}
var template = `
<div>
%[1]s<br>
<iframe src="http://koding:1q2w3e4r@%[1]s:9001" width=800px height=1100px;">
</iframe>
</div>
`