Skip to content

Commit b9808b7

Browse files
author
Shayne Clausson
committed
initial commit
0 parents  commit b9808b7

File tree

1,671 files changed

+627980
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,671 files changed

+627980
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ECS Instance Draining on Scale In
2+
===================================
3+
4+
Heavily inspired by this AWS [blog post](https://aws.amazon.com/blogs/compute/how-to-automate-container-instance-draining-in-amazon-ecs/), this module deploys resources and code to support ECS Instance Draning to ensure that running tasks are not obliterated by ASG scale-in events.
5+
6+
![alt tag](https://s3.amazonaws.com/chrisb/Architecture.png)
7+
8+
Further details about [AutoScaling Lifecyle Hooks](http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html) is available.
9+
10+
Module Input Variables
11+
----------------------
12+
13+
- `autoscaling_group_name` - The Name of the AutoScaling Group used by the ECS Cluster.
14+
- `hook_heartbeat_timeout` - Amount of time, in seconds, the lifecycle hook should wait before giving up and moving onto the default result. Defaults to 900 (15 mins).
15+
- `hook_default_result` - Can be one of either ABANDON or CONTINUE. ABANDON stops any remaining actions, such as other lifecycle hooks, while CONTINUE allows any other lifecycle hooks to complete. Default is ABANDON
16+
- `enabled` - boolean expression. If false, the Lifecycle Hook is removed from the AutoScaling Group. Defaults to `true`.
17+
18+
Usage
19+
-----
20+
21+
```js
22+
resource "aws_autoscaling_group" "ecs" {
23+
#properties omitted
24+
}
25+
26+
module "ecs_instance_draining_on_scale_in" {
27+
source = "../../../modules/ecs-instance-draining-on-scale-in"
28+
29+
autoscaling_group_name = "${aws_autoscaling_group.ecs.asg_name}"
30+
hook_heartbeat_timeout = 1800
31+
hook_default_result = "ABANDON"
32+
}
33+
```
34+
35+
Author
36+
------
37+
Created and maintained by [Shayne Clausson](https://github.com/sclausson)

index/_markerlib/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
try:
2+
import ast
3+
from _markerlib.markers import default_environment, compile, interpret
4+
except ImportError:
5+
if 'ast' in globals():
6+
raise
7+
def default_environment():
8+
return {}
9+
def compile(marker):
10+
def marker_fn(environment=None, override=None):
11+
# 'empty markers are True' heuristic won't install extra deps.
12+
return not marker.strip()
13+
marker_fn.__doc__ = marker
14+
return marker_fn
15+
def interpret(marker, environment=None, override=None):
16+
return compile(marker)()

index/_markerlib/__init__.pyc

1.33 KB
Binary file not shown.

index/_markerlib/markers.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# -*- coding: utf-8 -*-
2+
"""Interpret PEP 345 environment markers.
3+
4+
EXPR [in|==|!=|not in] EXPR [or|and] ...
5+
6+
where EXPR belongs to any of those:
7+
8+
python_version = '%s.%s' % (sys.version_info[0], sys.version_info[1])
9+
python_full_version = sys.version.split()[0]
10+
os.name = os.name
11+
sys.platform = sys.platform
12+
platform.version = platform.version()
13+
platform.machine = platform.machine()
14+
platform.python_implementation = platform.python_implementation()
15+
a free string, like '2.6', or 'win32'
16+
"""
17+
18+
__all__ = ['default_environment', 'compile', 'interpret']
19+
20+
import ast
21+
import os
22+
import platform
23+
import sys
24+
import weakref
25+
26+
_builtin_compile = compile
27+
28+
try:
29+
from platform import python_implementation
30+
except ImportError:
31+
if os.name == "java":
32+
# Jython 2.5 has ast module, but not platform.python_implementation() function.
33+
def python_implementation():
34+
return "Jython"
35+
else:
36+
raise
37+
38+
39+
# restricted set of variables
40+
_VARS = {'sys.platform': sys.platform,
41+
'python_version': '%s.%s' % sys.version_info[:2],
42+
# FIXME parsing sys.platform is not reliable, but there is no other
43+
# way to get e.g. 2.7.2+, and the PEP is defined with sys.version
44+
'python_full_version': sys.version.split(' ', 1)[0],
45+
'os.name': os.name,
46+
'platform.version': platform.version(),
47+
'platform.machine': platform.machine(),
48+
'platform.python_implementation': python_implementation(),
49+
'extra': None # wheel extension
50+
}
51+
52+
for var in list(_VARS.keys()):
53+
if '.' in var:
54+
_VARS[var.replace('.', '_')] = _VARS[var]
55+
56+
def default_environment():
57+
"""Return copy of default PEP 385 globals dictionary."""
58+
return dict(_VARS)
59+
60+
class ASTWhitelist(ast.NodeTransformer):
61+
def __init__(self, statement):
62+
self.statement = statement # for error messages
63+
64+
ALLOWED = (ast.Compare, ast.BoolOp, ast.Attribute, ast.Name, ast.Load, ast.Str)
65+
# Bool operations
66+
ALLOWED += (ast.And, ast.Or)
67+
# Comparison operations
68+
ALLOWED += (ast.Eq, ast.Gt, ast.GtE, ast.In, ast.Is, ast.IsNot, ast.Lt, ast.LtE, ast.NotEq, ast.NotIn)
69+
70+
def visit(self, node):
71+
"""Ensure statement only contains allowed nodes."""
72+
if not isinstance(node, self.ALLOWED):
73+
raise SyntaxError('Not allowed in environment markers.\n%s\n%s' %
74+
(self.statement,
75+
(' ' * node.col_offset) + '^'))
76+
return ast.NodeTransformer.visit(self, node)
77+
78+
def visit_Attribute(self, node):
79+
"""Flatten one level of attribute access."""
80+
new_node = ast.Name("%s.%s" % (node.value.id, node.attr), node.ctx)
81+
return ast.copy_location(new_node, node)
82+
83+
def parse_marker(marker):
84+
tree = ast.parse(marker, mode='eval')
85+
new_tree = ASTWhitelist(marker).generic_visit(tree)
86+
return new_tree
87+
88+
def compile_marker(parsed_marker):
89+
return _builtin_compile(parsed_marker, '<environment marker>', 'eval',
90+
dont_inherit=True)
91+
92+
_cache = weakref.WeakValueDictionary()
93+
94+
def compile(marker):
95+
"""Return compiled marker as a function accepting an environment dict."""
96+
try:
97+
return _cache[marker]
98+
except KeyError:
99+
pass
100+
if not marker.strip():
101+
def marker_fn(environment=None, override=None):
102+
""""""
103+
return True
104+
else:
105+
compiled_marker = compile_marker(parse_marker(marker))
106+
def marker_fn(environment=None, override=None):
107+
"""override updates environment"""
108+
if override is None:
109+
override = {}
110+
if environment is None:
111+
environment = default_environment()
112+
environment.update(override)
113+
return eval(compiled_marker, environment)
114+
marker_fn.__doc__ = marker
115+
_cache[marker] = marker_fn
116+
return _cache[marker]
117+
118+
def interpret(marker, environment=None):
119+
return compile(marker)(environment)

index/_markerlib/markers.pyc

5.6 KB
Binary file not shown.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
===============================
2+
Boto 3 - The AWS SDK for Python
3+
===============================
4+
5+
|Build Status| |Docs| |Version|
6+
7+
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for
8+
Python, which allows Python developers to write software that makes use
9+
of services like Amazon S3 and Amazon EC2. You can find the latest, most
10+
up to date, documentation at `Read the Docs`_, including a list of
11+
services that are supported. To see only those features which have been
12+
released, check out the `stable docs`_.
13+
14+
15+
.. _boto: https://docs.pythonboto.org/
16+
.. _`stable docs`: https://boto3.readthedocs.io/en/stable/
17+
.. _`Read the Docs`: https://boto3.readthedocs.io/en/latest/
18+
.. |Build Status| image:: http://img.shields.io/travis/boto/boto3/develop.svg?style=flat
19+
:target: https://travis-ci.org/boto/boto3
20+
:alt: Build Status
21+
.. |Docs| image:: https://readthedocs.org/projects/boto3/badge/?version=latest&style=flat
22+
:target: https://boto3.readthedocs.io/en/latest/
23+
:alt: Read the docs
24+
.. |Downloads| image:: http://img.shields.io/pypi/dm/boto3.svg?style=flat
25+
:target: https://pypi.python.org/pypi/boto3/
26+
:alt: Downloads
27+
.. |Version| image:: http://img.shields.io/pypi/v/boto3.svg?style=flat
28+
:target: https://pypi.python.org/pypi/boto3/
29+
:alt: Version
30+
.. |License| image:: http://img.shields.io/pypi/l/boto3.svg?style=flat
31+
:target: https://github.com/boto/boto3/blob/develop/LICENSE
32+
:alt: License
33+
34+
Quick Start
35+
-----------
36+
First, install the library and set a default region:
37+
38+
.. code-block:: sh
39+
40+
$ pip install boto3
41+
42+
Next, set up credentials (in e.g. ``~/.aws/credentials``):
43+
44+
.. code-block:: ini
45+
46+
[default]
47+
aws_access_key_id = YOUR_KEY
48+
aws_secret_access_key = YOUR_SECRET
49+
50+
Then, set up a default region (in e.g. ``~/.aws/config``):
51+
52+
.. code-block:: ini
53+
54+
[default]
55+
region=us-east-1
56+
57+
Then, from a Python interpreter:
58+
59+
.. code-block:: python
60+
61+
>>> import boto3
62+
>>> s3 = boto3.resource('s3')
63+
>>> for bucket in s3.buckets.all():
64+
print(bucket.name)
65+
66+
Development
67+
-----------
68+
69+
Getting Started
70+
~~~~~~~~~~~~~~~
71+
Assuming that you have Python and ``virtualenv`` installed, set up your
72+
environment and install the required dependencies like this instead of
73+
the ``pip install boto3`` defined above:
74+
75+
.. code-block:: sh
76+
77+
$ git clone https://github.com/boto/boto3.git
78+
$ cd boto3
79+
$ virtualenv venv
80+
...
81+
$ . venv/bin/activate
82+
$ pip install -r requirements.txt
83+
$ pip install -e .
84+
85+
Running Tests
86+
~~~~~~~~~~~~~
87+
You can run tests in all supported Python versions using ``tox``. By default,
88+
it will run all of the unit tests, but you can also specify your own
89+
``nosetests`` options. Note that this requires that you have all supported
90+
versions of Python installed, otherwise you must pass ``-e`` or run the
91+
``nosetests`` command directly:
92+
93+
.. code-block:: sh
94+
95+
$ tox
96+
$ tox tests/unit/test_session.py
97+
$ tox -e py26,py33 tests/integration
98+
99+
You can also run individual tests with your default Python version:
100+
101+
.. code-block:: sh
102+
103+
$ nosetests tests/unit
104+
105+
Generating Documentation
106+
~~~~~~~~~~~~~~~~~~~~~~~~
107+
Sphinx is used for documentation. You can generate HTML locally with the
108+
following:
109+
110+
.. code-block:: sh
111+
112+
$ pip install -r requirements-docs.txt
113+
$ cd docs
114+
$ make html
115+
116+

0 commit comments

Comments
 (0)