Mercurial > repos > shellac > sam_consensus_v3
annotate env/bin/asadmin @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac | 
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
1 #!/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/bin/python3 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
2 # Copyright (c) 2011 Joel Barciauskas http://joel.barciausk.as/ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
3 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
4 # Permission is hereby granted, free of charge, to any person obtaining a | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
5 # copy of this software and associated documentation files (the | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
6 # "Software"), to deal in the Software without restriction, including | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
9 # persons to whom the Software is furnished to do so, subject to the fol- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
10 # lowing conditions: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
11 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
12 # The above copyright notice and this permission notice shall be included | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
13 # in all copies or substantial portions of the Software. | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
14 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
21 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
22 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
23 # Auto Scaling Groups Tool | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
24 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
25 VERSION="0.1" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
26 usage = """%prog [options] [command] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
27 Commands: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
28 list|ls List all Auto Scaling Groups | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
29 list-lc|ls-lc List all Launch Configurations | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
30 delete <name> Delete ASG <name> | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
31 delete-lc <name> Delete Launch Configuration <name> | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
32 get <name> Get details of ASG <name> | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
33 create <name> Create an ASG | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
34 create-lc <name> Create a Launch Configuration | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
35 update <name> <prop> <value> Update a property of an ASG | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
36 update-image <asg-name> <lc-name> Update image ID for ASG by creating a new LC | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
37 migrate-instances <name> Shut down current instances one by one and wait for ASG to start up a new instance with the current AMI (useful in conjunction with update-image) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
38 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
39 Examples: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
40 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
41 1) Create launch configuration | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
42 bin/asadmin create-lc my-lc-1 -i ami-1234abcd -t c1.xlarge -k my-key -s web-group -m | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
43 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
44 2) Create auto scaling group in us-east-1a and us-east-1c with a load balancer and min size of 2 and max size of 6 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
45 bin/asadmin create my-asg -z us-east-1a -z us-east-1c -l my-lc-1 -b my-lb -H ELB -p 180 -x 2 -X 6 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
46 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
47 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
48 def get_group(autoscale, name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
49 g = autoscale.get_all_groups(names=[name]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
50 if len(g) < 1: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
51 print "No auto scaling groups by the name of %s found" % name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
52 return sys.exit(1) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
53 return g[0] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
54 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
55 def get_lc(autoscale, name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
56 l = autoscale.get_all_launch_configurations(names=[name]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
57 if len(l) < 1: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
58 print "No launch configurations by the name of %s found" % name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
59 sys.exit(1) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
60 return l[0] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
61 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
62 def list(autoscale): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
63 """List all ASGs""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
64 print "%-20s %s" % ("Name", "LC Name") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
65 print "-"*80 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
66 groups = autoscale.get_all_groups() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
67 for g in groups: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
68 print "%-20s %s" % (g.name, g.launch_config_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
69 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
70 def list_lc(autoscale): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
71 """List all LCs""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
72 print "%-30s %-20s %s" % ("Name", "Image ID", "Instance Type") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
73 print "-"*80 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
74 for l in autoscale.get_all_launch_configurations(): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
75 print "%-30s %-20s %s" % (l.name, l.image_id, l.instance_type) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
76 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
77 def get(autoscale, name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
78 """Get details about ASG <name>""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
79 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
80 print "="*80 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
81 print "%-30s %s" % ('Name:', g.name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
82 print "%-30s %s" % ('Launch configuration:', g.launch_config_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
83 print "%-30s %s" % ('Minimum size:', g.min_size) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
84 print "%-30s %s" % ('Maximum size:', g.max_size) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
85 print "%-30s %s" % ('Desired capacity:', g.desired_capacity) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
86 print "%-30s %s" % ('Load balancers:', ','.join(g.load_balancers)) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
87 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
88 print | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
89 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
90 print "Instances" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
91 print "---------" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
92 print "%-20s %-20s %-20s %s" % ("ID", "Status", "Health", "AZ") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
93 for i in g.instances: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
94 print "%-20s %-20s %-20s %s" % \ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
95 (i.instance_id, i.lifecycle_state, i.health_status, i.availability_zone) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
96 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
97 print | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
98 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
99 def create(autoscale, name, zones, lc_name, load_balancers, hc_type, hc_period, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
100 min_size, max_size, cooldown, capacity): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
101 """Create an ASG named <name>""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
102 g = AutoScalingGroup(name=name, launch_config=lc_name, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
103 availability_zones=zones, load_balancers=load_balancers, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
104 default_cooldown=cooldown, health_check_type=hc_type, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
105 health_check_period=hc_period, desired_capacity=capacity, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
106 min_size=min_size, max_size=max_size) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
107 g = autoscale.create_auto_scaling_group(g) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
108 return list(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
109 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
110 def create_lc(autoscale, name, image_id, instance_type, key_name, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
111 security_groups, instance_monitoring): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
112 l = LaunchConfiguration(name=name, image_id=image_id, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
113 instance_type=instance_type,key_name=key_name, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
114 security_groups=security_groups, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
115 instance_monitoring=instance_monitoring) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
116 l = autoscale.create_launch_configuration(l) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
117 return list_lc(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
118 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
119 def update(autoscale, name, prop, value): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
120 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
121 setattr(g, prop, value) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
122 g.update() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
123 return get(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
124 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
125 def delete(autoscale, name, force_delete=False): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
126 """Delete this ASG""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
127 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
128 autoscale.delete_auto_scaling_group(g.name, force_delete) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
129 print "Auto scaling group %s deleted" % name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
130 return list(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
131 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
132 def delete_lc(autoscale, name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
133 """Delete this LC""" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
134 l = get_lc(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
135 autoscale.delete_launch_configuration(name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
136 print "Launch configuration %s deleted" % name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
137 return list_lc(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
138 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
139 def update_image(autoscale, name, lc_name, image_id, is_migrate_instances=False): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
140 """ Get the current launch config, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
141 Update its name and image id | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
142 Re-create it as a new launch config | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
143 Update the ASG with the new LC | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
144 Delete the old LC """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
145 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
146 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
147 l = get_lc(autoscale, g.launch_config_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
148 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
149 old_lc_name = l.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
150 l.name = lc_name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
151 l.image_id = image_id | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
152 autoscale.create_launch_configuration(l) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
153 g.launch_config_name = l.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
154 g.update() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
155 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
156 if(is_migrate_instances): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
157 migrate_instances(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
158 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
159 return get(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
160 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
161 def migrate_instances(autoscale, name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
162 """ Shut down instances of the old image type one by one | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
163 and let the ASG start up instances with the new image """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
164 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
165 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
166 old_instances = g.instances | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
167 ec2 = boto.connect_ec2() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
168 for old_instance in old_instances: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
169 print "Terminating instance " + old_instance.instance_id | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
170 ec2.terminate_instances([old_instance.instance_id]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
171 while True: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
172 g = get_group(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
173 new_instances = g.instances | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
174 for new_instance in new_instances: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
175 hasOldInstance = False | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
176 instancesReady = True | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
177 if(old_instance.instance_id == new_instance.instance_id): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
178 hasOldInstance = True | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
179 print "Waiting for old instance to shut down..." | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
180 break | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
181 elif(new_instance.lifecycle_state != 'InService'): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
182 instancesReady = False | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
183 print "Waiting for instances to be ready...." | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
184 break | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
185 if(not hasOldInstance and instancesReady): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
186 break | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
187 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
188 time.sleep(20) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
189 return get(autoscale, name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
190 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
191 if __name__ == "__main__": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
192 try: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
193 import readline | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
194 except ImportError: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
195 pass | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
196 import boto | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
197 import sys | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
198 import time | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
199 from optparse import OptionParser | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
200 from boto.mashups.iobject import IObject | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
201 from boto.ec2.autoscale import AutoScalingGroup | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
202 from boto.ec2.autoscale import LaunchConfiguration | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
203 parser = OptionParser(version=VERSION, usage=usage) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
204 """ Create launch config options """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
205 parser.add_option("-i", "--image-id", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
206 help="Image (AMI) ID", action="store", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
207 type="string", default=None, dest="image_id") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
208 parser.add_option("-t", "--instance-type", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
209 help="EC2 Instance Type (e.g., m1.large, c1.xlarge), default is m1.large", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
210 action="store", type="string", default="m1.large", dest="instance_type") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
211 parser.add_option("-k", "--key-name", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
212 help="EC2 Key Name", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
213 action="store", type="string", dest="key_name") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
214 parser.add_option("-s", "--security-group", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
215 help="EC2 Security Group", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
216 action="append", default=[], dest="security_groups") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
217 parser.add_option("-m", "--monitoring", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
218 help="Enable instance monitoring", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
219 action="store_true", default=False, dest="instance_monitoring") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
220 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
221 """ Create auto scaling group options """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
222 parser.add_option("-z", "--zone", help="Add availability zone", action="append", default=[], dest="zones") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
223 parser.add_option("-l", "--lc-name", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
224 help="Launch configuration name", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
225 action="store", default=None, type="string", dest="lc_name") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
226 parser.add_option("-b", "--load-balancer", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
227 help="Load balancer name", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
228 action="append", default=[], dest="load_balancers") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
229 parser.add_option("-H", "--health-check-type", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
230 help="Health check type (EC2 or ELB)", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
231 action="store", default="EC2", type="string", dest="hc_type") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
232 parser.add_option("-p", "--health-check-period", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
233 help="Health check period in seconds (default 300s)", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
234 action="store", default=300, type="int", dest="hc_period") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
235 parser.add_option("-X", "--max-size", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
236 help="Max size of ASG (default 10)", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
237 action="store", default=10, type="int", dest="max_size") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
238 parser.add_option("-x", "--min-size", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
239 help="Min size of ASG (default 2)", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
240 action="store", default=2, type="int", dest="min_size") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
241 parser.add_option("-c", "--cooldown", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
242 help="Cooldown time after a scaling activity in seconds (default 300s)", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
243 action="store", default=300, type="int", dest="cooldown") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
244 parser.add_option("-C", "--desired-capacity", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
245 help="Desired capacity of the ASG", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
246 action="store", default=None, type="int", dest="capacity") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
247 parser.add_option("-f", "--force", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
248 help="Force delete ASG", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
249 action="store_true", default=False, dest="force") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
250 parser.add_option("-y", "--migrate-instances", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
251 help="Automatically migrate instances to new image when running update-image", | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
252 action="store_true", default=False, dest="migrate_instances") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
253 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
254 (options, args) = parser.parse_args() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
255 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
256 if len(args) < 1: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
257 parser.print_help() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
258 sys.exit(1) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
259 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
260 autoscale = boto.connect_autoscale() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
261 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
262 print "%s" % (autoscale.region.endpoint) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
263 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
264 command = args[0].lower() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
265 if command in ("ls", "list"): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
266 list(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
267 elif command in ("ls-lc", "list-lc"): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
268 list_lc(autoscale) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
269 elif command == "get": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
270 get(autoscale, args[1]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
271 elif command == "create": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
272 create(autoscale, args[1], options.zones, options.lc_name, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
273 options.load_balancers, options.hc_type, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
274 options.hc_period, options.min_size, options.max_size, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
275 options.cooldown, options.capacity) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
276 elif command == "create-lc": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
277 create_lc(autoscale, args[1], options.image_id, options.instance_type, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
278 options.key_name, options.security_groups, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
279 options.instance_monitoring) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
280 elif command == "update": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
281 update(autoscale, args[1], args[2], args[3]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
282 elif command == "delete": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
283 delete(autoscale, args[1], options.force) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
284 elif command == "delete-lc": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
285 delete_lc(autoscale, args[1]) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
286 elif command == "update-image": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
287 update_image(autoscale, args[1], args[2], | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
288 options.image_id, options.migrate_instances) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
289 elif command == "migrate-instances": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
290 migrate_instances(autoscale, args[1]) | 
