in footmark/ecs/connection.py [0:0]
def stop_instances(self, **kwargs):
"""
Stop the instances specified
:type instance_ids: list
:param instance_ids: A list of strings of the Instance IDs to stop
:type force: bool
:param force: Forces the instance to stop
:rtype: list
:return: A list of the instances stopped
"""
instance_ids = kwargs["instance_ids"]
kwargs = self.format_request_kwargs(**kwargs)
if instance_ids:
if isinstance(instance_ids, six.string_types):
instance_ids = [instance_ids]
for instance_id in instance_ids:
kwargs["instance_id"]= instance_id
try:
self.get_status_new(self.build_request_params(kwargs))
except ServerException as e:
if e.error_code == "IncorrectInstanceStatus":
target = self.describe_instances(instance_ids=[instance_id])
if target and str(target[0].status).lower() == "stopped":
continue
raise e
while instance_ids:
for inst in self.describe_instances(instance_ids=instance_ids, page_size=100):
if str(inst.status).lower() == "stopped":
instance_ids.remove(inst.id)
return True
return False