diff --git a/lib/fog/vcloud_director/compute.rb b/lib/fog/vcloud_director/compute.rb index e18f2f6c4..89f0b0762 100644 --- a/lib/fog/vcloud_director/compute.rb +++ b/lib/fog/vcloud_director/compute.rb @@ -54,6 +54,8 @@ module Fog collection :organizations model :catalog_item collection :catalog_items + model :custom_fields + collection :custom_fields model :vdc collection :vdcs model :vapp @@ -247,6 +249,7 @@ module Fog request :put_metadata_value # deprecated request :put_network request :put_network_connection_system_section_vapp + request :put_product_sections_vapp request :put_vapp_metadata_item_metadata request :put_vapp_name_and_description request :put_vapp_template_metadata_item_metadata diff --git a/lib/fog/vcloud_director/models/compute/custom_field.rb b/lib/fog/vcloud_director/models/compute/custom_field.rb new file mode 100644 index 000000000..0599d91e9 --- /dev/null +++ b/lib/fog/vcloud_director/models/compute/custom_field.rb @@ -0,0 +1,26 @@ +require 'fog/core/model' + +module Fog + module Compute + class VcloudDirector + + class CustomField < Model + + identity :id + attribute :value + attribute :type + attribute :password + attribute :user_configurable + + def set(key, value, opts={}) + service.put_vapp_custom_field(vapp.id, key, value, opts={}) + end + + def destroy + response = service.delete_vapp_custom_field(vapp.id, key) + service.process_task(response.body) + end + end + end + end +end diff --git a/lib/fog/vcloud_director/models/compute/custom_fields.rb b/lib/fog/vcloud_director/models/compute/custom_fields.rb new file mode 100644 index 000000000..c560f74cc --- /dev/null +++ b/lib/fog/vcloud_director/models/compute/custom_fields.rb @@ -0,0 +1,52 @@ +require 'fog/core/collection' +require 'fog/vcloud_director/models/compute/tag' + +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 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] + } + service.put_product_sections_vapp(vapp.id, new_items) + end + + def delete(item_id) + new_items = item_list.each.reject{|item| item[:id] == item_id} + service.put_product_sections_vapp(vapp.id, new_items) + end + + def item_list + return @items if @items + + resp = service.get_product_sections_vapp(vapp.id).body + @items = resp["ovf:ProductSection".to_sym]["ovf:Property".to_sym].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 diff --git a/lib/fog/vcloud_director/requests/compute/put_product_sections_vapp.rb b/lib/fog/vcloud_director/requests/compute/put_product_sections_vapp.rb new file mode 100644 index 000000000..c21a393ac --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/put_product_sections_vapp.rb @@ -0,0 +1,46 @@ +module Fog + module Compute + class VcloudDirector + class Real + # Set the value for the specified metadata key to the value provided, + # overwriting any existing value. + # + # @param [String] id Object identifier of the vApp or VM. + # @param [String] key Key of the metadata item. + # @param [Boolean,DateTime,Fixnum,String] value Value of the metadata + # item. + # @return [Excon::Response] + # * body<~Hash>: + # + # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/PUT-VAppMetadataItem-metadata.html + # @since vCloud API version 1.5 + def put_product_sections_vapp(id, sections) + xml = '' + xml += '' + xml += 'Global vApp Custom Properties' + xml += 'Global' + + sections.each do |section| + section[:user_configurable] ||= true + section[:type] ||= "string" + section[:password] ||= false + xml += "" + end + + xml += '' + xml += "" + puts xml + + request( + :body => xml, + :expects => 202, + :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.productSections+xml'}, + :method => 'PUT', + :parser => Fog::ToHashDocument.new, + :path => "vApp/#{id}/productSections" + ) + end + end + end + end +end