Class: List

Inherits:
Invocable show all
Defined in:
/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/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

- (List) initialize(client, product, service, protocol, endpoint)

Constructs a new instance.



263
264
265
266
267
268
269
270
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/lookup_service_helper.rb', line 263

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

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

Instance Method Details

- (Object) body_xml(body)

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>


291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/lookup_service_helper.rb', line 291

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

- (Object) get_instance_names



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
397
398
399
400
401
402
403
404
405
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/lookup_service_helper.rb', line 369

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
    Sample.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 { |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]
        Sample.log.debug "List: attrs=#{attrs}"
        attrs.each { |attr|
            if attr[:key] == 'com.vmware.vim.vcenter.instanceName'
                result[attr[:value]] = node_id
            end
        }
    }
    Sample.log.debug "List: result = #{result}"
    return result
end

- (Hash) get_service_endpoints

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



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
359
360
361
362
363
364
365
366
367
# File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/lookup_service_helper.rb', line 322

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>pa-rdinfra3-vm7-dhcp5583.eng.vmware.com@vsphere.local</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
    Sample.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 { |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]
    }
    Sample.log.debug "List: result = #{result}"
    return result
end