/
spec.go
83 lines (77 loc) · 2.77 KB
/
spec.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
82
83
package platform
import (
"strings"
"github.com/otiai10/hotsub/params"
"github.com/otiai10/dkmachine"
"github.com/otiai10/hotsub/core"
)
// DefineMachineSpec is a factory layer to connect cli.Context to CreateOptions.
func DefineMachineSpec(ctx params.Context) (*dkmachine.CreateOptions, error) {
opt := &dkmachine.CreateOptions{
// AWS
AmazonEC2Region: ctx.String("aws-region"),
AmazonEC2VpcID: ctx.String("aws-vpc-id"),
AmazonEC2SubnetID: ctx.String("aws-subnet-id"),
AmazonEC2RootSize: ctx.Int("disk-size"),
AmazonEC2InstanceType: ctx.String("aws-ec2-instance-type"),
AmazonEC2IAMInstanceProfile: DefaultAWSInstanceProfileNameForCompute,
AmazonEC2SecurityGroup: DefaultAWSSecurityGroupName,
// GCP
GoogleProject: ctx.String("google-project"),
GoogleZone: ctx.String("google-zone"),
GoogleDiskSize: ctx.Int("disk-size"),
GoogleTags: []string{DefaultGoogleInstanceTag},
GoogleScopes: strings.Join([]string{
"https://www.googleapis.com/auth/devstorage.read_write",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
}, ","),
}
switch Provider(ctx.String("provider")) {
case AWS:
opt.Driver = string(AmazonEC2)
case GCP:
opt.Driver = string(Google)
case VBOX:
opt.Driver = string(Vbox)
case HYPERV:
opt.Driver = string(Hyperv)
default:
opt.Driver = string(AmazonEC2)
}
return opt, nil
}
// DefineSharedDataInstanceSpec ...
// It defines ALL the specifications for docker-machine,
// though it's a bit verbose ;)
func DefineSharedDataInstanceSpec(shared core.Inputs, ctx params.Context) (*dkmachine.CreateOptions, error) {
opt := &dkmachine.CreateOptions{
Name: "Shared-Data-Instance",
AmazonEC2VpcID: ctx.String("aws-vpc-id"),
AmazonEC2SubnetID: ctx.String("aws-subnet-id"),
AmazonEC2Region: ctx.String("aws-region"),
AmazonEC2IAMInstanceProfile: DefaultAWSInstanceProfileNameForCompute,
AmazonEC2SecurityGroup: DefaultAWSSecurityGroupName,
AmazonEC2InstanceType: ctx.String("aws-shared-instance-type"),
AmazonEC2RootSize: ctx.Int("shareddata-disksize"),
// GCP
GoogleProject: ctx.String("google-project"),
GoogleZone: ctx.String("google-zone"),
GoogleDiskSize: ctx.Int("shareddata-disksize"),
GoogleTags: []string{DefaultGoogleInstanceTag},
GoogleScopes: strings.Join([]string{
"https://www.googleapis.com/auth/devstorage.read_write",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
}, ","),
}
switch Provider(ctx.String("provider")) {
case AWS:
opt.Driver = string(AmazonEC2)
case GCP:
opt.Driver = string(Google)
default:
opt.Driver = string(AmazonEC2)
}
return opt, nil
}