Loading LICENSE.txt 0 → 100644 +21 −0 Original line number Diff line number Diff line The MIT License (MIT) Copyright (c) [year] [fullname] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. MANIFEST.in +2 −1 Original line number Diff line number Diff line recursive-include eb-prune *.py exclude .pre-commit-config.yaml include README.rst include *.rst include *.txt include VERSION README.rst +40 −7 Original line number Diff line number Diff line eb-prune ######## Must specify AWS_DEFAULT_REGION environment variable. A CLI tool to prune old versions of Elastic Beanstalk. TODO ---- Installation ------------ - License. - Changelog. - README, - Specify number of versions to keep, dry-run option. .. code:: shell pip install eb-prune Usage ----- To keep the last 100 versions available, simply run :code:`eb-prune 100`. The tool relies on the usual AWS CLI configuration as described `here <http://docs.aws.amazon.com/cli/latest/topic/config-vars.html>`_, specifically on access key id, secret access key and region. .. code:: shell $ eb-prune --help usage: eb-prune [-h] [-d] versions_to_keep positional arguments: versions_to_keep The number of versions to keep. optional arguments: -h, --help show this help message and exit -d, --dry-run Dry run, do not delete versions. License ------- This software is licnesed under the MIT licese (see the :code:`LICENSE.txt` file). Author ------ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/. VERSION +1 −1 Original line number Diff line number Diff line 0.2.1 No newline at end of file 0.3.0 No newline at end of file eb_prune/__init__.py +19 −3 Original line number Diff line number Diff line Loading @@ -2,26 +2,30 @@ '''Prune older versions of an application in Elastic Beanstalk.''' from __future__ import (absolute_import, division, print_function, unicode_literals) from argparse import ArgumentParser from botocore import session def main(): versions_to_keep = 400 dry_run = False def prune(versions_to_keep, dry_run): if dry_run: print('DRY RUN! NOTHING WILL BE REMOVED.') print('Pruning Elastic Beanstalk versions.') aws_session = session.get_session() beanstalk_client = aws_session.create_client('elasticbeanstalk') response = beanstalk_client.describe_application_versions() if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError('Failed to describe application versions.') # Get all EB versions. versions = response['ApplicationVersions'] response = beanstalk_client.describe_environments() if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError('Failed to describe environments.') # Remove the currently in-use versions from the list. 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) # Remove the newest versions from the list. old_versions = sorted(previous_versions, key=lambda x: x.get('DateCreated'))[:-versions_to_keep] Loading @@ -40,5 +44,17 @@ def main(): print('Deleted {0} versions.'.format(len(old_versions))) def main(): parser = ArgumentParser() parser.add_argument('versions_to_keep', help='The number of versions to keep.', type=int) parser.add_argument('-d', '--dry-run', help='Dry run, do not delete versions.', action='store_true') args = parser.parse_args() prune(args.versions_to_keep, args.dry_run) if __name__ == '__main__': main() Loading
LICENSE.txt 0 → 100644 +21 −0 Original line number Diff line number Diff line The MIT License (MIT) Copyright (c) [year] [fullname] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MANIFEST.in +2 −1 Original line number Diff line number Diff line recursive-include eb-prune *.py exclude .pre-commit-config.yaml include README.rst include *.rst include *.txt include VERSION
README.rst +40 −7 Original line number Diff line number Diff line eb-prune ######## Must specify AWS_DEFAULT_REGION environment variable. A CLI tool to prune old versions of Elastic Beanstalk. TODO ---- Installation ------------ - License. - Changelog. - README, - Specify number of versions to keep, dry-run option. .. code:: shell pip install eb-prune Usage ----- To keep the last 100 versions available, simply run :code:`eb-prune 100`. The tool relies on the usual AWS CLI configuration as described `here <http://docs.aws.amazon.com/cli/latest/topic/config-vars.html>`_, specifically on access key id, secret access key and region. .. code:: shell $ eb-prune --help usage: eb-prune [-h] [-d] versions_to_keep positional arguments: versions_to_keep The number of versions to keep. optional arguments: -h, --help show this help message and exit -d, --dry-run Dry run, do not delete versions. License ------- This software is licnesed under the MIT licese (see the :code:`LICENSE.txt` file). Author ------ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/.
VERSION +1 −1 Original line number Diff line number Diff line 0.2.1 No newline at end of file 0.3.0 No newline at end of file
eb_prune/__init__.py +19 −3 Original line number Diff line number Diff line Loading @@ -2,26 +2,30 @@ '''Prune older versions of an application in Elastic Beanstalk.''' from __future__ import (absolute_import, division, print_function, unicode_literals) from argparse import ArgumentParser from botocore import session def main(): versions_to_keep = 400 dry_run = False def prune(versions_to_keep, dry_run): if dry_run: print('DRY RUN! NOTHING WILL BE REMOVED.') print('Pruning Elastic Beanstalk versions.') aws_session = session.get_session() beanstalk_client = aws_session.create_client('elasticbeanstalk') response = beanstalk_client.describe_application_versions() if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError('Failed to describe application versions.') # Get all EB versions. versions = response['ApplicationVersions'] response = beanstalk_client.describe_environments() if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError('Failed to describe environments.') # Remove the currently in-use versions from the list. 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) # Remove the newest versions from the list. old_versions = sorted(previous_versions, key=lambda x: x.get('DateCreated'))[:-versions_to_keep] Loading @@ -40,5 +44,17 @@ def main(): print('Deleted {0} versions.'.format(len(old_versions))) def main(): parser = ArgumentParser() parser.add_argument('versions_to_keep', help='The number of versions to keep.', type=int) parser.add_argument('-d', '--dry-run', help='Dry run, do not delete versions.', action='store_true') args = parser.parse_args() prune(args.versions_to_keep, args.dry_run) if __name__ == '__main__': main()