def _launch_instance(self):
resource = self._connect()<EOL>instance_name = ipa_utils.generate_instance_name('<STR_LIT>')<EOL>kwargs = {<EOL>'<STR_LIT>': self.instance_type or EC2_DEFAULT_TYPE,<EOL>'<STR_LIT>': self.image_id,<EOL>'<STR_LIT>': <NUM_LIT:1>,<EOL>'<STR_LIT>': <NUM_LIT:1>,<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT:Name>',<EOL>'<STR_LIT>': instance_name<EOL>}<EOL>]<EOL>}<EOL>]<EOL>}<EOL>if self.zone:<EOL><INDENT>kwargs['<STR_LIT>'] = {'<STR_LIT>': self.zone}<EOL><DEDENT>if self.ssh_key_name:<EOL><INDENT>kwargs['<STR_LIT>'] = self.ssh_key_name<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = self._get_user_data()<EOL><DEDENT>if self.subnet_id:<EOL><INDENT>kwargs['<STR_LIT>'] = self.subnet_id<EOL><DEDENT>if self.security_group_id:<EOL><INDENT>kwargs['<STR_LIT>'] = [self.security_group_id]<EOL><DEDENT>try:<EOL><INDENT>instances = resource.create_instances(**kwargs)<EOL><DEDENT>except Exception as error:<EOL><INDENT>raise EC2CloudException(<EOL>'<STR_LIT>'.format(error)<EOL>)<EOL><DEDENT>self.running_instance_id = instances[<NUM_LIT:0>].instance_id<EOL>self.logger.debug('<STR_LIT>' % self.running_instance_id)<EOL>self._wait_on_instance('<STR_LIT>', self.timeout)<EOL>
Launch an instance of the given image.