1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

make the request when the value is set

This commit is contained in:
Rodrigo Estebanez 2013-07-05 19:11:14 +02:00
parent 0ad1a40588
commit da2fcd6938
2 changed files with 12 additions and 32 deletions

View file

@ -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? }
end
end
def value=(new_value)
attributes[:old_value] ||= attributes[:value]
has_changed = ( value != new_value )
not_first_set = !value.nil?
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)
if not_first_set && has_changed
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)
service.process_task(response.body)
end
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

View file

@ -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