Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ECS PlacementConstraints, PlacementStrategy, and ServiceName #706

Merged
merged 14 commits into from
May 2, 2017
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ nosetests.xml
.project
.pydevproject
.idea
.venv

# Vim
*.sw*
33 changes: 33 additions & 0 deletions tests/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@

class TestECS(unittest.TestCase):

def test_allow_placement_strategy_constraint(self):
task_definition = ecs.TaskDefinition(
"mytaskdef",
ContainerDefinitions=[
ecs.ContainerDefinition(
Image="myimage",
Memory="300",
Name="mycontainer",
)
],
Volumes=[
ecs.Volume(Name="my-vol"),
],
)
ecs_service = ecs.Service(
'Service',
Cluster='cluster',
DesiredCount=2,
PlacementStrategies=[
ecs.PlacementStrategy(
Type="random",
)
],
PlacementConstraints=[
ecs.PlacementConstraint(
Type="distinctInstance",
)
],
TaskDefinition=Ref(task_definition),
)

ecs_service.to_dict()

def test_allow_string_cluster(self):
task_definition = ecs.TaskDefinition(
"mytaskdef",
Expand Down
33 changes: 33 additions & 0 deletions troposphere/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ class DeploymentConfiguration(AWSProperty):
}


def placement_strategy_validator(x):
valid_values = ['random', 'spread', 'binpack']
if x not in valid_values:
raise ValueError("Placement Strategy type must be one of: %s" %
', '.join(valid_values))
return x


def placement_constraint_validator(x):
valid_values = ['distinctInstance', 'memberOf']
if x not in valid_values:
raise ValueError("Placement Constraint type must be one of: %s" %
', '.join(valid_values))
return x


class PlacementConstraint(AWSProperty):
props = {
'Type': (placement_constraint_validator, True),
'Expression': (basestring, False),
}


class PlacementStrategy(AWSProperty):
props = {
'Type': (placement_strategy_validator, True),
'Field': (basestring, False),
}


class Service(AWSObject):
resource_type = "AWS::ECS::Service"

Expand All @@ -35,6 +65,9 @@ class Service(AWSObject):
'DesiredCount': (positive_integer, False),
'LoadBalancers': ([LoadBalancer], False),
'Role': (basestring, False),
'PlacementConstraints': ([PlacementConstraint], False),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the convention is for these props to be alphabetical. The Placement... ones should probably be moved above Role.

'PlacementStrategies': ([PlacementStrategy], False),
'ServiceName': (basestring, False),
'TaskDefinition': (basestring, True),
}

Expand Down