2014-05-20 10:51:47 -04:00
|
|
|
require 'fog/core/collection'
|
2014-05-30 12:48:17 -04:00
|
|
|
require 'fog/vcloud_director/models/compute/custom_field'
|
2014-05-20 10:51:47 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class VcloudDirector
|
|
|
|
|
|
|
|
class CustomFields < Collection
|
|
|
|
model Fog::Compute::VcloudDirector::CustomField
|
|
|
|
|
|
|
|
attribute :vapp
|
|
|
|
|
|
|
|
def get_by_id(item_id)
|
|
|
|
item_list.detect{|i| i[:id] == item_id}
|
|
|
|
end
|
|
|
|
|
2014-05-30 12:48:17 -04:00
|
|
|
def [](key)
|
|
|
|
get key.to_s
|
|
|
|
end
|
|
|
|
|
2014-05-20 10:51:47 -04:00
|
|
|
def set(key, value, opts={:type => 'string', :password => 'false', :user_configurable => 'true'})
|
|
|
|
new_items = item_list.each.reject{|item| item[:id] == key}
|
|
|
|
new_items << {
|
|
|
|
:id => key,
|
|
|
|
:value => value,
|
|
|
|
:type => opts[:type],
|
|
|
|
:password => opts[:password],
|
|
|
|
:user_configurable => opts[:user_configurable]
|
|
|
|
}
|
2014-06-18 10:28:29 -04:00
|
|
|
response = service.put_product_sections(vapp.id, new_items)
|
2014-05-30 12:48:17 -04:00
|
|
|
service.process_task(response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def []=(key,value)
|
|
|
|
set(key,value)
|
2014-05-20 10:51:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete(item_id)
|
2014-05-30 12:48:17 -04:00
|
|
|
id = item_id.to_s
|
|
|
|
new_items = item_list.each.reject{|item| item[:id] == id}
|
2014-06-18 10:28:29 -04:00
|
|
|
response = service.put_product_sections(vapp.id, new_items)
|
2014-05-30 12:48:17 -04:00
|
|
|
service.process_task(response.body)
|
2014-05-20 10:51:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def item_list
|
|
|
|
return @items if @items
|
|
|
|
|
|
|
|
resp = service.get_product_sections_vapp(vapp.id).body
|
2014-05-30 12:48:17 -04:00
|
|
|
|
|
|
|
collection = resp["ovf:ProductSection".to_sym]["ovf:Property".to_sym] rescue []
|
|
|
|
collection = [collection] if collection.is_a?(Hash)
|
|
|
|
|
|
|
|
@items = collection.collect do |property|
|
2014-05-20 10:51:47 -04:00
|
|
|
{
|
|
|
|
:id => property[:ovf_key],
|
|
|
|
:value => property[:ovf_value],
|
|
|
|
:type => property[:ovf_type],
|
|
|
|
:password => property[:ovf_password],
|
|
|
|
:user_configurable => property[:ovf_userConfigurable]
|
|
|
|
}
|
|
|
|
end rescue []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|