Class: List

Inherits:
Invocable show all
Defined in:
lib/lookup_service_helper.rb

Overview

Encapsulates the list operation of the lookup service.

Instance Attribute Summary

Attributes inherited from Invocable

#client, #operation, #response

Instance Method Summary collapse

Methods inherited from Invocable

#invoke, #request_xml, #response_hash, #response_xml

Constructor Details

#initialize(client, product, service, protocol, endpoint) ⇒ List

Constructs a new instance.



254
255
256
257
258
259
260
261
# File 'lib/lookup_service_helper.rb', line 254

def initialize(client, product, service, protocol, endpoint)
  super(:list, client)

  @product = product
  @service = service
  @protocol = protocol
  @endpoint = endpoint
end

Instance Method Details

#body_xml(body) ⇒ Object

<S:Envelope xmlns:S=“schemas.xmlsoap.org/soap/envelope/”>

    <S:Body>
        <List xmlns="urn:lookup">
            <_this type="LookupServiceRegistration">ServiceRegistration</_this>
            <filterCriteria>
                <serviceType>
                    <product>com.vmware.cis</product>
                    <type>cs.identity</type>
                </serviceType>
                <endpointType>
                    <protocol>wsTrust</protocol>
                    <type>com.vmware.cis.cs.identity.sso</type>
                </endpointType>
            </filterCriteria>
        </List>
    </S:Body>
</S:Envelope>


282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/lookup_service_helper.rb', line 282

def body_xml(body)
  body.tag!("List", "xmlns" => "urn:lookup") do |list|
    # TODO: use the copy that was retrieved on startup?
    list.tag!("_this",
              "type" => "LookupServiceRegistration") do |this|
      this << "ServiceRegistration"
    end
    list.tag!("filterCriteria") do |criteria|
      criteria.tag!("serviceType") do |stype|
        stype.tag!("product") do |p|
          p << @product
        end
        stype.tag!("type") do |t|
          t << @service
        end
      end
      criteria.tag!("endpointType") do |etype|
        etype.tag!("protocol") do |p|
          p << @protocol
        end
        etype.tag!("type") do |t|
          t << @endpoint
        end
      end
    end
  end
end

#get_instance_namesObject



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/lookup_service_helper.rb', line 360

def get_instance_names
  result = {}
=begin
    <serviceAttributes>
        <key>com.vmware.cis.cm.GroupInternalId</key>
        <value>com.vmware.vim.vcenter</value>
    </serviceAttributes>
    <serviceAttributes>
        <key>com.vmware.cis.cm.ControlScript</key>
        <value>vmware-vpxd.sh</value>
    </serviceAttributes>
    <serviceAttributes>
        <key>com.vmware.cis.cm.HostId</key>
        <value>906477a1-24c6-4d48-9e99-55ef962878f7</value>
    </serviceAttributes>
    <serviceAttributes>
        <key>com.vmware.vim.vcenter.instanceName</key>
        <value>pa-rdinfra3-vm7-dhcp5583.eng.vmware.com</value>
    </serviceAttributes>
=end
  Base.log.debug "List: response_hash = #{response_hash}"
  return_val = response_hash[:list_response][:returnval]
  return_val = [return_val] if return_val.is_a? Hash
  return_val.each do |entry|
    node_id = entry[:node_id]
    # TODO: is it possible there be 0 or 1 attrs?  if so, deal with it.
    attrs = entry[:service_attributes]
    Base.log.debug "List: attrs=#{attrs}"
    attrs.each do |attr|
      if attr[:key] == "com.vmware.vim.vcenter.instanceName"
        result[attr[:value]] = node_id
      end
    end
  end
  Base.log.debug "List: result = #{result}"
  result
end

#get_service_endpointsHash

Gets the service endpoint information from the response. Support for MxN.

Returns:

  • (Hash)

    a hash where the key is NodeId and the Value is a Service URL



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/lookup_service_helper.rb', line 313

def get_service_endpoints
  result = {}
=begin
  <ListResponse xmlns="urn:lookup">
      <returnval>
          <serviceVersion>2.0</serviceVersion>
          <vendorNameResourceKey/>
          <vendorNameDefault/>
          <vendorProductInfoResourceKey/>
          <vendorProductInfoDefault/>
          <serviceEndpoints>
              <url>https://pa-rdinfra3-vm7-dhcp5583.eng.vmware.com/sts/STSService/vsphere.local</url>
              <endpointType>
                  <protocol>wsTrust</protocol>
                  <type>com.vmware.cis.cs.identity.sso</type>
              </endpointType>
              <sslTrust>
                  ...
              </sslTrust>
          </serviceEndpoints>
          <serviceNameResourceKey/>
          <serviceNameDefault/>
          <serviceDescriptionResourceKey/>
          <serviceDescriptionDefault/>
          <ownerId>[email protected]</ownerId>
          <serviceType>
              <product>com.vmware.cis</product>
              <type>cs.identity</type>
          </serviceType>
          <nodeId/>
          <serviceId>6a8a5058-5d3d-4d42-bb5e-383b91c8732e</serviceId>
          <siteId>default-first-site</siteId>
      </returnval>
  </ListResponse>
=end
  Base.log.debug "List: response_hash = #{response_hash}"
  return_val = response_hash[:list_response][:returnval]
  return_val = [return_val] if return_val.is_a? Hash
  return_val.each do |entry|
      # FYI: the node_id is sometimes null, so use the service_id in this case
    node_id = entry[:node_id] || entry[:service_id]
    result[node_id] = entry[:service_endpoints][:url]
  end
  Base.log.debug "List: result = #{result}"
  result
end