Skip to content

Commit f099796

Browse files
author
Dario Berzano
committed
Merge branch 'feature-oldnewboto'
Fixes #8
2 parents 5e09079 + 7498a30 commit f099796

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

etc/init.d/elastiq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function stop() {
142142
local LastMsg
143143
while true ; do
144144
LastMsg=`query_status` || break
145-
query_status 2> /dev/null # for pid
145+
query_status > /dev/null 2>&1 # in this env for exporting pid
146146
kill -$Signal $Pid 2> /dev/null
147147
sleep 1
148148
kill -0 $Pid 2> /dev/null && Signal=9

pylib/elastiq/__init__.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ def ec2_running_instances(hostnames=None):
361361
object is a list of boto instances."""
362362

363363
try:
364-
res = ec2h.get_all_reservations()
364+
try:
365+
res = ec2h.get_all_reservations() # boto 2.34.1
366+
except AttributeError:
367+
logging.debug("Using old boto call for getting reservations")
368+
res = ec2h.get_all_instances() # boto 2.2.2
365369
except Exception, e:
366370
logging.error("Can't get list of EC2 instances (maybe wrong credentials?)")
367371
return None
@@ -615,11 +619,16 @@ def check_owned_instance(st, instance_id):
615619

616620
# Get information from EC2: we need the IP address
617621
try:
618-
inst_list = ec2h.get_only_instances( [ instance_id ] )
619-
if len(inst_list) == 1:
620-
inst = inst_list[0]
621-
else:
622-
raise Exception
622+
623+
try:
624+
inst_list = ec2h.get_only_instances( [ instance_id ] ) # boto 2.34.1
625+
except AttributeError:
626+
logging.debug("Using old boto workaround for getting one instance through reservations")
627+
res_list = ec2h.get_all_instances( [ instance_id ] ) # boto 2.2.2
628+
inst_list = res_list[0].instances
629+
630+
inst = inst_list[0]
631+
623632
except Exception as e:
624633
logging.error("Instance %s not found" % instance_id)
625634
return
@@ -806,7 +815,15 @@ def check_vm_errors(st):
806815

807816
# Get all instances in "error" state
808817
try:
809-
all_instances = ec2h.get_only_instances()
818+
819+
try:
820+
all_instances = ec2h.get_only_instances() # boto 2.34.1
821+
except AttributeError:
822+
logging.debug("Using old boto workaround for getting all instances through reservations")
823+
all_instances = []
824+
all_res = ec2h.get_all_instances()
825+
for r in all_res:
826+
all_instances.extend( r.instances ) # boto 2.2.2
810827

811828
# Clean up list from nonexisting instances
812829
new_owned_instances = []

0 commit comments

Comments
 (0)