forked from DSPN/google-compute-engine-dse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastax.py
191 lines (167 loc) · 6.62 KB
/
datastax.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import yaml
def GetZonesList(context):
zones = []
if context.properties['usEast1b']:
zones.append('us-east1-b')
if context.properties['usEast1c']:
zones.append('us-east1-c')
if context.properties['usEast1d']:
zones.append('us-east1-d')
if context.properties['usCentral1a']:
zones.append('us-central1-a')
if context.properties['usCentral1b']:
zones.append('us-central1-b')
if context.properties['usCentral1c']:
zones.append('us-central1-c')
if context.properties['usCentral1f']:
zones.append('us-central1-f')
if context.properties['europeWest1b']:
zones.append('europe-west1-b')
if context.properties['europeWest1c']:
zones.append('europe-west1-c')
if context.properties['europeWest1d']:
zones.append('europe-west1-d')
if context.properties['asiaEast1a']:
zones.append('asia-east1-a')
if context.properties['asiaEast1b']:
zones.append('asia-east1-b')
if context.properties['asiaEast1c']:
zones.append('asia-east1-c')
assert len(zones) > 0, 'No zones selected for DataStax Enterprise nodes'
return zones
def GenerateConfig(context):
config = {'resources': []}
# Set zones list based on zone booleans.
if ('zones' not in context.properties or len(context.properties['zones']) == 0):
context.properties['zones'] = GetZonesList(context)
# Set zone property to match ops center zone. Needed for calls to common.MakeGlobalComputeLink.
context.properties['zone'] = context.properties['opsCenterZone']
seed_nodes_dns_names = context.env['deployment'] + '-' + context.properties['zones'][0] + '-1-vm.c.' + context.env[
'project'] + '.internal'
opscenter_node_name = context.env['deployment'] + '-opscenter-vm'
opscenter_dns_name = opscenter_node_name + '.c.' + context.env['project'] + '.internal'
dse_node_script = '''
#!/usr/bin/env bash
mkdir /mnt
/usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" /dev/disk/by-id/google-${HOSTNAME}-data-disk /mnt
apt-get -y install unzip
wget https://github.com/DSPN/install-datastax-ubuntu/archive/master.zip
unzip master.zip
cd install-datastax-ubuntu-master/bin
cloud_type="gce"
seed_nodes_dns_names=''' + seed_nodes_dns_names + '''
zone=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/zone" | grep -o [[:alnum:]-]*$)
data_center_name=$zone
opscenter_dns_name=''' + opscenter_dns_name + '''
echo "Configuring nodes with the settings:"
echo cloud_type $cloud_type
echo seed_nodes_dns_names $seed_nodes_dns_names
echo data_center_name $data_center_name
echo opscenter_dns_name $opscenter_dns_name
./dse.sh $cloud_type $seed_nodes_dns_names $data_center_name $opscenter_dns_name
'''
zonal_clusters = {
'name': 'clusters-' + context.env['name'],
'type': 'regional_multi_vm.py',
'properties': {
'sourceImage': 'https://www.googleapis.com/compute/v1/projects/datastax-public/global/images/datastax-ubuntu-1404-trusty-v20160808',
'zones': context.properties['zones'],
'machineType': context.properties['machineType'],
'network': context.properties['network'],
'numberOfVMReplicas': context.properties['nodesPerZone'],
'disks': [
{
'deviceName': 'vm-data-disk',
'type': 'PERSISTENT',
'boot': 'false',
'autoDelete': 'true',
'initializeParams': {
'diskType': context.properties['dataDiskType'],
'diskSizeGb': context.properties['diskSize']
}
}
],
'bootDiskType': 'pd-standard',
'metadata': {
'items': [
{
'key': 'startup-script',
'value': dse_node_script
}
]
}
}
}
opscenter_script = '''
#!/usr/bin/env bash
apt-get -y install unzip
wget https://github.com/DSPN/install-datastax-ubuntu/archive/master.zip
unzip master.zip
cd install-datastax-ubuntu-master/bin
cloud_type="gce"
seed_nodes_dns_names=''' + seed_nodes_dns_names + '''
echo "Configuring nodes with the settings:"
echo cloud_type $cloud_type
echo seed_nodes_dns_names $seed_nodes_dns_names
./opscenter.sh $cloud_type $seed_nodes_dns_names
'''
opscenter_node_name = context.env['deployment'] + '-opscenter-vm'
opscenter_node = {
'name': opscenter_node_name,
'type': 'vm_instance.py',
'properties': {
'instanceName': opscenter_node_name,
'sourceImage': 'https://www.googleapis.com/compute/v1/projects/datastax-public/global/images/datastax-ubuntu-1404-trusty-v20160808',
'zone': context.properties['opsCenterZone'],
'machineType': context.properties['machineType'],
'network': context.properties['network'],
'bootDiskType': 'pd-standard',
'serviceAccounts': [{
'email': 'default',
'scopes': ['https://www.googleapis.com/auth/compute']
}],
'metadata': {
'items': [
{
'key': 'startup-script',
'value': opscenter_script
}
]
}
}
}
config['resources'].append(zonal_clusters)
config['resources'].append(opscenter_node)
first_enterprise_node_name = context.env['deployment'] + '-' + context.properties['zones'][0] + '-1-vm'
outputs = [
{
'name': 'project',
'value': context.env['project']
},
{
'name': 'opsCenterNodeName',
'value': opscenter_node_name
},
{
'name': 'firstEnterpriseNodeName',
'value': first_enterprise_node_name
},
{
'name': 'firstEnterpriseNodeSelfLink',
'value': '$(ref.' + first_enterprise_node_name + '.selfLink)'
},
{
'name': 'zoneList',
'value': ', '.join(context.properties['zones'])
},
{
'name': 'x-status-type',
'value': 'console'
},
{
'name': 'x-status-instance',
'value': opscenter_node_name
}
]
config['outputs'] = outputs
return yaml.dump(config)