-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-template.py
53 lines (48 loc) · 1.86 KB
/
vm-template.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
"""Creates the virtual machine with startup script."""
COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'
def GenerateConfig(context):
"""Creates the virtual machine."""
resources = [{
'name': context.env['name'],
'type': 'compute.v1.instance',
'properties': {
'zone': context.properties['zone'],
'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',
context.env['project'], '/zones/',
context.properties['zone'], '/machineTypes/',
context.properties['machineType']]),
'disks': [{
'deviceName': 'boot',
'type': 'PERSISTENT',
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': ''.join([COMPUTE_URL_BASE, 'projects/',
'centos-cloud/global/',
'images/family/centos-7'])
}
}],
'networkInterfaces': [{
'network': '$(ref.' + context.properties['network']
+ '.selfLink)',
'accessConfigs': [{
'name': 'External NAT',
'type': 'ONE_TO_ONE_NAT'
}]
}],
'metadata': {
'items': [{
'key': 'startup-script',
'value': context.imports['cloud-wp.sh'],
}, {
'key': 'cloud-sql-instances',
'value': ''.join(['$(ref.', 'mysql-', context.env['deployment'], '.connectionName)']),
}]
},
'serviceAccounts': [{
'email': 'default',
'scopes': ['https://www.googleapis.com/auth/cloud-platform']
}]
}
}]
return {'resources': resources}