Skip to content

Commit

Permalink
Merge 5d4cdc1 into 57ab107
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k committed Jan 7, 2016
2 parents 57ab107 + 5d4cdc1 commit 686fec0
Show file tree
Hide file tree
Showing 26 changed files with 2,025 additions and 1,612 deletions.
30 changes: 25 additions & 5 deletions touchdown/aws/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from touchdown.core import errors, serializers, resource
from touchdown.core.action import Action
from touchdown.core.plan import Present
from touchdown.core.diff import DiffSet


logger = logging.getLogger(__name__)
Expand All @@ -33,7 +32,8 @@
class Resource(resource.Resource):

def matches(self, runner, remote):
return DiffSet(runner, self, remote).matches()
d = serializers.Resource().diff(runner, self, remote)
return d.matches()


class Waiter(Action):
Expand Down Expand Up @@ -332,6 +332,9 @@ class SimpleApply(SimpleDescribe):
def get_create_serializer(self):
return serializers.Resource()

def get_create_name(self):
return self.resource.name

def get_update_serializer(self):
return serializers.Resource(mode="update")

Expand All @@ -349,13 +352,28 @@ def create_object(self):
g.is_creation_action = True
return g

def name_object(self):
if "name" not in self.resource.meta.fields:
return
name = self.get_create_name()
argument = self.resource.meta.fields["name"].argument
if getattr(argument, "group", "") == "tags":
yield self.generic_action(
["Name newly created resource {} (via tags)".format(name)],
self.client.create_tags,
Resources=serializers.ListOfOne(serializers.Identifier()),
Tags=serializers.ListOfOne(serializers.Dict(
Key=argument.field,
Value=name,
))
)

def update_tags(self):
if getattr(self.resource, "immutable_tags", False) and self.object:
return

if hasattr(self.resource, "tags"):
local_tags = dict(self.resource.tags)
local_tags['Name'] = self.resource.name
remote_tags = dict((v["Key"], v["Value"]) for v in self.object.get('Tags', []))

tags = {}
Expand All @@ -373,11 +391,11 @@ def update_object(self):
if self.update_action and self.object:
logger.debug("Checking resource {} for changes".format(self.resource))

ds = DiffSet(self.runner, self.resource, self.object)
ds = serializers.Resource().diff(self.runner, self.resource, self.object)
if not ds.matches():
logger.debug("Resource has {} differences".format(len(ds)))
yield self.generic_action(
["Updating {}".format(self.resource)] + list(ds.get_descriptions()),
["Updating {}".format(self.resource)] + list(ds.lines()),
getattr(self.client, self.update_action),
self.get_update_serializer(),
)
Expand All @@ -394,6 +412,8 @@ def get_actions(self):
logger.debug("Cannot find AWS object for resource {} - creating one".format(self.resource))
self.object = {}
yield self.create_object()
for action in self.name_object():
yield action
created = True

if created:
Expand Down
10 changes: 7 additions & 3 deletions touchdown/aws/elastictranscoder/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from touchdown.core.resource import Resource
from touchdown.core.plan import Plan
from touchdown.core import argument, serializers, diff
from touchdown.core import argument, serializers

from ..account import BaseAccount
from ..common import SimpleDescribe, SimpleApply, SimpleDestroy
Expand Down Expand Up @@ -91,10 +91,14 @@ class Apply(SimpleApply, Describe):
create_action = "create_pipeline"

def update_object(self):
d = diff.DiffSet(self.runner, self.resource, self.object.get('Notifications', {}), group="notifications")
d = serializers.Resource(group="notifications").diff(
self.runner,
self.resource,
self.object.get('Notifications', {})
)
if not d.matches():
yield self.generic_action(
["Update pipline notification topics"] + list(d.get_descriptions()),
["Update pipline notification topics"] + list(d.lines()),
self.client.update_pipeline_notifications,
Id=serializers.Identifier(),
Notifications=serializers.Resource(group="notifications"),
Expand Down
6 changes: 2 additions & 4 deletions touchdown/aws/s3/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

from touchdown.core.resource import Resource
from touchdown.core.plan import Plan
from touchdown.core import argument
from touchdown.core import argument, serializers
from touchdown.core.errors import InvalidParameter
from touchdown.core.diff import DiffSet

from ..account import BaseAccount
from ..common import SimpleDescribe, SimpleApply, SimpleDestroy
from touchdown.core import serializers


class CorsRule(Resource):
Expand Down Expand Up @@ -159,7 +157,7 @@ def update_notification_config(self):
update_notifications = True
elif self.object:
remote = self.get_remote_notification_config()
d = DiffSet(self.runner, self.resource, remote, group="notifications")
d = serializers.Resource(group="notifications").diff(self.runner, self.resource, remote)
update_notifications = not d.matches()

if update_notifications:
Expand Down
11 changes: 5 additions & 6 deletions touchdown/aws/sns/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from ..common import Resource, SimpleDescribe, SimpleApply, SimpleDestroy
from touchdown.core import serializers
from touchdown.core.adapters import Adapter
from touchdown.core.diff import DiffSet


class Subscription(Adapter):
Expand Down Expand Up @@ -69,7 +68,7 @@ def update_object(self):

for local in self.resource.notify:
for remote in remote_subscriptions:
if DiffSet(self.runner, local, remote).matches():
if serializers.Resource().diff(self.runner, local, remote).matches():
break
else:
yield self.generic_action(
Expand All @@ -85,7 +84,7 @@ def update_object(self):

for remote in remote_subscriptions:
for local in self.resource.notify:
if DiffSet(self.runner, local, remote).matches():
if serializers.Resource().diff(self.runner, local, remote).matches():
break
else:
yield self.generic_action(
Expand All @@ -100,13 +99,13 @@ def update_object(self):
TopicArn=self.resource_id,
)['Attributes']

d = DiffSet(self.runner, self.resource, attributes, group="attributes")
for diff in d.get_changes():
d = serializers.Resource(group="attributes").diff(self.runner, self.resource, attributes)
for field, diff in d.diffs:
yield self.generic_action(
"Update {}".format(diff),
self.client.set_topic_attributes,
TopicArn=serializers.Identifier(),
AttributeName=diff.remote_name,
AttributeName=field.field,
AttributeValue=diff.local_value,
)

Expand Down
5 changes: 2 additions & 3 deletions touchdown/aws/sqs/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ..account import BaseAccount
from ..common import Resource, SimpleDescribe, SimpleApply, SimpleDestroy
from touchdown.core import serializers
from touchdown.core.diff import DiffSet

from .. import sns
from .. import cloudwatch
Expand Down Expand Up @@ -94,10 +93,10 @@ class Apply(SimpleApply, Describe):
# waiter = "bucket_exists"

def update_object(self):
d = DiffSet(self.runner, self.resource, self.object, group="attributes")
d = serializers.Resource(group="attributes").diff(self.runner, self.resource, self.object)
if not d.matches():
yield self.generic_action(
["Updating queue attributes"] + list(d.get_descriptions()),
["Updating queue attributes"] + list(d.lines()),
self.client.set_queue_attributes,
QueueUrl=serializers.Identifier(),
Attributes=serializers.Resource(group="attributes")
Expand Down
2 changes: 1 addition & 1 deletion touchdown/aws/vpc/customer_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CustomerGateway(Resource):

resource_name = "customer_gateway"

name = argument.String()
name = argument.String(field="Name", group="tags")
type = argument.String(default="ipsec.1", choices=["ipsec.1"], field="Type")
public_ip = argument.IPAddress(field="PublicIp")
bgp_asn = argument.Integer(default=65000, field="BgpAsn")
Expand Down
2 changes: 1 addition & 1 deletion touchdown/aws/vpc/internet_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InternetGateway(Resource):

resource_name = "internet_gateway"

name = argument.String()
name = argument.String(field="Name", group="tags")
tags = argument.Dict()
vpc = argument.Resource(VPC)

Expand Down
Loading

0 comments on commit 686fec0

Please sign in to comment.