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:

  • host (Object)

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



17
18
19
20
# File 'lib/lookup_service_helper.rb', line 17

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.



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

def sample
  @sample
end

#serviceRegistrationObject (readonly)

Returns the value of attribute serviceRegistration.



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

def serviceRegistration
  @serviceRegistration
end

#soap_urlObject (readonly)

Returns the value of attribute soap_url.



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

def soap_url
  @soap_url
end

#wsdl_urlObject (readonly)

Returns the value of attribute wsdl_url.



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

def wsdl_url
  @wsdl_url
end

Instance Method Details

#connectObject

Connects to the lookup service.



23
24
25
26
27
# File 'lib/lookup_service_helper.rb', line 23

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.



157
158
159
160
161
162
163
164
# File 'lib/lookup_service_helper.rb', line 157

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.



35
36
37
38
39
40
41
42
43
# File 'lib/lookup_service_helper.rb', line 35

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

  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.



63
64
65
66
67
68
# File 'lib/lookup_service_helper.rb', line 63

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
  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.



51
52
53
54
55
56
# File 'lib/lookup_service_helper.rb', line 51

def find_vapi_urls
  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.



113
114
115
116
117
118
# File 'lib/lookup_service_helper.rb', line 113

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
  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.



101
102
103
104
105
106
# File 'lib/lookup_service_helper.rb', line 101

def find_vim_pbm_urls
  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.



88
89
90
91
92
93
# File 'lib/lookup_service_helper.rb', line 88

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
  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.



76
77
78
79
80
81
# File 'lib/lookup_service_helper.rb', line 76

def find_vim_urls
  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.



146
147
148
149
150
151
152
# File 'lib/lookup_service_helper.rb', line 146

def get_default_mgmt_node
  result = find_mgmt_nodes
  raise "Management nodes not found" unless result && !result.empty?

  # WHY: raise MultipleManagementNodeException.new if result.size > 1
  [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



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

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.empty?

  result[instance_name]
end

#get_mgmt_node_instance_name(node_id) ⇒ Object



134
135
136
137
138
139
140
141
142
# 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.empty?

  result.each { |k, v| return k if v == node_id }
  nil
end