-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoscaling.yaml
225 lines (208 loc) · 6.95 KB
/
autoscaling.yaml
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
heat_template_version: 2013-05-23
description: Load balance an autoScaling group
parameters:
max_instances:
type: number
description: Maximum number of instances
default : 5
min_instances:
type: number
description: Minimum number of instances
default : 1
desired_capacity:
type: number
description: Desired initial number of resources
default : 1
OS_AUTH_URL:
type: string
description: OS authentication URL
default : NO OS_AUTH_URL
image_cirros:
type: string
description: Image used for servers
default: cirros-0.3.4-x86_64-disk
image_ubuntu:
type: string
description: Image used for servers
default: precise-server-cloudimg-amd64-disk1
key:
type: string
description: SSH key to connect to the servers
default: mykeypair
flavor:
type: string
description: flavor used by the web servers
default: m1.nano
control_flavor:
type: string
description: flavor used by the db server
default: m1.micro
network:
type: string
description: Network used by the server
subnet_id:
type: string
description: subnet on which the load balancer will be located
external_network_id:
type: string
description: UUID of a Neutron external network
resources:
controller:
type: OS::Nova::Server
properties:
name: ctrlsrv
flavor: {get_param: control_flavor}
image: {get_param: image_ubuntu}
key_name: {get_param: key}
networks: [{network: {get_param: network} }]
user_data_format: RAW
user_data:
str_replace:
template: |
#!/bin/sh
# install python requests
echo "127.0.0.1 localhost ctrlsrv" >> /etc/hosts
export LC_ALL=C
sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py
sudo pip install virtualenv
sudo pip install requests
sudo apt-get -y install siege
sudo apt-get -y install subversion
sudo svn export https://github.com/arabnejad/Fuzzy-Q-Learning/trunk/FQL /tmp/FQL
cat << EOF > /tmp/FQL/config_param
Neutron FloatingIP:
$lb_floating
OS authentication URL:
$OS_AUTH_URL
Webhook to scale up1 the group:
$scale_up1_url
Webhook to scale up2 the group:
$scale_up2_url
Webhook to scale down1 the group:
$scale_down1_url
Webhook to scale down2 the group:
$scale_down2_url
Maximum number of instances:
$max_instances
Minimum number of instances:
$min_instances
EOF
params:
$lb_floating: {get_attr: [lb_floating, floating_ip_address]}
$scale_up1_url: {get_attr: [scaleup1_policy, alarm_url]}
$scale_up2_url: {get_attr: [scaleup2_policy, alarm_url]}
$scale_down1_url: {get_attr: [scaledown1_policy, alarm_url]}
$scale_down2_url: {get_attr: [scaledown2_policy, alarm_url]}
$OS_AUTH_URL: {get_param: OS_AUTH_URL}
$max_instances: {get_param: max_instances}
$min_instances: {get_param: min_instances}
# define autoscale group with minimum and maximum number of VMs
asg:
type: OS::Heat::AutoScalingGroup
properties:
desired_capacity: {get_param: desired_capacity}
min_size: {get_param: min_instances}
max_size: {get_param: max_instances}
resource:
type: lb_server.yaml
properties:
flavor: {get_param: flavor}
image: {get_param: image_cirros}
key_name: {get_param: key}
network: {get_param: network}
pool_id: {get_resource: pool}
metadata: {"metering.stack": {get_param: "OS::stack_id"}}
user_data: |
#!/bin/sh
MYIP=$(ifconfig eth0|grep 'inet addr'|awk -F: '{print $2}'| awk '{print $1}')
echo "<html>" > /tmp/index.html
echo "name=$(hostname) cirros VM image IP=$MYIP" >> /tmp/index.html
echo "</html>" >> /tmp/index.html
while true
do
{
echo "HTTP/1.0 200 OK";
echo "Content-Length: $(wc -c /tmp/index.html | cut -d' ' -f1)";
echo;
cat /tmp/index.html;
} | sudo nc -l -p 80;
rnd=$(awk "BEGIN{print $(($(hexdump -n 2 -e '/2 "%u"' /dev/urandom)%100))/100}");
sleep $rnd;
done
scaleup1_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 10
scaling_adjustment: 1
scaleup2_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 10
scaling_adjustment: 2
scaledown1_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 10
scaling_adjustment: -1
scaledown2_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: asg}
cooldown: 10
scaling_adjustment: -2
monitor:
type: OS::Neutron::HealthMonitor
properties:
type: TCP
delay: 1
max_retries: 10
timeout: 1
pool:
type: OS::Neutron::Pool
properties:
protocol: HTTP
monitors: [{get_resource: monitor}]
subnet_id: {get_param: subnet_id}
lb_method: ROUND_ROBIN
vip:
protocol_port: 80
lb:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: {get_resource: pool}
lb_floating:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: {get_param: external_network_id}
port_id: {get_attr: [pool, vip, port_id]}
outputs:
scale_up1_url:
value: {get_attr: [scaleup1_policy, alarm_url]}
description: Webhook to scale up the group, curl -XPOST -i 'scale_up1_url'
scale_up2_url:
value: {get_attr: [scaleup2_policy, alarm_url]}
description: Webhook to scale up the group, curl -XPOST -i 'scale_up2_url'
scale_down1_url:
value: {get_attr: [scaledown1_policy, alarm_url]}
description: Webhook to scale down the group, curl -XPOST -i 'scale_down1_url'
scale_down2_url:
value: {get_attr: [scaledown2_policy, alarm_url]}
description: Webhook to scale down the group, curl -XPOST -i 'scale_down2_url'
lbserver:
value: {get_attr: [lb_floating, floating_ip_address]}
description: Front-end web server, curl -XGET http://lbserver/
OS_AUTH_URL:
value: {get_param: OS_AUTH_URL}
description: OS authentication URL
desired_capacity:
value: {get_param: desired_capacity}
description: Desired initial number of resources