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 a vCenter Server ID by Using the Lookup Service procedure.
def get_mgmt_node_id( node_instance_name ) # 1 - List the vCenter Server instances. mgmt_node_infos = lookup_service_infos( prod='com.vmware.cis', svc_type='vcenterserver', proto='vmomi', ep_type='com.vmware.vim', node_id='*') # 2 - Find the matching node name and save the ID. mgmt_node_infos.each do |node| attrs = node[:service_attributes] attrs.each do |attr| if attr[:key] == 'com.vmware.vim.vcenter.instanceName' if attr[:value] == node_instance_name return node[:node_id] end end end #|attr| end #|node| end