def _download_logs_for_all_instances(instance_id_list, logs_location): for instance_id, url in iteritems(instance_id_list): zip_location = utils.save_file_from_url(url, logs_location, instance_id + '.zip') instance_folder = os.path.join(logs_location, instance_id) fileoperations.unzip_folder(zip_location, instance_folder) fileoperations.delete_file(zip_location)
def _download_logs_for_all_instances(instance_id_list, logs_location): for instance_id, url in iteritems(instance_id_list): zip_location = utils.save_file_from_url( url, logs_location, instance_id + '.zip' ) instance_folder = os.path.join(logs_location, instance_id) fileoperations.unzip_folder(zip_location, instance_folder) fileoperations.delete_file(zip_location)
def get_logs(env_name, info_type, do_zip=False, instance_id=None): # Get logs result = elasticbeanstalk.retrieve_environment_info(env_name, info_type) """ Results are ordered with latest last, we just want the latest """ log_list = {} for log in result['EnvironmentInfo']: i_id = log['Ec2InstanceId'] url = log['Message'] log_list[i_id] = url if instance_id: try: log_list = {instance_id: log_list[instance_id]} except KeyError: raise NotFoundError(strings['beanstalk-logs.badinstance'].replace( '{instance_id}', instance_id)) if info_type == 'bundle': # save file, unzip, place in logs directory logs_folder_name = datetime.now().strftime("%y%m%d_%H%M%S") logs_location = fileoperations.get_logs_location(logs_folder_name) #get logs for each instance for i_id, url in iteritems(log_list): zip_location = utils.save_file_from_url(url, logs_location, i_id + '.zip') instance_folder = os.path.join(logs_location, i_id) fileoperations.unzip_folder(zip_location, instance_folder) fileoperations.delete_file(zip_location) fileoperations.set_user_only_permissions(logs_location) if do_zip: fileoperations.zip_up_folder(logs_location, logs_location + '.zip') fileoperations.delete_directory(logs_location) logs_location += '.zip' fileoperations.set_user_only_permissions(logs_location) io.echo(strings['logs.location'].replace('{location}', logs_location)) else: io.echo(strings['logs.location'].replace('{location}', logs_location)) # create symlink to logs/latest latest_location = fileoperations.get_logs_location('latest') try: os.unlink(latest_location) except OSError: # doesn't exist. Ignore pass try: os.symlink(logs_location, latest_location) io.echo('Updated symlink at', latest_location) except OSError: #Oh well.. we tried. ## Probably on windows, or logs/latest is not a symlink pass else: # print logs data = [] for i_id, url in iteritems(log_list): data.append('============= ' + str(i_id) + ' ==============') log_result = utils.get_data_from_url(url) data.append(utils.decode_bytes(log_result)) io.echo_with_pager(os.linesep.join(data))