-
Notifications
You must be signed in to change notification settings - Fork 9
/
couchbase-byol.py
106 lines (95 loc) · 3.21 KB
/
couchbase-byol.py
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
import naming
def GenerateConfig(context):
license = 'byol'
config={}
config['resources'] = []
config['outputs'] = []
couchbaseUsername='couchbase'
couchbasePassword = GeneratePassword()
config['outputs'].append({
'name': 'couchbaseUsername',
'value': couchbaseUsername
})
config['outputs'].append({
'name': 'couchbasePassword',
'value': couchbasePassword
})
clusters = GetClusters(context)
deployment = {
'name': 'deployment',
'type': 'deployment.py',
'properties': {
'serverVersion': context.properties['serverVersion'],
'syncGatewayVersion': context.properties['syncGatewayVersion'],
'couchbaseUsername': couchbaseUsername,
'couchbasePassword': couchbasePassword,
'license': license,
'clusters': clusters
}
}
config['resources'].append(deployment)
for cluster in clusters:
clusterName = cluster['cluster']
for group in cluster['groups']:
outputName = naming.ExternalIpOutputName(clusterName, group['group'])
config['outputs'].append({
'name': outputName,
'value': '$(ref.deployment.%s)' % outputName
})
return config
def GetClusters(context):
clusters = []
regions = GetRegionsList(context)
for region in regions:
cluster = {
'cluster': region,
'region': region,
'groups':
[
{
'group': 'server',
'diskSize': context.properties['serverDiskSize'],
'nodeCount': context.properties['serverNodeCount'],
'nodeType': context.properties['serverNodeType'],
'services': ['data','query','index','fts', 'eventing', 'analytics']
}
]
}
if context.properties['syncGatewayNodeCount']>0:
cluster['groups'].append({
'group': 'syncgateway',
'diskSize': context.properties['syncGatewayDiskSize'],
'nodeCount': context.properties['syncGatewayNodeCount'],
'nodeType': context.properties['syncGatewayNodeType'],
'services': ['syncGateway']
})
clusters.append(cluster)
return clusters
def GetRegionsList(context):
regions = []
availableRegions = [
'us-central1',
'us-west1',
'us-east1',
'us-east4',
'europe-west1',
'europe-west2',
'europe-west3',
'asia-southeast1',
'asia-east1',
'asia-northeast1',
'australia-southeast1'
]
for region in availableRegions:
if context.properties[region]:
regions.append(region)
return regions
def GeneratePassword():
import random
categories = ['ABCDEFGHJKLMNPQRSTUVWXYZ', 'abcdefghijkmnopqrstuvwxyz', '123456789', '*-+.']
password=[]
for category in categories:
password.insert(random.randint(0, len(password)), random.choice(category))
while len(password) < 8:
password.insert(random.randint(0, len(password)), random.choice(''.join(categories)))
return ''.join(password)