This example provides a common pattern for filtering Lookup Service registration data. When you need to find the node ID under which a vCenter Server is registered with the Platform Services Controller, this function accepts a node instance name and returns the node ID for future lookup requests.

This example uses the steps that are described in the Retrieve a vCenter Server ID by Using the Lookup Service procedure.

sub get_mgmt_node_id
{
  my $node_instance_name = shift;

  # 1 - List the vCenter Server instances.
  my @mgmt_node_infos = lookup_service_infos('com.vmware.cis',
                                             'vcenterserver',
                                             'vmomi',
                                             'com.vmware.vim',
                                             '*');

  # 2 - Find the matching node name and save the ID.
  for my $node (@mgmt_node_infos) {
    my @attrs = $node{'serviceAttributes'};
    for my $attr (@attrs) {
      if ($attr{'key'} == 'com.vmware.vim.vcenter.instanceName') {
        if ($attr{'value'} == $node_instance_name) {
          return $node{'nodeId'};
        }
      }
    }  # $attr
  }  # $node
}  # get_mgmt_node_id()