diff --git a/lib/fog/vcloud_director/compute.rb b/lib/fog/vcloud_director/compute.rb index 7b2f0a8cb..4433aabc1 100644 --- a/lib/fog/vcloud_director/compute.rb +++ b/lib/fog/vcloud_director/compute.rb @@ -109,6 +109,7 @@ module Fog request :get_disks_rasd_items_list request :get_edge_gateway request :get_entity + request :get_execute_query request :get_groups_from_query request :get_guest_customization_system_section_vapp request :get_guest_customization_system_section_vapp_template diff --git a/lib/fog/vcloud_director/requests/compute/get_catalogs_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_catalogs_from_query.rb index b0a19fb24..b1ada430e 100644 --- a/lib/fog/vcloud_director/requests/compute/get_catalogs_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_catalogs_from_query.rb @@ -15,8 +15,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -28,6 +39,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :CatalogRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -38,12 +54,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-CatalogsFromQuery.html # @since vCloud API version 1.5 def get_catalogs_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -51,9 +70,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'catalogs/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:CatalogRecord] = [response.body[:CatalogRecord]] if response.body[:CatalogRecord].is_a?(Hash) + response.body[:CatalogRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_disks_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_disks_from_query.rb index 0e309ef15..79c843bc5 100644 --- a/lib/fog/vcloud_director/requests/compute/get_disks_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_disks_from_query.rb @@ -15,8 +15,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -28,6 +39,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :DiskRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -38,12 +54,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-DisksFromQuery.html # @since vCloud API version 1.5 def get_disks_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -51,9 +70,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'disks/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:DiskRecord] = [response.body[:DiskRecord]] if response.body[:DiskRecord].is_a?(Hash) + response.body[:DiskRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_execute_query.rb b/lib/fog/vcloud_director/requests/compute/get_execute_query.rb new file mode 100644 index 000000000..4c435a4c7 --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/get_execute_query.rb @@ -0,0 +1,460 @@ +module Fog + module Compute + class VcloudDirector + class Real + # REST API General queries handler. + # + # @param [String] type The type of the query. Type names are + # case-sensitive. You can retrieve a summary list of all typed + # queries types accessible to the currently authenticated user by + # making a request with type=nil. + # @param [Hash] options + # @option options [String] :sortAsc (Sorted by database ID) Sort + # results by attribute-name in ascending order. attribute-name cannot + # include metadata. + # @option options [String] :sortDesc (Sorted by database ID) Sort + # results by attribute-name in descending order. attribute-name + # cannot include metadata. + # @option options [Integer] :page (1) If the query results span + # multiple pages, return this page. + # @option options [Integer] :pageSize (25) Number of results per page, + # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. + # @option options [Integer] :offset (0) Integer value specifying the + # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. + # @return [Excon::Response] if type is specified. + # * hash<~Hash>: + # * :href<~String> - The URI of the entity. + # * :type<~String> - The MIME type of the entity. + # * :name<~String> - Query name that generated this result set. + # * :page<~String> - Page of the result set that this container + # holds. The first page is page number 1. + # * :pageSize<~String> - Page size, as a number of records or + # references. + # * :total<~String> - Total number of records or references in the + # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. + # * :Record<~Array> - The name and content of this item + # varies according to the type and format of the query. + # * :firstPage<~Integer> - First page in the result set. + # * :previousPage<~Integer> - Previous page in the result set. + # * :nextPage<~Integer> - Next page in the result set. + # * :lastPage<~Integer> - Last page in the result set. + # @return [Excon::Response] if type is nil. + # * hash<~Hash>: + # * :href<~String> - The URI of the entity. + # * :type<~String> - The MIME type of the entity. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :name<~String> - Contains the name of the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. + # + # @see http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.reference.doc_55/doc/operations/GET-ExecuteQuery.html + # @since vCloud API version 1.5 + def get_execute_query(type=nil, options={}) + if type.nil? + response = request( + :expects => 200, + :idempotent => true, + :method => 'GET', + :parser => Fog::ToHashDocument.new, + :path => 'query' + ) + else + query = ["type=#{type}"] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] + + response = request( + :expects => 200, + :idempotent => true, + :method => 'GET', + :parser => Fog::ToHashDocument.new, + :path => 'query', + :query => query.map {|q| URI.escape(q)}.join('&') + ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) + record = "#{response.body[:name]}Record".to_sym + response.body[record] = [response.body[record]] if response.body[record].is_a?(Hash) + response.body[record] ||= [] + + %w[firstPage previousPage nextPage lastPage].each do |rel| + if link = response.body[:Link].detect {|l| l[:rel] == rel} + href = Nokogiri::XML.fragment(link[:href]) + query = CGI.parse(URI.parse(href.text).query) + response.body[rel.to_sym] = query['page'].first.to_i + response.body[:pageSize] ||= query['pageSize'].first.to_i + end + end + + response + end + end + end + + class Mock + def get_execute_query(type=nil, options={}) + if type.nil? + body = + {:xmlns=>xmlns, + :xmlns_xsi=>xmlns_xsi, + :type=>"application/vnd.vmware.vcloud.query.queryList+xml", + :href=>make_href('query'), + :xsi_schemaLocation=>xsi_schema_location, + :Link=> + [{:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"organization", + :href=>make_href('query?type=organization&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"organization", + :href=>make_href('query?type=organization&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"organization", + :href=>make_href('query?type=organization&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"orgVdc", + :href=>make_href('query?type=orgVdc&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"orgVdc", + :href=>make_href('query?type=orgVdc&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"orgVdc", + :href=>make_href('query?type=orgVdc&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"media", + :href=>make_href('query?type=media&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"media", + :href=>make_href('query?type=media&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"media", + :href=>make_href('query?type=media&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vAppTemplate", + :href=>make_href('query?type=vAppTemplate&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vAppTemplate", + :href=>make_href('query?type=vAppTemplate&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vAppTemplate", + :href=>make_href('query?type=vAppTemplate&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vApp", + :href=>make_href('query?type=vApp&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vApp", + :href=>make_href('query?type=vApp&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vApp", + :href=>make_href('query?type=vApp&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vm", + :href=>make_href('query?type=vm&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vm", + :href=>make_href('query?type=vm&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vm", + :href=>make_href('query?type=vm&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"orgNetwork", + :href=>make_href('query?type=orgNetwork&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"orgNetwork", + :href=>make_href('query?type=orgNetwork&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"orgNetwork", + :href=>make_href('query?type=orgNetwork&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vAppNetwork", + :href=>make_href('query?type=vAppNetwork&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vAppNetwork", + :href=>make_href('query?type=vAppNetwork&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vAppNetwork", + :href=>make_href('query?type=vAppNetwork&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"catalog", + :href=>make_href('query?type=catalog&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"catalog", + :href=>make_href('query?type=catalog&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"catalog", + :href=>make_href('query?type=catalog&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"group", + :href=>make_href('query?type=group&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"group", + :href=>make_href('query?type=group&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"group", + :href=>make_href('query?type=group&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"user", + :href=>make_href('query?type=user&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"user", + :href=>make_href('query?type=user&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"user", + :href=>make_href('query?type=user&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"strandedUser", + :href=>make_href('query?type=strandedUser&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"strandedUser", + :href=>make_href('query?type=strandedUser&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"strandedUser", + :href=>make_href('query?type=strandedUser&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"role", + :href=>make_href('query?type=role&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"role", + :href=>make_href('query?type=role&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"role", + :href=>make_href('query?type=role&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"allocatedExternalAddress", + :href=>make_href('query?type=allocatedExternalAddress&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"allocatedExternalAddress", + :href=>make_href('query?type=allocatedExternalAddress&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"event", + :href=>make_href('query?type=event&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"event", + :href=>make_href('query?type=event&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"right", + :href=>make_href('query?type=right&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"right", + :href=>make_href('query?type=right&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"right", + :href=>make_href('query?type=right&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vAppOrgNetworkRelation", + :href=>make_href('query?type=vAppOrgNetworkRelation&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vAppOrgNetworkRelation", + :href=>make_href('query?type=vAppOrgNetworkRelation&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vAppOrgNetworkRelation", + :href=>make_href('query?type=vAppOrgNetworkRelation&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"catalogItem", + :href=>make_href('query?type=catalogItem&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"catalogItem", + :href=>make_href('query?type=catalogItem&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"catalogItem", + :href=>make_href('query?type=catalogItem&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"task", + :href=>make_href('query?type=task&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"task", + :href=>make_href('query?type=task&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"task", + :href=>make_href('query?type=task&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"disk", + :href=>make_href('query?type=disk&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"disk", + :href=>make_href('query?type=disk&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"disk", + :href=>make_href('query?type=disk&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vmDiskRelation", + :href=>make_href('query?type=vmDiskRelation&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vmDiskRelation", + :href=>make_href('query?type=vmDiskRelation&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"service", + :href=>make_href('query?type=service&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"service", + :href=>make_href('query?type=service&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"service", + :href=>make_href('query?type=service&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"orgVdcStorageProfile", + :href=>make_href('query?type=orgVdcStorageProfile&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"orgVdcStorageProfile", + :href=>make_href('query?type=orgVdcStorageProfile&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"orgVdcStorageProfile", + :href=>make_href('query?type=orgVdcStorageProfile&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"apiDefinition", + :href=>make_href('query?type=apiDefinition&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"apiDefinition", + :href=>make_href('query?type=apiDefinition&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"apiDefinition", + :href=>make_href('query?type=apiDefinition&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"fileDescriptor", + :href=>make_href('query?type=fileDescriptor&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"fileDescriptor", + :href=>make_href('query?type=fileDescriptor&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"edgeGateway", + :href=>make_href('query?type=edgeGateway&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"edgeGateway", + :href=>make_href('query?type=edgeGateway&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"edgeGateway", + :href=>make_href('query?type=edgeGateway&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"orgVdcNetwork", + :href=>make_href('query?type=orgVdcNetwork&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"orgVdcNetwork", + :href=>make_href('query?type=orgVdcNetwork&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"orgVdcNetwork", + :href=>make_href('query?type=orgVdcNetwork&format=idrecords')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.references+xml", + :name=>"vAppOrgVdcNetworkRelation", + :href=>make_href('query?type=vAppOrgVdcNetworkRelation&format=references')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.records+xml", + :name=>"vAppOrgVdcNetworkRelation", + :href=>make_href('query?type=vAppOrgVdcNetworkRelation&format=records')}, + {:rel=>"down", + :type=>"application/vnd.vmware.vcloud.query.idrecords+xml", + :name=>"vAppOrgVdcNetworkRelation", + :href=>make_href('query?type=vAppOrgVdcNetworkRelation&format=idrecords')}]} + + Excon::Response.new( + :status => 200, + :headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"}, + :body => body + ) + else + Fog::Mock.not_implemented + end + end + end + end + end +end diff --git a/lib/fog/vcloud_director/requests/compute/get_groups_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_groups_from_query.rb index ee4528f4c..966e4a6a7 100644 --- a/lib/fog/vcloud_director/requests/compute/get_groups_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_groups_from_query.rb @@ -16,8 +16,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -29,6 +40,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :GroupRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -39,12 +55,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-GroupsFromQuery.html # @since vCloud API version 1.5 def get_groups_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -52,9 +71,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'admin/groups/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:GroupRecord] = [response.body[:GroupRecord]] if response.body[:GroupRecord].is_a?(Hash) + response.body[:GroupRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_medias_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_medias_from_query.rb index 76edc000a..39b89c94d 100644 --- a/lib/fog/vcloud_director/requests/compute/get_medias_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_medias_from_query.rb @@ -15,8 +15,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -28,6 +39,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :MediaRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -38,12 +54,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-MediasFromQuery.html # @since vCloud API version 1.5 def get_medias_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -51,9 +70,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'mediaList/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:MediaRecord] = [response.body[:MediaRecord]] if response.body[:MediaRecord].is_a?(Hash) + response.body[:MediaRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_organizations_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_organizations_from_query.rb index a34a4b910..27dff18fa 100644 --- a/lib/fog/vcloud_director/requests/compute/get_organizations_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_organizations_from_query.rb @@ -16,8 +16,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -29,6 +40,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :OrganizationRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -39,12 +55,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-OrganizationsFromQuery.html # @since vCloud API version 1.5 def get_organizations_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -52,9 +71,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'admin/orgs/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:OrganizationRecord] = [response.body[:OrganizationRecord]] if response.body[:OrganizationRecord].is_a?(Hash) + response.body[:OrganizationRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_users_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_users_from_query.rb index 767f92d75..330ce35fe 100644 --- a/lib/fog/vcloud_director/requests/compute/get_users_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_users_from_query.rb @@ -16,8 +16,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -29,6 +40,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :UserRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -39,12 +55,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-UsersFromQuery-query.html # @since vCloud API version 1.5 def get_users_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -52,9 +71,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'admin/users/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:UserRecord] = [response.body[:UserRecord]] if response.body[:UserRecord].is_a?(Hash) + response.body[:UserRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_vapp_templates_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_vapp_templates_from_query.rb index 0315c0c95..2bb879a1a 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vapp_templates_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vapp_templates_from_query.rb @@ -16,8 +16,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -29,6 +40,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :VAppTemplateRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -39,12 +55,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VAppTemplatesFromQuery.html # @since vCloud API version 1.5 def get_vapp_templates_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -52,9 +71,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'vAppTemplates/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:VAppTemplateRecord] = [response.body[:VAppTemplateRecord]] if response.body[:VAppTemplateRecord].is_a?(Hash) + response.body[:VAppTemplateRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_vapps_in_lease_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_vapps_in_lease_from_query.rb index 01a7b081e..54a39578b 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vapps_in_lease_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vapps_in_lease_from_query.rb @@ -15,8 +15,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -28,6 +39,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :VAppRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -38,12 +54,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VAppsInLeaseFromQuery.html # @since vCloud API version 1.5 def get_vapps_in_lease_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -51,9 +70,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'vApps/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:VAppRecord] = [response.body[:VAppRecord]] if response.body[:VAppRecord].is_a?(Hash) + response.body[:VAppRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_vdcs_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_vdcs_from_query.rb index 29be3b4ad..1160637bd 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vdcs_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vdcs_from_query.rb @@ -15,8 +15,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -28,6 +39,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :OrgVdcRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -38,12 +54,15 @@ module Fog # @see http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.reference.doc_55/doc/operations/GET-RightsFromQuery-query.html # @since vCloud API version 1.5 def get_vdcs_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -51,9 +70,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'admin/vdcs/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:OrgVdcRecord] = [response.body[:OrgVdcRecord]] if response.body[:OrgVdcRecord].is_a?(Hash) + response.body[:OrgVdcRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb b/lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb index 41c6b3222..1de02048f 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb @@ -4,6 +4,7 @@ module Fog class Real require 'fog/vcloud_director/parsers/compute/vms_by_metadata' + # @see #get_vms_in_lease_by_query def get_vms_by_metadata(key,value) request( :expects => 200, diff --git a/lib/fog/vcloud_director/requests/compute/get_vms_in_lease_from_query.rb b/lib/fog/vcloud_director/requests/compute/get_vms_in_lease_from_query.rb index 0c0f3d23f..1628395e4 100644 --- a/lib/fog/vcloud_director/requests/compute/get_vms_in_lease_from_query.rb +++ b/lib/fog/vcloud_director/requests/compute/get_vms_in_lease_from_query.rb @@ -16,8 +16,19 @@ module Fog # multiple pages, return this page. # @option options [Integer] :pageSize (25) Number of results per page, # to a maximum of 128. + # @option options [String] :format (records) One of the following + # types: + # - *references* Returns a reference to each object, including its + # :name, :type, and :href attributes. + # - *records* Returns all database records for each object, with each + # record as an attribute. + # - *idrecords* Identical to the records format, except that object + # references are returned in :id format rather than :href format. + # @option options [Array] :fields (all static attribute names) + # List of attribute names or metadata key names to return. # @option options [Integer] :offset (0) Integer value specifying the # first record to return. Record numbers < offset are not returned. + # @option options [String] :filter (none) Filter expression. # @return [Excon::Response] # * hash<~Hash>: # * :href<~String> - The URI of the entity. @@ -29,6 +40,11 @@ module Fog # references. # * :total<~String> - Total number of records or references in the # container. + # * :Link<~Array>: + # * :href<~String> - Contains the URI to the entity. + # * :type<~String> - Contains the type of the entity. + # * :rel<~String> - Defines the relationship of the link to the + # object that contains it. # * :VMRecord<~Array>: # * TODO # * :firstPage<~Integer> - First page in the result set. @@ -39,12 +55,15 @@ module Fog # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VMsInLeaseFromQuery.html # @since vCloud API version 1.5 def get_vms_in_lease_from_query(options={}) - query = {} - query[:sortAsc] = options[:sortAsc] if options[:sortAsc] - query[:sortDesc] = options[:sortDesc] if options[:sortDesc] - query[:page] = options[:page] if options[:page] - query[:pageSize] = options[:pageSize] if options[:pageSize] - query[:offset] = options[:offset] if options[:offset] + query = [] + query << "sortAsc=#{options[:sortAsc]}" if options[:sortAsc] + query << "sortDesc=#{options[:sortDesc]}" if options[:sortDesc] + query << "page=#{options[:page]}" if options[:page] + query << "pageSize=#{options[:pageSize]}" if options[:pageSize] + query << "format=#{options[:format]}" if options[:format] + query << "fields=#{Array(options[:fields]).join(',')}" if options[:fields] + query << "offset=#{options[:offset]}" if options[:offset] + query << "filter=#{options[:filter]}" if options[:filter] response = request( :expects => 200, @@ -52,9 +71,11 @@ module Fog :method => 'GET', :parser => Fog::ToHashDocument.new, :path => 'vms/query', - :query => query + :query => query.map {|q| URI.escape(q)}.join('&') ) + response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash) response.body[:VMRecord] = [response.body[:VMRecord]] if response.body[:VMRecord].is_a?(Hash) + response.body[:VMRecord] ||= [] %w[firstPage previousPage nextPage lastPage].each do |rel| if link = response.body[:Link].detect {|l| l[:rel] == rel} diff --git a/tests/vcloud_director/requests/compute/query_tests.rb b/tests/vcloud_director/requests/compute/query_tests.rb new file mode 100644 index 000000000..3e9e7ead0 --- /dev/null +++ b/tests/vcloud_director/requests/compute/query_tests.rb @@ -0,0 +1,34 @@ +Shindo.tests('Compute::VcloudDirector | query requests', ['vclouddirector']) do + + @service = Fog::Compute::VcloudDirector.new + + tests('retrieve a summary list of all typed queries types') do + tests('#get_execute_query') do + @query_list = @service.get_execute_query.body + tests(':type').returns('application/vnd.vmware.vcloud.query.queryList+xml') do + @query_list[:type] + end + end + end + + pending if Fog.mocking? + + @query_list[:Link].select do |link| + link[:rel] == 'down' + end.sort_by do |link| + [link[:name], link[:href]] + end.each do |link| + href = Nokogiri::XML.fragment(link[:href]) + query = CGI.parse(URI.parse(href.text).query) + type = query['type'].first + format = query['format'].first + next if %w[right role strandedUser].include?(type) + tests("type => #{type}, format => #{format}") do + tests("#get_execute_query").data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do + @body = @service.get_execute_query(type, :format => format).body + end + tests("resource type").returns(link[:type]) { @body[:type] } + end + end + +end