Class: Fog::Compute::VcloudDirector::CustomFields

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/vcloud_director/models/compute/custom_fields.rb

Instance Method Summary collapse

Methods inherited from Collection

#all, #get, #get_by_name, #get_everyone, #index

Instance Method Details

#[](key) ⇒ Object



17
18
19
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 17

def [](key)
  get key.to_s
end

#[]=(key, value) ⇒ Object



34
35
36
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 34

def []=(key,value)
  set(key,value)
end

#delete(item_id) ⇒ Object



38
39
40
41
42
43
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 38

def delete(item_id)
  id = item_id.to_s
  new_items = item_list.each.reject{|item| item[:id] == id}
  response = service.put_product_sections(vapp.id, new_items)
  service.process_task(response.body)
end

#get_by_id(item_id) ⇒ Object



13
14
15
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 13

def get_by_id(item_id)
  item_list.detect{|i| i[:id] == item_id}
end

#item_listObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 45

def item_list
  return @items if @items

  resp = service.get_product_sections_vapp(vapp.id).body

  collection = resp["ovf:ProductSection".to_sym]["ovf:Property".to_sym] rescue []
  collection = [collection] if collection.is_a?(Hash)

  @items = collection.collect do |property|
    {
      :id                => property[:ovf_key],
      :value             => property[:ovf_value],
      :type              => property[:ovf_type],
      :password          => property[:ovf_password],
      :user_configurable => property[:ovf_userConfigurable]
    }
  end rescue []
end

#set(key, value, opts = {:type => 'string', :password => 'false', :user_configurable => 'true'}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/vcloud_director/models/compute/custom_fields.rb', line 21

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]
  }
  response = service.put_product_sections(vapp.id, new_items)
  service.process_task(response.body)
end