ibm_power_hmc 0.2.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +0 -0
- data/.rubocop_local.yml +2 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/ibm_power_hmc.gemspec +0 -0
- data/lib/ibm_power_hmc/connection.rb +161 -23
- data/lib/ibm_power_hmc/job.rb +0 -0
- data/lib/ibm_power_hmc/parser.rb +217 -39
- data/lib/ibm_power_hmc/pcm.rb +0 -0
- data/lib/ibm_power_hmc/version.rb +1 -1
- data/lib/ibm_power_hmc.rb +4 -4
- metadata +7 -8
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 288ed57579492fd505491fe8e56f9dbd371cb6aaae118f98c14202fd20e8bf85
|
4
|
+
data.tar.gz: b21286ee62bfa69e14d609ad001b72f012ccbe3fdebc59f090320d03877e6d20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d5010709dd4a423ca131c99d3891ef78c4de8a479e87afe402eb554db660f03f2d85b24728d22773ff1681263f4346ff303e08078c4e9b91519e5ad6398a40a
|
7
|
+
data.tar.gz: fd6e00f6bb1039b0320d7fb7959f6a3a2206047fe6ebcb1cc795a6f0f37e92e8740cbe8d980d4fa496bfa6c00d3de6efeafba6f4136b7974630b5d187e4bbc7d
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
File without changes
|
data/.rubocop_local.yml
CHANGED
data/CHANGELOG.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/ibm_power_hmc.gemspec
CHANGED
File without changes
|
@@ -8,15 +8,15 @@ module IbmPowerHmc
|
|
8
8
|
# HMC REST Client connection.
|
9
9
|
class Connection
|
10
10
|
##
|
11
|
-
# @!method initialize(host:, username: "hscroot",
|
11
|
+
# @!method initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true)
|
12
12
|
# Create a new HMC connection.
|
13
13
|
#
|
14
14
|
# @param host [String] Hostname of the HMC.
|
15
|
-
# @param username [String] User name.
|
16
15
|
# @param password [String] Password.
|
16
|
+
# @param username [String] User name.
|
17
17
|
# @param port [Integer] TCP port number.
|
18
18
|
# @param validate_ssl [Boolean] Verify SSL certificates.
|
19
|
-
def initialize(host:, username: "hscroot",
|
19
|
+
def initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true)
|
20
20
|
@hostname = "#{host}:#{port}"
|
21
21
|
@username = username
|
22
22
|
@password = password
|
@@ -151,18 +151,13 @@ module IbmPowerHmc
|
|
151
151
|
end
|
152
152
|
|
153
153
|
##
|
154
|
-
# @!method rename_lpar(lpar_uuid,
|
154
|
+
# @!method rename_lpar(lpar_uuid, new_name)
|
155
155
|
# Rename a logical partition.
|
156
156
|
# @param lpar_uuid [String] The UUID of the logical partition.
|
157
|
-
# @param
|
158
|
-
def rename_lpar(lpar_uuid,
|
157
|
+
# @param new_name [String] The new name of the logical partition.
|
158
|
+
def rename_lpar(lpar_uuid, new_name)
|
159
159
|
method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"
|
160
|
-
|
161
|
-
:content_type => "application/vnd.ibm.powervm.uom+xml; type=LogicalPartition",
|
162
|
-
}
|
163
|
-
modify_object(method_url, headers) do |lpar|
|
164
|
-
lpar.xml.elements["PartitionName"].text = newname
|
165
|
-
end
|
160
|
+
modify_object(method_url) { |lpar| lpar.name = new_name }
|
166
161
|
end
|
167
162
|
|
168
163
|
##
|
@@ -201,6 +196,110 @@ module IbmPowerHmc
|
|
201
196
|
Parser.new(response.body).object(:VirtualIOServer)
|
202
197
|
end
|
203
198
|
|
199
|
+
##
|
200
|
+
# @!method virtual_switches(sys_uuid)
|
201
|
+
# Retrieve the list of virtual switches from a specified managed system.
|
202
|
+
# @param sys_uuid [String] The UUID of the managed system.
|
203
|
+
# @return [Array<IbmPowerHmc::VirtualSwitch>] The list of virtual switches.
|
204
|
+
def virtual_switches(sys_uuid)
|
205
|
+
method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualSwitch"
|
206
|
+
response = request(:get, method_url)
|
207
|
+
FeedParser.new(response.body).objects(:VirtualSwitch)
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# @!method virtual_switch(vswitch_uuid, sys_uuid)
|
212
|
+
# Retrieve information about a virtual switch.
|
213
|
+
# @param vswitch_uuid [String] The UUID of the virtual switch.
|
214
|
+
# @param sys_uuid [String] The UUID of the managed system.
|
215
|
+
# @return [IbmPowerHmc::VirtualSwitch] The virtual switch.
|
216
|
+
def virtual_switch(vswitch_uuid, sys_uuid)
|
217
|
+
method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualSwitch/#{vswitch_uuid}"
|
218
|
+
response = request(:get, method_url)
|
219
|
+
Parser.new(response.body).object(:VirtualSwitch)
|
220
|
+
end
|
221
|
+
|
222
|
+
##
|
223
|
+
# @!method virtual_networks(sys_uuid)
|
224
|
+
# Retrieve the list of virtual networks from a specified managed system.
|
225
|
+
# @param sys_uuid [String] The UUID of the managed system.
|
226
|
+
# @return [Array<IbmPowerHmc::VirtualNetwork>] The list of virtual networks.
|
227
|
+
def virtual_networks(sys_uuid)
|
228
|
+
method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualNetwork"
|
229
|
+
response = request(:get, method_url)
|
230
|
+
FeedParser.new(response.body).objects(:VirtualNetwork)
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# @!method virtual_network(vnet_uuid, sys_uuid)
|
235
|
+
# Retrieve information about a virtual network.
|
236
|
+
# @param vnet_uuid [String] The UUID of the virtual network.
|
237
|
+
# @param sys_uuid [String] The UUID of the managed system.
|
238
|
+
# @return [IbmPowerHmc::VirtualNetwork] The virtual network.
|
239
|
+
def virtual_network(vnet_uuid, sys_uuid)
|
240
|
+
method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualNetwork/#{vnet_uuid}"
|
241
|
+
response = request(:get, method_url)
|
242
|
+
Parser.new(response.body).object(:VirtualNetwork)
|
243
|
+
end
|
244
|
+
|
245
|
+
##
|
246
|
+
# @!method network_adapter_lpar(lpar_uuid, netadap_uuid = nil)
|
247
|
+
# Retrieve one or all virtual ethernet network adapters attached to a logical partition.
|
248
|
+
# @param lpar_uuid [String] UUID of the logical partition.
|
249
|
+
# @param netadap_uuid [String] UUID of the adapter to match (returns all adapters if omitted).
|
250
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of network adapters.
|
251
|
+
def network_adapter_lpar(lpar_uuid, netadap_uuid = nil)
|
252
|
+
network_adapter("LogicalPartition", lpar_uuid, netadap_uuid)
|
253
|
+
end
|
254
|
+
|
255
|
+
##
|
256
|
+
# @!method network_adapter_vios(vios_uuid, netadap_uuid = nil)
|
257
|
+
# Retrieve one or all virtual ethernet network adapters attached to a Virtual I/O Server.
|
258
|
+
# @param vios_uuid [String] UUID of the Virtual I/O Server.
|
259
|
+
# @param netadap_uuid [String] UUID of the adapter to match (returns all adapters if omitted).
|
260
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of network adapters.
|
261
|
+
def network_adapter_vios(vios_uuid, netadap_uuid = nil)
|
262
|
+
network_adapter("VirtualIOServer", vios_uuid, netadap_uuid)
|
263
|
+
end
|
264
|
+
|
265
|
+
##
|
266
|
+
# @!method sriov_elp_lpar(lpar_uuid, sriov_elp_uuid = nil)
|
267
|
+
# Retrieve one or all SR-IOV ethernet logical ports attached to a logical partition.
|
268
|
+
# @param lpar_uuid [String] UUID of the logical partition.
|
269
|
+
# @param netadap_uuid [String] UUID of the port to match (returns all ports if omitted).
|
270
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of ports.
|
271
|
+
def sriov_elp_lpar(lpar_uuid, sriov_elp_uuid = nil)
|
272
|
+
sriov_ethernet_port("LogicalPartition", lpar_uuid, sriov_elp_uuid)
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# @!method network_adapter_vios(vios_uuid, netadap_uuid = nil)
|
277
|
+
# Retrieve one or all SR-IOV ethernet logical ports attached to a Virtual I/O Server.
|
278
|
+
# @param vios_uuid [String] UUID of the Virtual I/O Server.
|
279
|
+
# @param netadap_uuid [String] UUID of the port to match (returns all ports if omitted).
|
280
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of ports.
|
281
|
+
def sriov_elp_vios(vios_uuid, sriov_elp_uuid = nil)
|
282
|
+
sriov_ethernet_port("VirtualIOServer", vios_uuid, sriov_elp_uuid)
|
283
|
+
end
|
284
|
+
|
285
|
+
##
|
286
|
+
# @!method vnic_dedicated(lpar_uuid, vnic_uuid = nil)
|
287
|
+
# Retrieve one or all dedicated virtual network interface controller (vNIC) attached to a logical partition.
|
288
|
+
# @param lpar_uuid [String] UUID of the logical partition.
|
289
|
+
# @param netadap_uuid [String] UUID of the vNIC to match (returns all vNICs if omitted).
|
290
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of vNICs.
|
291
|
+
def vnic_dedicated(lpar_uuid, vnic_uuid = nil)
|
292
|
+
if vnic_uuid.nil?
|
293
|
+
method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualNICDedicated"
|
294
|
+
response = request(:get, method_url)
|
295
|
+
FeedParser.new(response.body).objects(:VirtualNICDedicated)
|
296
|
+
else
|
297
|
+
method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualNICDedicated/#{vnic_uuid}"
|
298
|
+
response = request(:get, method_url)
|
299
|
+
Parser.new(response.body).object(:VirtualNICDedicated)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
204
303
|
##
|
205
304
|
# @!method poweron_lpar(lpar_uuid, params = {}, sync = true)
|
206
305
|
# Power on a logical partition.
|
@@ -219,9 +318,7 @@ module IbmPowerHmc
|
|
219
318
|
##
|
220
319
|
# @!method poweroff_lpar(lpar_uuid, params = {}, sync = true)
|
221
320
|
# Power off a logical partition.
|
222
|
-
# @param
|
223
|
-
# @param params [Hash] Job parameters.
|
224
|
-
# @param sync [Boolean] Start the job and wait for its completion.
|
321
|
+
# @param (see #poweron_lpar)
|
225
322
|
# @return [IbmPowerHmc::HmcJob] The HMC job.
|
226
323
|
def poweroff_lpar(lpar_uuid, params = {}, sync = true)
|
227
324
|
method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/PowerOff"
|
@@ -249,9 +346,7 @@ module IbmPowerHmc
|
|
249
346
|
##
|
250
347
|
# @!method poweroff_vios(vios_uuid, params = {}, sync = true)
|
251
348
|
# Power off a virtual I/O server.
|
252
|
-
# @param
|
253
|
-
# @param params [Hash] Job parameters.
|
254
|
-
# @param sync [Boolean] Start the job and wait for its completion.
|
349
|
+
# @param (see #poweron_vios)
|
255
350
|
# @return [IbmPowerHmc::HmcJob] The HMC job.
|
256
351
|
def poweroff_vios(vios_uuid, params = {}, sync = true)
|
257
352
|
method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/do/PowerOff"
|
@@ -279,9 +374,7 @@ module IbmPowerHmc
|
|
279
374
|
##
|
280
375
|
# @!method poweroff_managed_system(sys_uuid, params = {}, sync = true)
|
281
376
|
# Power off a managed system.
|
282
|
-
# @param
|
283
|
-
# @param params [Hash] Job parameters.
|
284
|
-
# @param sync [Boolean] Start the job and wait for its completion.
|
377
|
+
# @param (see #poweron_managed_system)
|
285
378
|
# @return [IbmPowerHmc::HmcJob] The HMC job.
|
286
379
|
def poweroff_managed_system(sys_uuid, params = {}, sync = true)
|
287
380
|
method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/do/PowerOff"
|
@@ -418,6 +511,13 @@ module IbmPowerHmc
|
|
418
511
|
|
419
512
|
private
|
420
513
|
|
514
|
+
# @!method modify_object(method_url, headers = {}, attempts = 5)
|
515
|
+
# Modify an object at a specified URI.
|
516
|
+
# @param method_url [String] The URL of the object to modify.
|
517
|
+
# @param headers [Hash] HTTP headers.
|
518
|
+
# @param attempts [Integer] Maximum number of retries.
|
519
|
+
# @yield [obj] The object to modify.
|
520
|
+
# @yieldparam obj [IbmPowerHmc::AbstractRest] The object to modify.
|
421
521
|
def modify_object(method_url, headers = {}, attempts = 5)
|
422
522
|
while attempts > 0
|
423
523
|
response = request(:get, method_url)
|
@@ -426,16 +526,54 @@ module IbmPowerHmc
|
|
426
526
|
yield obj
|
427
527
|
|
428
528
|
# Use ETag to ensure object has not changed.
|
429
|
-
headers = headers.merge("If-Match" => obj.etag)
|
529
|
+
headers = headers.merge("If-Match" => obj.etag, :content_type => obj.content_type)
|
430
530
|
begin
|
431
531
|
request(:post, method_url, headers, obj.xml.to_s)
|
432
532
|
break
|
433
533
|
rescue HttpError => e
|
434
534
|
attempts -= 1
|
435
|
-
# Will get 412 ("Precondition Failed" if ETag mismatches
|
535
|
+
# Will get 412 ("Precondition Failed") if ETag mismatches
|
436
536
|
raise if e.status != 412 || attempts == 0
|
437
537
|
end
|
438
538
|
end
|
439
539
|
end
|
540
|
+
|
541
|
+
##
|
542
|
+
# @!method network_adapter(vm_type, lpar_uuid, netadap_uuid)
|
543
|
+
# Retrieve one or all virtual ethernet network adapters attached to a Logical Partition or a Virtual I/O Server.
|
544
|
+
# @param vm_type [String] "LogicalPartition" or "VirtualIOServer".
|
545
|
+
# @param lpar_uuid [String] UUID of the Logical Partition or the Virtual I/O Server.
|
546
|
+
# @param netadap_uuid [String] UUID of the adapter to match (returns all adapters if nil).
|
547
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of network adapters.
|
548
|
+
def network_adapter(vm_type, lpar_uuid, netadap_uuid)
|
549
|
+
if netadap_uuid.nil?
|
550
|
+
method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/ClientNetworkAdapter"
|
551
|
+
response = request(:get, method_url)
|
552
|
+
FeedParser.new(response.body).objects(:ClientNetworkAdapter)
|
553
|
+
else
|
554
|
+
method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/ClientNetworkAdapter/#{netadap_uuid}"
|
555
|
+
response = request(:get, method_url)
|
556
|
+
Parser.new(response.body).object(:ClientNetworkAdapter)
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
##
|
561
|
+
# @!method sriov_ethernet_port(vm_type, lpar_uuid, sriov_elp_uuid)
|
562
|
+
# Retrieve one or all SR-IOV Ethernet loical ports attached to a Logical Partition or a Virtual I/O Server.
|
563
|
+
# @param vm_type [String] "LogicalPartition" or "VirtualIOServer".
|
564
|
+
# @param lpar_uuid [String] UUID of the Logical Partition or the Virtual I/O Server.
|
565
|
+
# @param netadap_uuid [String] UUID of the port to match (returns all ports if nil).
|
566
|
+
# @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of ports.
|
567
|
+
def sriov_ethernet_port(vm_type, lpar_uuid, sriov_elp_uuid)
|
568
|
+
if sriov_elp_uuid.nil?
|
569
|
+
method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/SRIOVEthernetLogicalPort"
|
570
|
+
response = request(:get, method_url)
|
571
|
+
FeedParser.new(response.body).objects(:SRIOVEthernetLogicalPort)
|
572
|
+
else
|
573
|
+
method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/SRIOVEthernetLogicalPort/#{sriov_elp_uuid}"
|
574
|
+
response = request(:get, method_url)
|
575
|
+
Parser.new(response.body).object(:SRIOVEthernetLogicalPort)
|
576
|
+
end
|
577
|
+
end
|
440
578
|
end
|
441
579
|
end
|
data/lib/ibm_power_hmc/job.rb
CHANGED
File without changes
|
data/lib/ibm_power_hmc/parser.rb
CHANGED
@@ -4,16 +4,26 @@ require 'time'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module IbmPowerHmc
|
7
|
-
|
7
|
+
##
|
8
|
+
# Generic parser for HMC K2 XML responses.
|
8
9
|
class Parser
|
9
10
|
def initialize(body)
|
10
11
|
@doc = REXML::Document.new(body)
|
11
12
|
end
|
12
13
|
|
14
|
+
##
|
15
|
+
# @!method entry
|
16
|
+
# Return the first K2 entry element in the response.
|
17
|
+
# @return [REXML::Element, nil] The first entry element.
|
13
18
|
def entry
|
14
19
|
@doc.elements["entry"]
|
15
20
|
end
|
16
21
|
|
22
|
+
##
|
23
|
+
# @!method object(filter_type = nil)
|
24
|
+
# Parse the first K2 entry element into an object.
|
25
|
+
# @param filter_type [String] Entry type must match the specified type.
|
26
|
+
# @return [IbmPowerHmc::AbstractRest, nil] The parsed object.
|
17
27
|
def object(filter_type = nil)
|
18
28
|
self.class.to_obj(entry, filter_type)
|
19
29
|
end
|
@@ -21,19 +31,28 @@ module IbmPowerHmc
|
|
21
31
|
def self.to_obj(entry, filter_type = nil)
|
22
32
|
return if entry.nil?
|
23
33
|
|
24
|
-
content = entry.elements["content"]
|
34
|
+
content = entry.elements["content[@type]"]
|
25
35
|
return if content.nil?
|
26
36
|
|
27
|
-
type = content.attributes["type"]
|
28
|
-
return if type.nil?
|
29
|
-
|
30
|
-
type = type.split("=").last
|
37
|
+
type = content.attributes["type"].split("=").last
|
31
38
|
return unless filter_type.nil? || filter_type.to_s == type
|
32
39
|
|
33
40
|
Module.const_get("IbmPowerHmc::#{type}").new(entry)
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
44
|
+
##
|
45
|
+
# Parser for HMC K2 feeds.
|
46
|
+
# A feed encapsulates a list of entries like this:
|
47
|
+
# <feed>
|
48
|
+
# <entry>
|
49
|
+
# <!-- entry #1 -->
|
50
|
+
# </entry>
|
51
|
+
# <entry>
|
52
|
+
# <!-- entry #2 -->
|
53
|
+
# </entry>
|
54
|
+
# ...
|
55
|
+
# </feed>
|
37
56
|
class FeedParser < Parser
|
38
57
|
def entries
|
39
58
|
objs = []
|
@@ -43,6 +62,11 @@ module IbmPowerHmc
|
|
43
62
|
objs
|
44
63
|
end
|
45
64
|
|
65
|
+
##
|
66
|
+
# @!method objects(filter_type = nil)
|
67
|
+
# Parse feed entries into objects.
|
68
|
+
# @param filter_type [String] Filter entries based on content type.
|
69
|
+
# @return [Array<IbmPowerHmc::AbstractRest>] The list of objects.
|
46
70
|
def objects(filter_type = nil)
|
47
71
|
entries do |entry|
|
48
72
|
self.class.to_obj(entry, filter_type)
|
@@ -53,38 +77,88 @@ module IbmPowerHmc
|
|
53
77
|
private_constant :Parser
|
54
78
|
private_constant :FeedParser
|
55
79
|
|
56
|
-
|
57
|
-
|
80
|
+
##
|
81
|
+
# HMC generic K2 non-REST object.
|
82
|
+
# @abstract
|
83
|
+
# @attr_reader [REXML::Document] xml The XML document representing this object.
|
84
|
+
class AbstractNonRest
|
58
85
|
ATTRS = {}.freeze
|
59
|
-
attr_reader :
|
86
|
+
attr_reader :xml
|
60
87
|
|
61
|
-
def initialize(
|
62
|
-
@
|
63
|
-
|
64
|
-
@etag = doc.elements["etag:etag"]&.text&.strip
|
65
|
-
type = self.class.name.split("::").last
|
66
|
-
@xml = doc.elements["content/#{type}:#{type}"]
|
67
|
-
define_attrs(self.class::ATTRS)
|
88
|
+
def initialize(xml)
|
89
|
+
@xml = xml
|
90
|
+
self.class::ATTRS.each { |varname, xpath| define_attr(varname, xpath) }
|
68
91
|
end
|
69
92
|
|
93
|
+
##
|
94
|
+
# @!method define_attr(varname, xpath)
|
95
|
+
# Define an instance variable using the text of an XML element as value.
|
96
|
+
# @param varname [String] The name of the instance variable.
|
97
|
+
# @param xpath [String] The XPath of the XML element containing the text.
|
70
98
|
def define_attr(varname, xpath)
|
71
|
-
value =
|
99
|
+
value = singleton(xpath)
|
72
100
|
self.class.__send__(:attr_reader, varname)
|
73
101
|
instance_variable_set("@#{varname}", value)
|
74
102
|
end
|
103
|
+
private :define_attr
|
75
104
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
105
|
+
##
|
106
|
+
# @!method singleton(xpath, attr = nil)
|
107
|
+
# Get the text (or the value of a specified attribute) of an XML element.
|
108
|
+
# @param xpath [String] The XPath of the XML element.
|
109
|
+
# @param attr [String] The name of the attribute.
|
110
|
+
# @return [String, nil] The text or attribute value of the XML element or nil.
|
111
|
+
# @example lpar.singleton("PartitionProcessorConfiguration/*/MaximumVirtualProcessors").to_i
|
112
|
+
def singleton(xpath, attr = nil)
|
113
|
+
elem = xml.elements[xpath]
|
114
|
+
return if elem.nil?
|
115
|
+
|
116
|
+
attr.nil? ? elem.text&.strip : elem.attributes[attr]
|
80
117
|
end
|
81
118
|
|
82
|
-
def
|
83
|
-
|
119
|
+
def extract_uuid_from_href(href, index = -1)
|
120
|
+
URI(href).path.split('/')[index]
|
84
121
|
end
|
85
122
|
|
86
|
-
def
|
87
|
-
|
123
|
+
def uuids_from_links(elem, index = -1)
|
124
|
+
xml.get_elements("#{elem}/link[@href]").map do |link|
|
125
|
+
extract_uuid_from_href(link.attributes["href"], index)
|
126
|
+
end.compact
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# HMC generic K2 REST object.
|
132
|
+
# Encapsulate data for a single REST object.
|
133
|
+
# The XML looks like this:
|
134
|
+
# <entry>
|
135
|
+
# <id>uuid</id>
|
136
|
+
# <published>timestamp</published>
|
137
|
+
# <link rel="SELF" href="https://..."/>
|
138
|
+
# <etag:etag>ETag</etag:etag>
|
139
|
+
# <content type="type">
|
140
|
+
# <!-- actual content here -->
|
141
|
+
# </content>
|
142
|
+
# </entry>
|
143
|
+
#
|
144
|
+
# @abstract
|
145
|
+
# @attr_reader [String] uuid The UUID of the object contained in the entry.
|
146
|
+
# @attr_reader [Time] published The time at which the entry was published.
|
147
|
+
# @attr_reader [URI::HTTPS] href The URL of the object itself.
|
148
|
+
# @attr_reader [String] etag The entity tag of the entry.
|
149
|
+
# @attr_reader [String] content_type The content type of the object contained in the entry.
|
150
|
+
class AbstractRest < AbstractNonRest
|
151
|
+
attr_reader :uuid, :published, :href, :etag, :content_type
|
152
|
+
|
153
|
+
def initialize(entry)
|
154
|
+
@uuid = entry.elements["id"]&.text
|
155
|
+
@published = Time.xmlschema(entry.elements["published"]&.text)
|
156
|
+
link = entry.elements["link[@rel='SELF']"]
|
157
|
+
@href = URI(link.attributes["href"]) unless link.nil?
|
158
|
+
@etag = entry.elements["etag:etag"]&.text&.strip
|
159
|
+
content = entry.elements["content"]
|
160
|
+
@content_type = content.attributes["type"]
|
161
|
+
super(content.elements.first)
|
88
162
|
end
|
89
163
|
end
|
90
164
|
|
@@ -97,9 +171,7 @@ module IbmPowerHmc
|
|
97
171
|
}.freeze
|
98
172
|
|
99
173
|
def managed_systems_uuids
|
100
|
-
|
101
|
-
extract_uuid_from_href(link.attributes["href"])
|
102
|
-
end.compact
|
174
|
+
uuids_from_links("ManagedSystems")
|
103
175
|
end
|
104
176
|
end
|
105
177
|
|
@@ -121,15 +193,19 @@ module IbmPowerHmc
|
|
121
193
|
}.freeze
|
122
194
|
|
123
195
|
def lpars_uuids
|
124
|
-
|
125
|
-
extract_uuid_from_href(link.attributes["href"])
|
126
|
-
end.compact
|
196
|
+
uuids_from_links("AssociatedLogicalPartitions")
|
127
197
|
end
|
128
198
|
|
129
199
|
def vioses_uuids
|
130
|
-
|
131
|
-
|
132
|
-
|
200
|
+
uuids_from_links("AssociatedVirtualIOServers")
|
201
|
+
end
|
202
|
+
|
203
|
+
def vswitches_uuids
|
204
|
+
uuids_from_links("AssociatedSystemIOConfiguration/AssociatedSystemVirtualNetwork/VirtualSwitches")
|
205
|
+
end
|
206
|
+
|
207
|
+
def networks_uuids
|
208
|
+
uuids_from_links("AssociatedSystemIOConfiguration/AssociatedSystemVirtualNetwork/VirtualNetworks")
|
133
209
|
end
|
134
210
|
end
|
135
211
|
|
@@ -144,23 +220,125 @@ module IbmPowerHmc
|
|
144
220
|
:dedicated => "PartitionProcessorConfiguration/HasDedicatedProcessors",
|
145
221
|
:rmc_state => "ResourceMonitoringControlState",
|
146
222
|
:rmc_ipaddr => "ResourceMonitoringIPAddress",
|
147
|
-
:
|
223
|
+
:os => "OperatingSystemVersion",
|
224
|
+
:ref_code => "ReferenceCode",
|
225
|
+
:procs => "PartitionProcessorConfiguration/CurrentDedicatedProcessorConfiguration/CurrentProcessors",
|
226
|
+
:proc_units => "PartitionProcessorConfiguration/CurrentSharedProcessorConfiguration/CurrentProcessingUnits",
|
227
|
+
:vprocs => "PartitionProcessorConfiguration/CurrentSharedProcessorConfiguration/AllocatedVirtualProcessors"
|
148
228
|
}.freeze
|
149
229
|
|
150
230
|
def sys_uuid
|
151
|
-
sys_href =
|
231
|
+
sys_href = singleton("AssociatedManagedSystem", "href")
|
152
232
|
extract_uuid_from_href(sys_href)
|
153
233
|
end
|
234
|
+
|
235
|
+
def net_adap_uuids
|
236
|
+
uuids_from_links("ClientNetworkAdapters")
|
237
|
+
end
|
238
|
+
|
239
|
+
def sriov_elp_uuids
|
240
|
+
uuids_from_links("SRIOVEthernetLogicalPorts")
|
241
|
+
end
|
242
|
+
|
243
|
+
def name=(name)
|
244
|
+
xml.elements[ATTRS[:name]].text = name
|
245
|
+
@name = name
|
246
|
+
end
|
154
247
|
end
|
155
248
|
|
156
249
|
# Logical Partition information
|
157
250
|
class LogicalPartition < BasePartition
|
251
|
+
def vnic_dedicated_uuids
|
252
|
+
uuids_from_links("DedicatedVirtualNICs")
|
253
|
+
end
|
158
254
|
end
|
159
255
|
|
160
256
|
# VIOS information
|
161
257
|
class VirtualIOServer < BasePartition
|
162
258
|
end
|
163
259
|
|
260
|
+
# Virtual Switch information
|
261
|
+
class VirtualSwitch < AbstractRest
|
262
|
+
ATTRS = {
|
263
|
+
:id => "SwitchID",
|
264
|
+
:mode => "SwitchMode",
|
265
|
+
:name => "SwitchName"
|
266
|
+
}.freeze
|
267
|
+
|
268
|
+
def sys_uuid
|
269
|
+
href.path.split('/')[-3]
|
270
|
+
end
|
271
|
+
|
272
|
+
def networks_uuids
|
273
|
+
uuids_from_links("VirtualNetworks")
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
# Virtual Network information
|
278
|
+
class VirtualNetwork < AbstractRest
|
279
|
+
ATTRS = {
|
280
|
+
:name => "NetworkName",
|
281
|
+
:vlan_id => "NetworkVLANID",
|
282
|
+
:vswitch_id => "VswitchID",
|
283
|
+
:tagged => "TaggedNetwork"
|
284
|
+
}.freeze
|
285
|
+
|
286
|
+
def vswitch_uuid
|
287
|
+
href = singleton("AssociatedSwitch", "href")
|
288
|
+
extract_uuid_from_href(href)
|
289
|
+
end
|
290
|
+
|
291
|
+
def lpars_uuids
|
292
|
+
uuids_from_links("ConnectedPartitions")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
# Virtual I/O Adapter information
|
297
|
+
class VirtualIOAdapter < AbstractRest
|
298
|
+
ATTRS = {
|
299
|
+
:type => "AdapterType", # "Server", "Client", "Unknown"
|
300
|
+
:location => "LocationCode",
|
301
|
+
:slot => "VirtualSlotNumber",
|
302
|
+
:required => "RequiredAdapter"
|
303
|
+
}.freeze
|
304
|
+
end
|
305
|
+
|
306
|
+
# Virtual Ethernet Adapter information
|
307
|
+
class VirtualEthernetAdapter < VirtualIOAdapter
|
308
|
+
ATTRS = ATTRS.merge({
|
309
|
+
:macaddr => "MACAddress",
|
310
|
+
:vswitch_id => "VirtualSwitchID",
|
311
|
+
:vlan_id => "PortVLANID",
|
312
|
+
:location => "LocationCode"
|
313
|
+
}.freeze)
|
314
|
+
|
315
|
+
def vswitch_uuid
|
316
|
+
uuids_from_links("AssociatedVirtualSwitch").first
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# Client Network Adapter information
|
321
|
+
class ClientNetworkAdapter < VirtualEthernetAdapter
|
322
|
+
def networks_uuids
|
323
|
+
uuids_from_links("VirtualNetworks")
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class SRIOVEthernetLogicalPort < AbstractRest
|
328
|
+
ATTRS = {
|
329
|
+
:macaddr => "MACAddress",
|
330
|
+
:location => "LocationCode"
|
331
|
+
}.freeze
|
332
|
+
end
|
333
|
+
|
334
|
+
class VirtualNICDedicated < AbstractRest
|
335
|
+
ATTRS = {
|
336
|
+
:macaddr => "Details/MACAddress",
|
337
|
+
:slot => "VirtualSlotNumber",
|
338
|
+
:location => "DynamicReconfigurationConnectorName"
|
339
|
+
}.freeze
|
340
|
+
end
|
341
|
+
|
164
342
|
# HMC Event
|
165
343
|
class Event < AbstractRest
|
166
344
|
ATTRS = {
|
@@ -191,9 +369,9 @@ module IbmPowerHmc
|
|
191
369
|
|
192
370
|
def results
|
193
371
|
results = {}
|
194
|
-
xml.each_element("Results/JobParameter") do |
|
195
|
-
name =
|
196
|
-
value =
|
372
|
+
xml.each_element("Results/JobParameter") do |jobparam|
|
373
|
+
name = jobparam.elements["ParameterName"]&.text&.strip
|
374
|
+
value = jobparam.elements["ParameterValue"]&.text&.strip
|
197
375
|
results[name] = value unless name.nil?
|
198
376
|
end
|
199
377
|
results
|
data/lib/ibm_power_hmc/pcm.rb
CHANGED
File without changes
|
data/lib/ibm_power_hmc.rb
CHANGED
@@ -7,8 +7,8 @@ require "ibm_power_hmc/version"
|
|
7
7
|
|
8
8
|
# Module for IBM HMC Rest API Client
|
9
9
|
module IbmPowerHmc
|
10
|
-
require_relative "./ibm_power_hmc/parser
|
11
|
-
require_relative "./ibm_power_hmc/job
|
12
|
-
require_relative "./ibm_power_hmc/connection
|
13
|
-
require_relative "./ibm_power_hmc/pcm
|
10
|
+
require_relative "./ibm_power_hmc/parser"
|
11
|
+
require_relative "./ibm_power_hmc/job"
|
12
|
+
require_relative "./ibm_power_hmc/connection"
|
13
|
+
require_relative "./ibm_power_hmc/pcm"
|
14
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_power_hmc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IBM Power
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
27
|
description: A Ruby gem for interacting with the IBM Hardware Management Console (HMC).
|
28
|
-
email:
|
28
|
+
email:
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- ".rubocop_local.yml"
|
36
36
|
- CHANGELOG.md
|
37
37
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
38
|
- LICENSE
|
40
39
|
- README.md
|
41
40
|
- Rakefile
|
@@ -56,7 +55,7 @@ metadata:
|
|
56
55
|
homepage_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby
|
57
56
|
source_code_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby
|
58
57
|
changelog_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby/blob/master/CHANGELOG.md
|
59
|
-
post_install_message:
|
58
|
+
post_install_message:
|
60
59
|
rdoc_options: []
|
61
60
|
require_paths:
|
62
61
|
- lib
|
@@ -71,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
70
|
- !ruby/object:Gem::Version
|
72
71
|
version: '0'
|
73
72
|
requirements: []
|
74
|
-
rubygems_version: 3.1.
|
75
|
-
signing_key:
|
73
|
+
rubygems_version: 3.1.4
|
74
|
+
signing_key:
|
76
75
|
specification_version: 4
|
77
76
|
summary: IBM Power HMC Ruby gem.
|
78
77
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ibm_power_hmc (0.1.0)
|
5
|
-
rest-client (~> 2.1)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
domain_name (0.5.20190701)
|
11
|
-
unf (>= 0.0.5, < 1.0.0)
|
12
|
-
http-accept (1.7.0)
|
13
|
-
http-cookie (1.0.4)
|
14
|
-
domain_name (~> 0.5)
|
15
|
-
mime-types (3.3.1)
|
16
|
-
mime-types-data (~> 3.2015)
|
17
|
-
mime-types-data (3.2021.0704)
|
18
|
-
netrc (0.11.0)
|
19
|
-
rake (12.3.3)
|
20
|
-
rest-client (2.1.0)
|
21
|
-
http-accept (>= 1.7.0, < 2.0)
|
22
|
-
http-cookie (>= 1.0.2, < 2.0)
|
23
|
-
mime-types (>= 1.16, < 4.0)
|
24
|
-
netrc (~> 0.8)
|
25
|
-
unf (0.1.4)
|
26
|
-
unf_ext
|
27
|
-
unf_ext (0.0.7.7)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
ibm_power_hmc!
|
34
|
-
rake (~> 12.0)
|
35
|
-
|
36
|
-
BUNDLED WITH
|
37
|
-
2.1.4
|