This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
cloud.go
132 lines (110 loc) · 3.58 KB
/
cloud.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package cloud
import (
"github.com/hortonworks/cb-cli/cli/types"
"github.com/hortonworks/cb-cli/models_cloudbreak"
)
type CloudType string
const (
AWS = CloudType("AWS")
AZURE = CloudType("AZURE")
GCP = CloudType("GCP")
OPENSTACK = CloudType("OPENSTACK")
YARN = CloudType("YARN")
)
type NetworkMode int
const (
NEW_NETWORK_NEW_SUBNET NetworkMode = iota
EXISTING_NETWORK_NEW_SUBNET
EXISTING_NETWORK_EXISTING_SUBNET
LEGACY_NETWORK
NO_NETWORK
)
type CloudStorageType int
const (
WASB CloudStorageType = iota
ADLS
S3
GCS
NO_CLOUD_STORAGE
)
const (
REGION_FIELD = "region"
AVAILABILITY_ZONE_FIELD = "availabilityZone"
)
var currentCloud CloudType
func SetProviderType(ct CloudType) {
currentCloud = ct
}
var CloudProviders = make(map[CloudType]CloudProvider)
type CloudProvider interface {
GetName() *string
GetCredentialParameters(func(string) string, func(string) bool) (map[string]interface{}, error)
GetNetworkParamatersTemplate(NetworkMode) map[string]interface{}
GetInstanceGroupParamatersTemplate(node Node) map[string]interface{}
GetParamatersTemplate() map[string]interface{}
SkippedFields() map[string]bool
GenerateDefaultTemplate() *models_cloudbreak.TemplateV2Request
GenerateDefaultNetwork(networkParameters map[string]interface{}, mode NetworkMode) *models_cloudbreak.NetworkV2Request
GenerateNetworkRequestFromNetworkResponse(response *models_cloudbreak.NetworkResponse) *models_cloudbreak.NetworkV2Request
GenerateDefaultSecurityGroup(node Node) *models_cloudbreak.SecurityGroupV2Request
}
func GetProvider() CloudProvider {
return CloudProviders[currentCloud]
}
type Node struct {
Name string
GroupType string
Count int32
}
type DefaultCloudProvider struct {
}
func (p *DefaultCloudProvider) SkippedFields() map[string]bool {
return make(map[string]bool)
}
func (p *DefaultCloudProvider) GetCredentialParameters(func(string) string, func(string) bool) (map[string]interface{}, error) {
return make(map[string]interface{}), nil
}
func (p *DefaultCloudProvider) GenerateDefaultTemplate() *models_cloudbreak.TemplateV2Request {
return &models_cloudbreak.TemplateV2Request{
InstanceType: "____",
VolumeType: "____",
VolumeCount: 1,
VolumeSize: 10,
}
}
func (p *DefaultCloudProvider) GenerateDefaultNetwork(networkParameters map[string]interface{}, mode NetworkMode) *models_cloudbreak.NetworkV2Request {
network := &models_cloudbreak.NetworkV2Request{
Parameters: networkParameters,
}
if mode != EXISTING_NETWORK_EXISTING_SUBNET && mode != LEGACY_NETWORK {
network.SubnetCIDR = "10.0.0.0/16"
}
return network
}
func (p *DefaultCloudProvider) GenerateDefaultSecurityGroup(node Node) *models_cloudbreak.SecurityGroupV2Request {
return &models_cloudbreak.SecurityGroupV2Request{
SecurityRules: getDefaultSecurityRules(node),
}
}
func (p *DefaultCloudProvider) GenerateNetworkRequestFromNetworkResponse(response *models_cloudbreak.NetworkResponse) *models_cloudbreak.NetworkV2Request {
return &models_cloudbreak.NetworkV2Request{
Parameters: response.Parameters,
}
}
func getDefaultSecurityRules(node Node) []*models_cloudbreak.SecurityRuleRequest {
ruleGen := func(port string) *models_cloudbreak.SecurityRuleRequest {
return &models_cloudbreak.SecurityRuleRequest{
Subnet: &(&types.S{S: "0.0.0.0/0"}).S,
Protocol: &(&types.S{S: "tcp"}).S,
Ports: &port,
}
}
rules := []*models_cloudbreak.SecurityRuleRequest{
ruleGen("22"),
}
if node.GroupType == models_cloudbreak.InstanceGroupResponseTypeGATEWAY {
rules = append(rules, ruleGen("443"))
rules = append(rules, ruleGen("9443"))
}
return rules
}