This example provides a common pattern for filtering Lookup Service registration data. This example is based on the code in the lookup_service_helper.rb sample file. The file is located in the following vCloud Suite SDK for Ruby directory: client/samples/lib/sample/common/

This example uses the steps that are described in the Retrieve Service Endpoints on vCenter Server Instances procedure.

def lookup_service_infos(prod, svc_type, proto, ep_type, node_id=nil)
  # Uses global $my_ls_stub
  # Accepts a node_id string or '*' to search all nodes.

  # 1 - Create a SOAP request with filter criteria for the List operation.
  builder = Builder::XmlMarkup.new()
  builder.instruct!(:xml, encoding: 'UTF-8')
  builder.tag!('S:Envelope', 'xmlns:S' =>
'http://schemas.xmlsoap.org/soap/envelope/') do |envelope|
    envelope.tag!('S:Body') do |body|
      body.tag!('List', 'xmlns' => 'urn:lookup') do |list|
        list.tag!('_this', 'type' => 'LookupServiceRegistration') do |this|
          this << 'ServiceRegistration'
        end
        list.tag!('filterCriteria') do |criteria|
          node_id = nil if node_id == '*'
          if node_id
            criteria.tag!('nodeId') {|id| id << node_id }
          end
          criteria.tag!('serviceType') do |stype|
            stype.tag!('product') {|p| p << prod}
            stype.tag!('type') {|t| t << svc_type}
          end #|stype|
          criteria.tag!('endpointType') do |etype|
            etype.tag!('protocol') {|p| p << proto}
            etype.tag!('type') {|t| t << ep_type}
          end #|etype|
        end #|criteria|
      end #|list|
    end #|body|
  end #|envelope|
  request = builder.target!.to_s

  # 2 - Retrieve the Lookup Service response.
  response = $my_ls_stub.call(:list, xml: request)
  list_service_infos = response.to_hash[:list_response][:returnval]
  return list_service_infos

end  # lookup_service_infos