From d82a1e13bbd184c16453458994a4f5c5266c30c4 Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 8 Aug 2011 12:17:14 -0500 Subject: [PATCH] [compute|aws] add support for saving assigned tags at server creation time closes #366 --- lib/fog/compute/models/aws/server.rb | 9 +++++++++ tests/compute/models/aws/server_tests.rb | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/fog/compute/models/aws/server.rb b/lib/fog/compute/models/aws/server.rb index dde33bd73..765cd7132 100644 --- a/lib/fog/compute/models/aws/server.rb +++ b/lib/fog/compute/models/aws/server.rb @@ -168,6 +168,15 @@ module Fog data = connection.run_instances(image_id, 1, 1, options) merge_attributes(data.body['instancesSet'].first) + + for key, value in self.tags + connection.tags.create( + :key => key, + :resource_id => self.identity, + :value => value + ) + end + true end diff --git a/tests/compute/models/aws/server_tests.rb b/tests/compute/models/aws/server_tests.rb index 658ec21d5..ab0bcec8a 100644 --- a/tests/compute/models/aws/server_tests.rb +++ b/tests/compute/models/aws/server_tests.rb @@ -6,7 +6,6 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do responds_to(association) end - tests('new instance') do test('#monitor = true') do @@ -44,4 +43,16 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do end @instance.destroy + + tests('tags') do + @instance = Fog::Compute[:aws].servers.create(:tags => {'key' => 'value'}) + + tests('@instance.reload.tags').returns({'key' => 'value'}) do + @instance.reload.tags + end + + Fog::Compute[:aws].tags.all('resource-id' => @instance.identity).each {|tag| tag.destroy} + @instance.destroy + end + end