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:
parent
0ad1a40588
commit
da2fcd6938
2 changed files with 12 additions and 32 deletions
|
@ -10,37 +10,20 @@ module Fog
|
||||||
identity :id, :aliases => :key
|
identity :id, :aliases => :key
|
||||||
attribute :value
|
attribute :value
|
||||||
|
|
||||||
|
def value=(new_value)
|
||||||
def save
|
has_changed = ( value != new_value )
|
||||||
if value_changed?
|
not_first_set = !value.nil?
|
||||||
puts "Debug: change the value from #{attributes[:old_value]} to #{attributes[:value]}"
|
attributes[:value] = new_value
|
||||||
set_value(value)
|
if not_first_set && has_changed
|
||||||
attributes[:value_task].wait_for { :ready? }
|
response = service.put_vm_metadata_value(attributes[:vm_id], id, value)
|
||||||
|
service.process_task(response.body)
|
||||||
end
|
end
|
||||||
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
|
def destroy
|
||||||
response = service.delete_vm_metadata(attributes[:vm_id], id)
|
response = service.delete_vm_metadata(attributes[:vm_id], id)
|
||||||
task = response.body
|
service.process_task(response.body)
|
||||||
task[:id] = task[:href].split('/').last
|
|
||||||
attributes[:destroy_tag_task] = service.tasks.new(task)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Fog
|
||||||
attribute :vm_id
|
attribute :vm_id
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def all
|
def all
|
||||||
|
@ -19,9 +19,8 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(tag_id)
|
def get(tag_id)
|
||||||
tag = tags.detect{ |tag| tag.keys.first == tag_id }
|
return nil unless tags[tag_id]
|
||||||
return nil unless tag
|
new({key: tag_id, value: tags[tag_id] }.merge(vm_id: vm_id))
|
||||||
new(tag.merge(vm_id: vm_id))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(key,value)
|
def create(key,value)
|
||||||
|
@ -29,9 +28,7 @@ module Fog
|
||||||
data = Fog::Generators::Compute::Vcloudng::Metadata.new(@tags)
|
data = Fog::Generators::Compute::Vcloudng::Metadata.new(@tags)
|
||||||
data.add_item(key,value)
|
data.add_item(key,value)
|
||||||
response = service.post_vm_metadata(vm_id, data.attrs)
|
response = service.post_vm_metadata(vm_id, data.attrs)
|
||||||
task = response.body
|
service.process_task(response.body)
|
||||||
task[:id] = task[:href].split('/').last
|
|
||||||
attributes[:crate_tag_task] = service.tasks.new(task)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# private
|
# private
|
||||||
|
|
Loading…
Reference in a new issue