File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66from kvirt .common import pprint , error , warning , get_ssh_pub_key
77from kvirt .defaults import IMAGES , METADATA_FIELDS
88import boto3
9+ from botocore .exceptions import ClientError , WaiterError
910import os
1011import sys
1112from string import ascii_lowercase
@@ -455,8 +456,17 @@ def start(self, name):
455456 except :
456457 return {'result' : 'failure' , 'reason' : f"VM { name } not found" }
457458 instanceid = vm ['InstanceId' ]
458- conn .start_instances (InstanceIds = [instanceid ])
459- return {'result' : 'success' }
459+ try :
460+ conn .start_instances (InstanceIds = [instanceid ])
461+ except ClientError as e :
462+ if e .response ['Error' ]['Code' ] != 'InsufficientInstanceCapacity' :
463+ return {'result' : 'failure' , 'reason' : str (e )}
464+ waiter = conn .get_waiter ('instance_running' )
465+ try :
466+ waiter .wait (InstanceIds = [instanceid ], WaiterConfig = {'Delay' : 5 , 'MaxAttempts' : 24 })
467+ return {'result' : 'success' }
468+ except WaiterError :
469+ return {'result' : 'failure' , 'reason' : 'Instance did not reach running state' }
460470
461471 def stop (self , name , soft = False ):
462472 conn = self .conn
You can’t perform that action at this time.
0 commit comments