-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstance_group.py
94 lines (88 loc) · 4.25 KB
/
instance_group.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
def generate_config(context):
sourceImage = 'projects/neo4j-aura-gcp/global/images/neo4j-enterprise-edition-v9-byol-v20240110'
properties = context.properties
prefix = context.env['deployment']
instance_template = {
'name': properties['instanceTemplateName'],
'type': 'compute.v1.instanceTemplate',
'properties': {
'properties': {
'machineType': context.properties['nodeType'],
'tags': {
'items': [prefix + '-external', prefix + '-internal'],
},
'networkInterfaces': [{
'network':
properties['networkRef'],
'subnetwork':
properties['subnetRef'],
'accessConfigs': [{
'name': 'External NAT',
'type': 'ONE_TO_ONE_NAT'
}]
}],
'disks': [{
'deviceName': 'boot',
'type': 'PERSISTENT',
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': sourceImage,
'diskType': context.properties['diskType'],
'diskSizeGb': context.properties['diskSize']
}
}],
'metadata': {'items': [{'key': 'startup-script', 'value': generate_startup_script(context)}]},
'serviceAccounts': [{
'email': 'default',
'scopes': [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/cloud.useraccounts.readonly',
'https://www.googleapis.com/auth/devstorage.read_only',
'https://www.googleapis.com/auth/logging.write',
'https://www.googleapis.com/auth/monitoring.write',
'https://www.googleapis.com/auth/cloudruntimeconfig',
]
}],
'labels': {
'goog-dm': context.env['deployment']
}
}
}
}
instance_group_manager = {
'name': properties['instanceGroupManagerName'],
'type': 'compute.v1.regionInstanceGroupManager',
'properties': {
'region': context.properties['region'],
'baseInstanceName': context.env['deployment'] + '-cluster' + '-instance',
'instanceTemplate': '$(ref.' + properties['instanceTemplateName'] + '.selfLink)',
'targetSize': context.properties['nodeCount']
}
}
# Standalone server
if context.properties['publicIp']:
instance_template['properties']['properties']['networkInterfaces'][0]['accessConfigs'][0]['natIP'] = context.properties['publicIp']
instance_group_manager['type'] = 'compute.v1.instanceGroupManager'
instance_group_manager['properties']['zone'] = context.properties['zone']
config = {'resources': [], 'outputs': []}
config['resources'].append(instance_template)
config['resources'].append(instance_group_manager)
config['outputs'].append({
'name': 'name',
'value': '$(ref.' + properties['instanceGroupManagerName'] + '.instanceGroup)'
})
return config
def generate_startup_script(context):
script = '#!/usr/bin/env bash\n\n'
script += 'deployment="' + context.env['deployment'] + '"\n'
script += 'adminPassword="' + context.properties['adminPassword'] + '"\n'
script += 'nodeCount="' + str(context.properties['nodeCount']) + '"\n'
script += 'installGraphDataScience="' + str(context.properties['installGraphDataScience']) + '"\n'
script += 'graphDataScienceLicenseKey="' + context.properties['graphDataScienceLicenseKey'] + '"\n'
script += 'installBloom="' + str(context.properties['installBloom']) + '"\n'
script += 'bloomLicenseKey="' + context.properties['bloomLicenseKey'] + '"\n'
script += 'region="' + context.properties['region'] + '"\n'
script += 'runTimeConfigName="' + context.properties['runTimeConfigName'] + '"\n'
script += context.imports['core-' + context.properties['graphDatabaseVersion'] + '.sh']
return script