@@ -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