From da2fcd693824c7b2bbc804a8ba9a1201c969a208 Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Fri, 5 Jul 2013 19:11:14 +0200 Subject: [PATCH] make the request when the value is set --- lib/fog/vcloudng/models/compute/tag.rb | 33 ++++++------------------- lib/fog/vcloudng/models/compute/tags.rb | 11 +++------ 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/lib/fog/vcloudng/models/compute/tag.rb b/lib/fog/vcloudng/models/compute/tag.rb index 7a0bc3414..0a5cbc7f8 100644 --- a/lib/fog/vcloudng/models/compute/tag.rb +++ b/lib/fog/vcloudng/models/compute/tag.rb @@ -10,37 +10,20 @@ module Fog identity :id, :aliases => :key attribute :value - - def save - if value_changed? - puts "Debug: change the value from #{attributes[:old_value]} to #{attributes[:value]}" - set_value(value) - attributes[:value_task].wait_for { :ready? } + def value=(new_value) + has_changed = ( value != new_value ) + not_first_set = !value.nil? + attributes[:value] = new_value + if not_first_set && has_changed + response = service.put_vm_metadata_value(attributes[:vm_id], id, value) + service.process_task(response.body) end end - def value=(new_value) - attributes[:old_value] ||= attributes[:value] - attributes[:value] = new_value - end - - def value_changed? - return false unless attributes[:old_value] - attributes[:value] != attributes[:old_value] - end - - def set_value(new_value) - response = service.put_vm_metadata_value(attributes[:vm_id], id, value) - task = response.body - task[:id] = task[:href].split('/').last - attributes[:value_task] = service.tasks.new(task) - end def destroy response = service.delete_vm_metadata(attributes[:vm_id], id) - task = response.body - task[:id] = task[:href].split('/').last - attributes[:destroy_tag_task] = service.tasks.new(task) + service.process_task(response.body) end end diff --git a/lib/fog/vcloudng/models/compute/tags.rb b/lib/fog/vcloudng/models/compute/tags.rb index 35674f362..fd45f6622 100644 --- a/lib/fog/vcloudng/models/compute/tags.rb +++ b/lib/fog/vcloudng/models/compute/tags.rb @@ -11,7 +11,7 @@ module Fog attribute :vm_id def index - tags.keys.map{ |key| new({key: key, value: tags[key] }.merge(vm_id: vm_id))} + tags.keys.map{ |key| new({key: key, value: tags[key] }.merge(vm_id: vm_id)) } end def all @@ -19,9 +19,8 @@ module Fog end def get(tag_id) - tag = tags.detect{ |tag| tag.keys.first == tag_id } - return nil unless tag - new(tag.merge(vm_id: vm_id)) + return nil unless tags[tag_id] + new({key: tag_id, value: tags[tag_id] }.merge(vm_id: vm_id)) end def create(key,value) @@ -29,9 +28,7 @@ module Fog data = Fog::Generators::Compute::Vcloudng::Metadata.new(@tags) data.add_item(key,value) response = service.post_vm_metadata(vm_id, data.attrs) - task = response.body - task[:id] = task[:href].split('/').last - attributes[:crate_tag_task] = service.tasks.new(task) + service.process_task(response.body) end # private