Skip to content
Snippets Groups Projects
Commit 603a1b06 authored by nimrod's avatar nimrod
Browse files

First commit, moved from private repo (version 0.2.0).

parents
No related branches found
No related tags found
No related merge requests found
*~
~*
*.swp
*.swo
*.pyc
.DS_Store
build/
dist/
*.egg-info/
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: cf550fcab3f12015f8676b8278b30e1a5bc10e70
hooks:
- id: check-added-large-files
- id: check-json
- id: check-xml
- id: check-yaml
- id: check-merge-conflict
- id: flake8
#!/usr/bin/env python
'''Prune older versions of an application in Elastic Beanstalk.'''
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from botocore import session
if __name__ == '__main__':
print('Pruning Elastic Beanstalk versions.')
session = session.get_session()
beanstalk_client = session.create_client('elasticbeanstalk')
response = beanstalk_client.describe_application_versions()
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError('Failed to describe application versions.')
versions = response['ApplicationVersions']
response = beanstalk_client.describe_environments()
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError('Failed to describe environments.')
active_versions = [env['VersionLabel'] for env in response['Environments']]
previous_versions = filter(
lambda x: (not x['VersionLabel'] in active_versions) and
x['Status'] == 'UNPROCESSED', versions)
old_versions = sorted(previous_versions,
key=lambda x: x.get('DateCreated'))[:-400]
for version in old_versions:
response = beanstalk_client.delete_application_version(
ApplicationName=version['ApplicationName'],
VersionLabel=version['VersionLabel'],
DeleteSourceBundle=True)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError(
'Failed to delete version {0}.'.format(
version['VersionLabel']))
print('Deleted version {0} of {1}.'.format(version['VersionLabel'],
version['ApplicationName']))
print('Deleted {0} versions.'.format(len(old_versions)))
setup.py 0 → 100644
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
name='eb-prune',
version='0.2.0',
description='Pruning of Elastic Beanstalk versions.',
long_description=open('README.rst', 'r').read(),
url='https://www.shore.co.il/cgit/eb-prune',
author='Nimrod Adar',
author_email='nimrod@shore.co.il',
license='MIT',
classifiers=[
'Development status :: 4 - Beta',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2.6',
'Intended Audience :: System Administrators',
'Topic :: Utilities',
],
keywords='beanstalk AWS',
packages=find_packages(),
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment