mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add custom_fields support to vcloud_director
This commit is contained in:
parent
a5e5d102a3
commit
02b8998d46
4 changed files with 127 additions and 0 deletions
|
@ -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
|
||||
|
|
26
lib/fog/vcloud_director/models/compute/custom_field.rb
Normal file
26
lib/fog/vcloud_director/models/compute/custom_field.rb
Normal file
|
@ -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
|
52
lib/fog/vcloud_director/models/compute/custom_fields.rb
Normal file
52
lib/fog/vcloud_director/models/compute/custom_fields.rb
Normal file
|
@ -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
|
|
@ -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 = '<ProductSectionList xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">'
|
||||
xml += '<ovf:ProductSection>'
|
||||
xml += '<ovf:Info>Global vApp Custom Properties</ovf:Info>'
|
||||
xml += '<ovf:Category>Global</ovf:Category>'
|
||||
|
||||
sections.each do |section|
|
||||
section[:user_configurable] ||= true
|
||||
section[:type] ||= "string"
|
||||
section[:password] ||= false
|
||||
xml += "<ovf:Property ovf:userConfigurable='#{section[:user_configurable]}' ovf:type='#{section[:type]}' ovf:password='#{section[:password]}' ovf:key='#{section[:id]}' ovf:value='#{section[:value]}'/>"
|
||||
end
|
||||
|
||||
xml += '</ovf:ProductSection>'
|
||||
xml += "</ProductSectionList>"
|
||||
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
|
Loading…
Reference in a new issue