-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
81 lines (64 loc) · 1.58 KB
/
config.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
74
75
76
77
78
79
80
81
package config
import (
"os"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)
//DefaultHome user home
const DefaultHome = "/home/ec2-user"
const TagMaster = "beej-master"
const TagSlave = "beej"
//T2Micro instance type
const T2Micro = "t2.micro"
//T2Small instance type
const T2Small = "t2.small"
//DefaultUser is ec2 instance , this specity user name , only use Amazon AMI as base image
const DefaultUser = "ec2-user"
//JmeterCluster is beej ec2 instance warpper
type JmeterCluster struct {
Master Server
Slave []Server
}
//Server is ec2 instance warpper struct
type Server struct {
PublicDnsName string
PrivateIP string
IsMaster bool
RawInstance *ec2.Instance
}
type InstanceConfig struct {
ImageId *string
InstanceType *string
MinCount *int64
MaxCount *int64
KeyName *string
SecurityGroups []*string
}
//LoadConfig is func use ~/.aws/config
func LoadConfig(profile, region *string) *session.Session {
//use profile and region flag
if profile != nil && *profile == "" {
os.Setenv("AWS_PROFILE", *profile)
}
if *region != "" {
os.Setenv("AWS_REGION", *region)
}
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
return sess
}
func IsMaster(tags []*ec2.Tag) bool {
return containsTag(tags, TagMaster)
}
func IsSlave(tags []*ec2.Tag) bool {
return containsTag(tags, TagSlave)
}
func containsTag(tags []*ec2.Tag, value string) bool {
for _, v := range tags {
if *v.Value == value {
return true
}
}
return false
}