def _handle_tail_logs(instance_id_list): data = [] for instance_id, url in iteritems(instance_id_list): data.append('============= ' + str(instance_id) + ' ==============') log_result = utils.get_data_from_url(url) data.append(utils.decode_bytes(log_result)) io.echo_with_pager(os.linesep.join(data))
def cli_update_exists(current_version): try: data = utils.get_data_from_url( 'https://pypi.python.org/pypi/awsebcli/json', timeout=5) data = json.loads(data) latest = data['info']['version'] return latest != current_version except: return False
def cli_update_exists(current_version): try: data = utils.get_data_from_url( 'https://pypi.python.org/pypi/awsebcli/json', timeout=5) data = json.loads(data) latest = data['info']['version'] return latest != current_version except: # Ignore all exceptions. We want to fail silently. return False
def download_source_bundle(app_name, env_name): env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name) if env.version_label and env.version_label != 'Sample Application': app_version = elasticbeanstalk.get_application_versions( app_name, version_labels=[env.version_label])['ApplicationVersions'][0] source_bundle = app_version['SourceBundle'] bucket_name = source_bundle['S3Bucket'] key_name = source_bundle['S3Key'] io.echo('Downloading application version...') data = s3.get_object(bucket_name, key_name) filename = get_filename(key_name) else: # sample app template = cloudformation.get_template('awseb-' + env.id + '-stack') try: url = template['TemplateBody']['Parameters']['AppSource'][ 'Default'] except KeyError: raise NotFoundError('Can not find app source for environment') utils.get_data_from_url(url) io.echo('Downloading application version...') data = utils.get_data_from_url(url, timeout=30) filename = 'sample.zip' fileoperations.make_eb_dir('downloads/') location = fileoperations.get_eb_file_full_location('downloads/' + filename) fileoperations.write_to_data_file(location, data) io.echo('Application version downloaded to:', location) cwd = os.getcwd() try: fileoperations._traverse_to_project_root() if heuristics.directory_is_empty(): # If we dont have any project code, unzip as current project io.echo('Unzipping application version as project files.') fileoperations.unzip_folder(location, os.getcwd()) io.echo('Done.') finally: os.chdir(cwd)
def download_application_version(url, zip_file_location): """ Method downloads the application version from the URL, 'url', and writes them at the location specified by `zip_file_location` :param url: the URL of the application version. :param zip_file_location: path on the user's system to write the application version ZIP file to. :return: None """ data = utils.get_data_from_url(url, timeout=30) fileoperations.write_to_data_file(zip_file_location, data)
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))