Sha256: 2a1769ffb2108a05ebd7bfba0cbfc9e7c235834f286a85f8b515cd9bd42f9091

Contents?: true

Size: 1.98 KB

Versions: 46

Compression:

Stored size: 1.98 KB

Contents

require 'fog/core/collection'
require 'fog/vcloud_director/models/compute/custom_field'

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

        def [](key)
          get key.to_s
        end

        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

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

        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

        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
      end

    end
  end
end

Version data entries

46 entries across 44 versions & 6 rubygems

Version Path
fog-2.3.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-ifeel-2.2.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-2.2.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-2.1.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-1.42.1/lib/fog/vcloud_director/models/compute/custom_fields.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-1.42.1/lib/fog/vcloud_director/models/compute/custom_fields.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-1.42.1/lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-1.42.1 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.2.2 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.2.1 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.2.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.1.10 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.1.9 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-2.0.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-1.42.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-1.41.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-1.40.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-1.39.0 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.1.8 lib/fog/vcloud_director/models/compute/custom_fields.rb
fog-vcloud-director-0.1.7 lib/fog/vcloud_director/models/compute/custom_fields.rb