-
Notifications
You must be signed in to change notification settings - Fork 709
/
Copy pathautoscaler.py
104 lines (101 loc) · 3.71 KB
/
autoscaler.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
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Autoscaler/IGM/InstanceTemplate multiversion test."""
import compute_constants
import compute_resource_util
from compute_resource_util import ComputeResource
from compute_resource_util import Resources
def GenerateConfig(context):
"""Generate template config based on python objects."""
compute_resource_util.SetContext(context)
properties = context.properties
disk_name = context.env['deployment'] + '-' + 'disk'
image = 'projects/debian-cloud/global/images/debian-7-wheezy-v20140619'
default_network = 'global/networks/default'
assert ('region' in properties) ^ ('zone' in properties), (
'Need to specify exactly only one from zone or region')
template = ComputeResource(
'template', compute_constants.INSTANCETEMPLATES, {
'properties': {
'machineType':
'f1-micro',
'disks': [{
'deviceName': 'boot',
'boot': True,
'autoDelete': True,
'mode': 'READ_WRITE',
'initializeParams': {
'diskName': disk_name,
'sourceImage': image
},
'type': 'PERSISTENT'
}],
'networkInterfaces': [{
'network': default_network
}]
}
})
if 'region' in properties:
igm = ComputeResource(
'igm', compute_constants.REGIONINSTANCEGROUPMANAGERS, {
'region': properties['region'],
'size': properties['size'],
'baseInstanceName': context.env['deployment'] + '-instance',
'instanceTemplate': template.SelfLink(),
'targetSize': 1
})
ComputeResource(
'autoscaler', compute_constants.REGIONAUTOSCALERS, {
'region':
properties['region'],
'autoscalingPolicy': {
'coolDownPeriodSec': 60,
'cpuUtilization': {
'utilizationTarget': 0.8
},
'maxNumReplicas': 3,
'minNumReplicas': 1
},
'description':
'Autoscaler created for cloud config testing purposes',
'target':
igm.SelfLink()
})
else:
igm = ComputeResource(
'igm', compute_constants.INSTANCEGROUPMANAGERS, {
'zone': properties['zone'],
'size': properties['size'],
'baseInstanceName': context.env['deployment'] + '-instance',
'instanceTemplate': template.SelfLink(),
'targetSize': 1
})
ComputeResource(
'autoscaler', compute_constants.AUTOSCALERS, {
'zone':
properties['zone'],
'autoscalingPolicy': {
'coolDownPeriodSec': 60,
'cpuUtilization': {
'utilizationTarget': 0.8
},
'maxNumReplicas': 3,
'minNumReplicas': 1
},
'description':
'Autoscaler created for cloud config testing purposes',
'target':
igm.SelfLink()
})
return Resources()