Class: LookupServiceHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/lookup_service_helper.rb

Overview

Utility class that helps use the lookup service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ LookupServiceHelper

Constructs a new instance.

Parameters:

  • sample (SampleBase)

    the associated sample, which provides access to the configuration properties of the sample



18
19
20
21
22
23
# File 'lib/lookup_service_helper.rb', line 18

def initialize(host)
  
    @soap_url = format("https://%s/lookupservice/sdk", host)
    @wsdl_url = format("https://%s/lookupservice/wsdl/lookup.wsdl", host)

end

Instance Attribute Details

#sampleObject (readonly)

Returns the value of attribute sample.



12
13
14
# File 'lib/lookup_service_helper.rb', line 12

def sample
  @sample
end

#serviceRegistrationObject (readonly)

Returns the value of attribute serviceRegistration.



13
14
15
# File 'lib/lookup_service_helper.rb', line 13

def serviceRegistration
  @serviceRegistration
end

#soap_urlObject (readonly)

Returns the value of attribute soap_url.



12
13
14
# File 'lib/lookup_service_helper.rb', line 12

def soap_url
  @soap_url
end

#wsdl_urlObject (readonly)

Returns the value of attribute wsdl_url.



12
13
14
# File 'lib/lookup_service_helper.rb', line 12

def wsdl_url
  @wsdl_url
end

Instance Method Details

#connectObject

Connects to the lookup service.



26
27
28
29
30
# File 'lib/lookup_service_helper.rb', line 26

def connect
    rsc = RetrieveServiceContent.new(client).invoke()
    @serviceRegistration = rsc.get_service_registration()
    Base.log.info "service registration = #{serviceRegistration}"
end

#find_mgmt_nodesHash

Finds all the management nodes

Returns:

  • (Hash)

    management node instance name and node id (UUID) in a dictionary.



154
155
156
157
158
159
160
161
# File 'lib/lookup_service_helper.rb', line 154

def find_mgmt_nodes
    #assert self.serviceRegistration is not None
    list = List.new(client, 'com.vmware.cis', 'vcenterserver',
                    'vmomi', 'com.vmware.vim')

    list.invoke()
    list.get_instance_names()
end

#find_sso_urlString

Finds the SSO service URL. In a MxN setup where there are more than one PSC nodes; This method returns the first SSO service endpoint URL as returned by the lookup service.

Returns:

  • (String)

    SSO Service endpoint URL.



38
39
40
41
42
43
44
45
# File 'lib/lookup_service_helper.rb', line 38

def find_sso_url
    result = find_service_url(product='com.vmware.cis',
                              service='cs.identity',
                              endpoint='com.vmware.cis.cs.identity.sso',
                              protocol='wsTrust')
    raise 'SSO URL not found' unless result && result.size > 0
    return result.values[0]
end

#find_vapi_url(node_id) ⇒ String

Finds the vapi service endpoint URL of a management node.

Parameters:

  • node_id (String)

    The UUID of the management node.

Returns:

  • (String)

    vapi service endpoint URL of a management node or nil if no vapi endpoint is found.



65
66
67
68
69
70
# File 'lib/lookup_service_helper.rb', line 65

def find_vapi_url(node_id)
    raise 'node_id is required' if node_id.nil?
    result = find_vapi_urls()
    raise 'VAPI URLs not found' unless result && result.size > 0
    return result[node_id]
end

#find_vapi_urlsHash

Finds all the vAPI service endpoint URLs. In a MxN setup where there are more than one management node; this method returns more than one URL

Returns:

  • (Hash)

    vapi service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL.



53
54
55
56
57
58
# File 'lib/lookup_service_helper.rb', line 53

def find_vapi_urls
    return find_service_url(product='com.vmware.cis',
                            service='cs.vapi',
                            endpoint='com.vmware.vapi.endpoint',
                            protocol='vapi.json.https.public')
end

#find_vim_pbm_url(node_id) ⇒ String

Finds the spbm service endpoint URL of a management node

Parameters:

  • node_id (String)

    The UUID of the management node.

Returns:

  • (String)

    spbm service endpoint URL of a management node or nil if no spbm endpoint is found.



115
116
117
118
119
120
# File 'lib/lookup_service_helper.rb', line 115

def find_vim_pbm_url(node_id)
    raise 'node_id is required' if node_id.nil?
    result = find_vim_pbm_urls()
    raise 'PBM URLs not found' unless result && result.size > 0
    return result[node_id]
end

#find_vim_pbm_urlsHash

Finds all the spbm service endpoint URLs In a MxN setup where there are more than one management node; this method returns more than one URL

Returns:

  • (Hash)

    spbm service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL.



103
104
105
106
107
108
# File 'lib/lookup_service_helper.rb', line 103

def find_vim_pbm_urls
    return find_service_url(product='com.vmware.vim.sms',
                            service='sms',
                            endpoint='com.vmware.vim.pbm',
                            protocol='https')
end

#find_vim_url(node_id) ⇒ String

Finds the vim service endpoint URL of a management node

Parameters:

  • node_id (String)

    The UUID of the management node.

Returns:

  • (String)

    vim service endpoint URL of a management node or nil if no vim endpoint is found.



90
91
92
93
94
95
# File 'lib/lookup_service_helper.rb', line 90

def find_vim_url(node_id)
    raise 'node_id is required' if node_id.nil?
    result = find_vim_urls()
    raise 'VIM URLs not found' unless result && result.size > 0
    return result[node_id]
end

#find_vim_urlsHash

Finds all the vim service endpoint URLs In a MxN setup where there are more than one management node; this method returns more than one URL

Returns:

  • (Hash)

    vim service endpoint URLs in a dictionary where the key is the node_id and the value is the service URL.



78
79
80
81
82
83
# File 'lib/lookup_service_helper.rb', line 78

def find_vim_urls
    return find_service_url(product='com.vmware.cis',
                            service='vcenterserver',
                            endpoint='com.vmware.vim',
                            protocol='vmomi')
end

#get_default_mgmt_nodeObject

Finds the instance name and UUID of the management node for M1xN1 or when the PSC and management services all reside on a single node.



144
145
146
147
148
149
# File 'lib/lookup_service_helper.rb', line 144

def get_default_mgmt_node
    result = find_mgmt_nodes()
    raise 'Management nodes not found' unless result && result.size > 0
    #WHY: raise MultipleManagementNodeException.new if result.size > 1
    return [result.keys[0], result.values[0]]
end

#get_mgmt_node_id(instance_name) ⇒ String

Get the management node id from the instance name

Parameters:

  • instance_name (String)

    The instance name of the management node

Returns:

  • (String)

    The UUID of the management node or nil is no management node is found by the given instance name



127
128
129
130
131
132
# File 'lib/lookup_service_helper.rb', line 127

def get_mgmt_node_id(instance_name)
    raise 'instance_name is required' if instance_name.nil?
    result = find_mgmt_nodes()
    raise 'Management nodes not found' unless result && result.size > 0
    return result[instance_name]
end

#get_mgmt_node_instance_name(node_id) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/lookup_service_helper.rb', line 134

def get_mgmt_node_instance_name(node_id)
    raise 'node_id is required' if node_id.nil?
    result = find_mgmt_nodes()
    raise 'Management nodes not found' unless result && result.size > 0
    result.each { |k, v| return k if v == node_id }
    nil
end