ibm_power_hmc 0.1.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aae673197b8e5426c2f75250ef521db9d7e8eed79a20c70089612a10d189cfc
4
- data.tar.gz: f7b5cd95629fedf835a97eebd33874edf777527cb8af2c4c5ebdbaaf9364d4d8
3
+ metadata.gz: 2c866478ebd950e9570ce2983d62e90b15fdc27163ea77f3b3f5873138b57cf9
4
+ data.tar.gz: c58488b78a699e4d0f1fc48c43d41db03f9df7c20f861d29e37d80375e8068a2
5
5
  SHA512:
6
- metadata.gz: 793385e1153eff3f9d4bdb8eafe62365a92f0d7fcde75452c1327c36de86b99b2ffd011bf05a57ec9101b4d2d6e84139bc4e86e6cb83347aadef1f0fe5e10b1c
7
- data.tar.gz: 3eedcfd6693b0ac13c725488c1f13bb6433e94b136eaebf1c48f4118582b7ed937ad0e6fe1d06f8c74d209eb67f885e181cc26b7b60683f837628f9fc5ed4f3c
6
+ metadata.gz: 8201481418ec67876a0298d8785ca23a7f2e366a4765ddda8e98024fa71a97a79932661d920090b033da9958c3859460865bb56b7379058e02a9d4f688dab523
7
+ data.tar.gz: cfee7c90c9c22149358b17cf861df4d31d757dde93cf5a30c1196f7957fe48d28bb636643bfbed99238b18215d2048d61c85067b66c8d481bc7678d3fe5ab112
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /Gemfile.lock
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
data/.rubocop_local.yml CHANGED
@@ -2,6 +2,8 @@ AllCops:
2
2
  Exclude:
3
3
  - '*.gemspec'
4
4
  Layout/HashAlignment:
5
- EnforcedHashRocketStyle: key
5
+ Enabled: false
6
6
  Style/ConditionalAssignment:
7
- EnforcedStyle: assign_inside_condition
7
+ Enabled: false
8
+ Style/OptionalBooleanParameter:
9
+ Enabled: false
data/README.md CHANGED
@@ -42,6 +42,12 @@ puts hmc.name
42
42
  puts hmc.version
43
43
  ```
44
44
 
45
+ Retrieving managed systems that are powered on:
46
+
47
+ ```ruby
48
+ hc.managed_systems("State" => "operating")
49
+ ```
50
+
45
51
  Listing the logical partitions and virtual I/O servers of each managed system:
46
52
 
47
53
  ```ruby
@@ -2,24 +2,21 @@
2
2
 
3
3
  # Module for IBM HMC Rest API Client
4
4
  module IbmPowerHmc
5
- require_relative 'pcm.rb'
6
-
7
5
  class Error < StandardError; end
8
6
 
9
7
  ##
10
8
  # HMC REST Client connection.
11
9
  class Connection
12
10
  ##
13
- # @!method initialize(host:, username: "hscroot", password:, port: 12_443, validate_ssl: true)
11
+ # @!method initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true)
14
12
  # Create a new HMC connection.
15
13
  #
16
14
  # @param host [String] Hostname of the HMC.
17
- # @param username [String] User name.
18
15
  # @param password [String] Password.
16
+ # @param username [String] User name.
19
17
  # @param port [Integer] TCP port number.
20
18
  # @param validate_ssl [Boolean] Verify SSL certificates.
21
- def initialize(host:, username: "hscroot", password:, port: 12_443, validate_ssl: true)
22
- # Damien: use URI::HTTPS
19
+ def initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true)
23
20
  @hostname = "#{host}:#{port}"
24
21
  @username = username
25
22
  @password = password
@@ -37,10 +34,8 @@ module IbmPowerHmc
37
34
  :content_type => "application/vnd.ibm.powervm.web+xml; type=LogonRequest"
38
35
  }
39
36
  doc = REXML::Document.new("")
40
- doc.add_element("LogonRequest", {
41
- "xmlns" => "http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/",
42
- "schemaVersion" => "V1_1_0"
43
- })
37
+ doc.add_element("LogonRequest", "schemaVersion" => "V1_1_0")
38
+ doc.root.add_namespace("http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/")
44
39
  doc.root.add_element("UserID").text = @username
45
40
  doc.root.add_element("Password").text = @password
46
41
 
@@ -69,15 +64,6 @@ module IbmPowerHmc
69
64
  @api_session_token = nil
70
65
  end
71
66
 
72
- def parse_feed(doc, myclass)
73
- objs = []
74
- doc.each_element("feed/entry") do |entry|
75
- objs << myclass.new(entry)
76
- end
77
- objs
78
- end
79
- private :parse_feed
80
-
81
67
  ##
82
68
  # @!method management_console
83
69
  # Retrieve information about the management console.
@@ -85,20 +71,20 @@ module IbmPowerHmc
85
71
  def management_console
86
72
  method_url = "/rest/api/uom/ManagementConsole"
87
73
  response = request(:get, method_url)
88
- doc = REXML::Document.new(response.body)
89
74
  # This request returns a feed with a single entry.
90
- parse_feed(doc, ManagementConsole).first
75
+ FeedParser.new(response.body).objects(:ManagementConsole).first
91
76
  end
92
77
 
93
78
  ##
94
- # @!method managed_systems
79
+ # @!method managed_systems(search = {})
95
80
  # Retrieve the list of systems managed by the HMC.
81
+ # @param search [Hash] The optional property name and value to match.
96
82
  # @return [Array<IbmPowerHmc::ManagedSystem>] The list of managed systems.
97
- def managed_systems
83
+ def managed_systems(search = {})
98
84
  method_url = "/rest/api/uom/ManagedSystem"
85
+ search.each { |key, value| method_url += "/search/(#{key}==#{value})" }
99
86
  response = request(:get, method_url)
100
- doc = REXML::Document.new(response.body)
101
- parse_feed(doc, ManagedSystem)
87
+ FeedParser.new(response.body).objects(:ManagedSystem)
102
88
  end
103
89
 
104
90
  ##
@@ -106,31 +92,30 @@ module IbmPowerHmc
106
92
  # Retrieve information about a managed system.
107
93
  # @param sys_uuid [String] The UUID of the managed system.
108
94
  # @param group_name [String] The extended group attributes.
109
- # @return [IbmPowerHmc::ManagedSystem] The logical partition.
95
+ # @return [IbmPowerHmc::ManagedSystem] The managed system.
110
96
  def managed_system(sys_uuid, group_name = nil)
111
97
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}"
112
98
  method_url += "?group=#{group_name}" unless group_name.nil?
113
99
 
114
100
  response = request(:get, method_url)
115
- doc = REXML::Document.new(response.body)
116
- entry = doc.elements["entry"]
117
- ManagedSystem.new(entry)
101
+ Parser.new(response.body).object(:ManagedSystem)
118
102
  end
119
103
 
120
104
  ##
121
- # @!method lpars(sys_uuid = nil)
105
+ # @!method lpars(sys_uuid = nil, search = {})
122
106
  # Retrieve the list of logical partitions managed by the HMC.
123
107
  # @param sys_uuid [String] The UUID of the managed system.
108
+ # @param search [Hash] The optional property name and value to match.
124
109
  # @return [Array<IbmPowerHmc::LogicalPartition>] The list of logical partitions.
125
- def lpars(sys_uuid = nil)
110
+ def lpars(sys_uuid = nil, search = {})
126
111
  if sys_uuid.nil?
127
112
  method_url = "/rest/api/uom/LogicalPartition"
113
+ search.each { |key, value| method_url += "/search/(#{key}==#{value})" }
128
114
  else
129
115
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/LogicalPartition"
130
116
  end
131
117
  response = request(:get, method_url)
132
- doc = REXML::Document.new(response.body)
133
- parse_feed(doc, LogicalPartition)
118
+ FeedParser.new(response.body).objects(:LogicalPartition)
134
119
  end
135
120
 
136
121
  ##
@@ -149,15 +134,14 @@ module IbmPowerHmc
149
134
  method_url += "?group=#{group_name}" unless group_name.nil?
150
135
 
151
136
  response = request(:get, method_url)
152
- doc = REXML::Document.new(response.body)
153
- entry = doc.elements["entry"]
154
- LogicalPartition.new(entry)
137
+ Parser.new(response.body).object(:LogicalPartition)
155
138
  end
156
139
 
157
140
  ##
158
141
  # @!method lpar_quick_property(lpar_uuid, property_name)
159
142
  # Retrieve a quick property of a logical partition.
160
143
  # @param lpar_uuid [String] The UUID of the logical partition.
144
+ # @param property_name [String] The quick property name.
161
145
  # @return [String] The quick property value.
162
146
  def lpar_quick_property(lpar_uuid, property_name)
163
147
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/quick/#{property_name}"
@@ -167,19 +151,30 @@ module IbmPowerHmc
167
151
  end
168
152
 
169
153
  ##
170
- # @!method vioses(sys_uuid = nil)
154
+ # @!method rename_lpar(lpar_uuid, new_name)
155
+ # Rename a logical partition.
156
+ # @param lpar_uuid [String] The UUID of the logical partition.
157
+ # @param new_name [String] The new name of the logical partition.
158
+ def rename_lpar(lpar_uuid, new_name)
159
+ method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"
160
+ modify_object(method_url) { |lpar| lpar.name = new_name }
161
+ end
162
+
163
+ ##
164
+ # @!method vioses(sys_uuid = nil, search = {})
171
165
  # Retrieve the list of virtual I/O servers managed by the HMC.
172
166
  # @param sys_uuid [String] The UUID of the managed system.
167
+ # @param search [Hash] The optional property name and value to match.
173
168
  # @return [Array<IbmPowerHmc::VirtualIOServer>] The list of virtual I/O servers.
174
- def vioses(sys_uuid = nil)
169
+ def vioses(sys_uuid = nil, search = {})
175
170
  if sys_uuid.nil?
176
171
  method_url = "/rest/api/uom/VirtualIOServer"
172
+ search.each { |key, value| method_url += "/search/(#{key}==#{value})" }
177
173
  else
178
174
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualIOServer"
179
175
  end
180
176
  response = request(:get, method_url)
181
- doc = REXML::Document.new(response.body)
182
- parse_feed(doc, VirtualIOServer)
177
+ FeedParser.new(response.body).objects(:VirtualIOServer)
183
178
  end
184
179
 
185
180
  ##
@@ -198,9 +193,73 @@ module IbmPowerHmc
198
193
  method_url += "?group=#{group_name}" unless group_name.nil?
199
194
 
200
195
  response = request(:get, method_url)
201
- doc = REXML::Document.new(response.body)
202
- entry = doc.elements["entry"]
203
- VirtualIOServer.new(entry)
196
+ Parser.new(response.body).object(:VirtualIOServer)
197
+ end
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)
204
263
  end
205
264
 
206
265
  ##
@@ -221,9 +280,7 @@ module IbmPowerHmc
221
280
  ##
222
281
  # @!method poweroff_lpar(lpar_uuid, params = {}, sync = true)
223
282
  # Power off a logical partition.
224
- # @param lpar_uuid [String] The UUID of the logical partition.
225
- # @param params [Hash] Job parameters.
226
- # @param sync [Boolean] Start the job and wait for its completion.
283
+ # @param (see #poweron_lpar)
227
284
  # @return [IbmPowerHmc::HmcJob] The HMC job.
228
285
  def poweroff_lpar(lpar_uuid, params = {}, sync = true)
229
286
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/PowerOff"
@@ -251,9 +308,7 @@ module IbmPowerHmc
251
308
  ##
252
309
  # @!method poweroff_vios(vios_uuid, params = {}, sync = true)
253
310
  # Power off a virtual I/O server.
254
- # @param vios_uuid [String] The UUID of the virtual I/O server.
255
- # @param params [Hash] Job parameters.
256
- # @param sync [Boolean] Start the job and wait for its completion.
311
+ # @param (see #poweron_vios)
257
312
  # @return [IbmPowerHmc::HmcJob] The HMC job.
258
313
  def poweroff_vios(vios_uuid, params = {}, sync = true)
259
314
  method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/do/PowerOff"
@@ -281,9 +336,7 @@ module IbmPowerHmc
281
336
  ##
282
337
  # @!method poweroff_managed_system(sys_uuid, params = {}, sync = true)
283
338
  # Power off a managed system.
284
- # @param sys_uuid [String] The UUID of the managed system.
285
- # @param params [Hash] Job parameters.
286
- # @param sync [Boolean] Start the job and wait for its completion.
339
+ # @param (see #poweron_managed_system)
287
340
  # @return [IbmPowerHmc::HmcJob] The HMC job.
288
341
  def poweroff_managed_system(sys_uuid, params = {}, sync = true)
289
342
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/do/PowerOff"
@@ -293,6 +346,21 @@ module IbmPowerHmc
293
346
  job
294
347
  end
295
348
 
349
+ ##
350
+ # @!method remove_connection(hmc_uuid, sys_uuid, sync = true)
351
+ # Remove a managed system from the management console.
352
+ # @param hmc_uuid [String] The UUID of the management console.
353
+ # @param sys_uuid [String] The UUID of the managed system.
354
+ # @param sync [Boolean] Start the job and wait for its completion.
355
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
356
+ def remove_connection(hmc_uuid, sys_uuid, sync = true)
357
+ method_url = "/rest/api/uom/ManagementConsole/#{hmc_uuid}/ManagedSystem/#{sys_uuid}/do/RemoveConnection"
358
+
359
+ job = HmcJob.new(self, method_url, "RemoveConnection", "ManagedSystem")
360
+ job.run if sync
361
+ job
362
+ end
363
+
296
364
  ##
297
365
  # @!method cli_run(hmc_uuid, cmd, sync = true)
298
366
  # Run a CLI command on the HMC as a job.
@@ -326,8 +394,7 @@ module IbmPowerHmc
326
394
  # No need to sleep as the HMC already waits a bit before returning 204
327
395
  break if response.code != 204 || !wait
328
396
  end
329
- doc = REXML::Document.new(response.body)
330
- parse_feed(doc, Event)
397
+ FeedParser.new(response.body).objects(:Event)
331
398
  end
332
399
 
333
400
  ##
@@ -356,10 +423,8 @@ module IbmPowerHmc
356
423
 
357
424
  # Try to parse body as an HttpErrorResponse
358
425
  unless err.response.nil?
359
- doc = REXML::Document.new(err.response.body)
360
- entry = doc.elements["entry"]
361
- unless entry.nil?
362
- resp = HttpErrorResponse.new(entry)
426
+ resp = Parser.new(err.response.body).object(:HttpErrorResponse)
427
+ unless resp.nil?
363
428
  @uri = resp.uri
364
429
  @reason = resp.reason
365
430
  @message = resp.message
@@ -368,7 +433,7 @@ module IbmPowerHmc
368
433
  end
369
434
 
370
435
  def to_s
371
- "msg=#{@message} status=#{@status} reason=#{@reason} uri=#{@uri}"
436
+ "msg=\"#{@message}\" status=\"#{@status}\" reason=\"#{@reason}\" uri=#{@uri}"
372
437
  end
373
438
  end
374
439
 
@@ -386,7 +451,7 @@ module IbmPowerHmc
386
451
  # Check for relative URLs
387
452
  url = "https://#{@hostname}#{url}" if url.start_with?("/")
388
453
  begin
389
- headers = headers.merge({"X-API-Session" => @api_session_token})
454
+ headers = headers.merge("X-API-Session" => @api_session_token)
390
455
  RestClient::Request.execute(
391
456
  :method => method,
392
457
  :url => url,
@@ -405,5 +470,53 @@ module IbmPowerHmc
405
470
  raise HttpError.new(e), "REST request failed"
406
471
  end
407
472
  end
473
+
474
+ private
475
+
476
+ # @!method modify_object(method_url, headers = {}, attempts = 5)
477
+ # Modify an object at a specified URI.
478
+ # @param method_url [String] The URL of the object to modify.
479
+ # @param headers [Hash] HTTP headers.
480
+ # @param attempts [Integer] Maximum number of retries.
481
+ # @yield [obj] The object to modify.
482
+ # @yieldparam obj [IbmPowerHmc::AbstractRest] The object to modify.
483
+ def modify_object(method_url, headers = {}, attempts = 5)
484
+ while attempts > 0
485
+ response = request(:get, method_url)
486
+ obj = Parser.new(response.body).object
487
+
488
+ yield obj
489
+
490
+ # Use ETag to ensure object has not changed.
491
+ headers = headers.merge("If-Match" => obj.etag, :content_type => obj.content_type)
492
+ begin
493
+ request(:post, method_url, headers, obj.xml.to_s)
494
+ break
495
+ rescue HttpError => e
496
+ attempts -= 1
497
+ # Will get 412 ("Precondition Failed") if ETag mismatches
498
+ raise if e.status != 412 || attempts == 0
499
+ end
500
+ end
501
+ end
502
+
503
+ ##
504
+ # @!method network_adapter(vm_type, lpar_uuid, netadap_uuid)
505
+ # Retrieve one or all virtual ethernet network adapters attached to a Logical Partition or a Virtual I/O Server.
506
+ # @param vm_type [String] "LogicalPartition" or "VirtualIOServer".
507
+ # @param lpar_uuid [String] UUID of the Logical Partition or the Virtual I/O Server.
508
+ # @param netadap_uuid [String] UUID of the adapter to match (returns all adapters if nil).
509
+ # @return [Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter] The list of network adapters.
510
+ def network_adapter(vm_type, lpar_uuid, netadap_uuid)
511
+ if netadap_uuid.nil?
512
+ method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/ClientNetworkAdapter"
513
+ response = request(:get, method_url)
514
+ FeedParser.new(response.body).objects(:ClientNetworkAdapter)
515
+ else
516
+ method_url = "/rest/api/uom/#{vm_type}/#{lpar_uuid}/ClientNetworkAdapter/#{netadap_uuid}"
517
+ response = request(:get, method_url)
518
+ Parser.new(response.body).object(:ClientNetworkAdapter)
519
+ end
520
+ end
408
521
  end
409
522
  end
@@ -24,7 +24,7 @@ module IbmPowerHmc
24
24
  end
25
25
 
26
26
  ##
27
- # @!method status
27
+ # @!method start
28
28
  # Start the job asynchronously.
29
29
  # @return [String] The ID of the job.
30
30
  def start
@@ -32,25 +32,22 @@ module IbmPowerHmc
32
32
  :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest"
33
33
  }
34
34
  doc = REXML::Document.new("")
35
- doc.add_element("JobRequest:JobRequest", {
36
- "xmlns:JobRequest" => "http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/",
37
- "xmlns" => "http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/",
38
- "schemaVersion" => "V1_1_0"
39
- })
40
- op = doc.root.add_element("RequestedOperation", {"schemaVersion" => "V1_1_0"})
35
+ doc.add_element("JobRequest:JobRequest", "schemaVersion" => "V1_1_0")
36
+ doc.root.add_namespace("http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/")
37
+ doc.root.add_namespace("JobRequest", "http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/")
38
+ op = doc.root.add_element("RequestedOperation", "schemaVersion" => "V1_1_0")
41
39
  op.add_element("OperationName").text = @operation
42
40
  op.add_element("GroupName").text = @group
43
- # Damien: ProgressType?
44
- jobparams = doc.root.add_element("JobParameters", {"schemaVersion" => "V1_1_0"})
41
+
42
+ jobparams = doc.root.add_element("JobParameters", "schemaVersion" => "V1_1_0")
45
43
  @params.each do |key, value|
46
- jobparam = jobparams.add_element("JobParameter", {"schemaVersion" => "V1_1_0"})
44
+ jobparam = jobparams.add_element("JobParameter", "schemaVersion" => "V1_1_0")
47
45
  jobparam.add_element("ParameterName").text = key
48
46
  jobparam.add_element("ParameterValue").text = value
49
47
  end
50
48
  response = @conn.request(:put, @method_url, headers, doc.to_s)
51
- doc = REXML::Document.new(response.body)
52
- info = doc.root.elements["content/JobResponse:JobResponse"]
53
- @id = info.elements["JobID"].text
49
+ jobresp = Parser.new(response.body).object(:JobResponse)
50
+ @id = jobresp.id
54
51
  end
55
52
 
56
53
  # @return [Hash] The job results returned by the HMC.
@@ -68,20 +65,9 @@ module IbmPowerHmc
68
65
  :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest"
69
66
  }
70
67
  response = @conn.request(:get, method_url, headers)
71
- doc = REXML::Document.new(response.body)
72
- info = doc.root.elements["content/JobResponse:JobResponse"]
73
- status = info.elements["Status"].text
74
- # Damien: also retrieve "ResponseException/Message"?
75
-
76
- # Gather Job results returned by the HMC.
77
- @results = {}
78
- info.each_element("Results/JobParameter") do |result|
79
- name = result.elements["ParameterName"].text.strip
80
- value = result.elements["ParameterValue"].text.strip
81
- @results[name] = value
82
- end
83
-
84
- status
68
+ jobresp = Parser.new(response.body).object(:JobResponse)
69
+ @results = jobresp.results
70
+ jobresp.status
85
71
  end
86
72
 
87
73
  ##
@@ -112,8 +98,7 @@ module IbmPowerHmc
112
98
  # @return [String] The status of the job.
113
99
  def run(timeout = 120, poll_interval = 0)
114
100
  start
115
- status = wait(timeout, poll_interval)
116
- status
101
+ wait(timeout, poll_interval)
117
102
  ensure
118
103
  delete if defined?(@id)
119
104
  end
@@ -0,0 +1,358 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'uri'
5
+
6
+ module IbmPowerHmc
7
+ ##
8
+ # Generic parser for HMC K2 XML responses.
9
+ class Parser
10
+ def initialize(body)
11
+ @doc = REXML::Document.new(body)
12
+ end
13
+
14
+ ##
15
+ # @!method entry
16
+ # Return the first K2 entry element in the response.
17
+ # @return [REXML::Element, nil] The first entry element.
18
+ def entry
19
+ @doc.elements["entry"]
20
+ end
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.
27
+ def object(filter_type = nil)
28
+ self.class.to_obj(entry, filter_type)
29
+ end
30
+
31
+ def self.to_obj(entry, filter_type = nil)
32
+ return if entry.nil?
33
+
34
+ content = entry.elements["content[@type]"]
35
+ return if content.nil?
36
+
37
+ type = content.attributes["type"].split("=").last
38
+ return unless filter_type.nil? || filter_type.to_s == type
39
+
40
+ Module.const_get("IbmPowerHmc::#{type}").new(entry)
41
+ end
42
+ end
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>
56
+ class FeedParser < Parser
57
+ def entries
58
+ objs = []
59
+ @doc.each_element("feed/entry") do |entry|
60
+ objs << yield(entry)
61
+ end
62
+ objs
63
+ end
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.
70
+ def objects(filter_type = nil)
71
+ entries do |entry|
72
+ self.class.to_obj(entry, filter_type)
73
+ end.compact
74
+ end
75
+ end
76
+
77
+ private_constant :Parser
78
+ private_constant :FeedParser
79
+
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
85
+ ATTRS = {}.freeze
86
+ attr_reader :xml
87
+
88
+ def initialize(xml)
89
+ @xml = xml
90
+ self.class::ATTRS.each { |varname, xpath| define_attr(varname, xpath) }
91
+ end
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.
98
+ def define_attr(varname, xpath)
99
+ value = singleton(xpath)
100
+ self.class.__send__(:attr_reader, varname)
101
+ instance_variable_set("@#{varname}", value)
102
+ end
103
+ private :define_attr
104
+
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]
117
+ end
118
+
119
+ def extract_uuid_from_href(href)
120
+ URI(href).path.split('/').last
121
+ end
122
+ end
123
+
124
+ ##
125
+ # HMC generic K2 REST object.
126
+ # Encapsulate data for a single REST object.
127
+ # The XML looks like this:
128
+ # <entry>
129
+ # <id>uuid</id>
130
+ # <published>timestamp</published>
131
+ # <link rel="SELF" href="https://..."/>
132
+ # <etag:etag>ETag</etag:etag>
133
+ # <content type="type">
134
+ # <!-- actual content here -->
135
+ # </content>
136
+ # </entry>
137
+ #
138
+ # @abstract
139
+ # @attr_reader [String] uuid The UUID of the object contained in the entry.
140
+ # @attr_reader [Time] published The time at which the entry was published.
141
+ # @attr_reader [URI::HTTPS] href The URL of the object itself.
142
+ # @attr_reader [String] etag The entity tag of the entry.
143
+ # @attr_reader [String] content_type The content type of the object contained in the entry.
144
+ class AbstractRest < AbstractNonRest
145
+ attr_reader :uuid, :published, :href, :etag, :content_type
146
+
147
+ def initialize(entry)
148
+ @uuid = entry.elements["id"]&.text
149
+ @published = Time.xmlschema(entry.elements["published"]&.text)
150
+ link = entry.elements["link[@rel='SELF']"]
151
+ @href = URI(link.attributes["href"]) unless link.nil?
152
+ @etag = entry.elements["etag:etag"]&.text&.strip
153
+ content = entry.elements["content"]
154
+ @content_type = content.attributes["type"]
155
+ super(content.elements.first)
156
+ end
157
+ end
158
+
159
+ # HMC information
160
+ class ManagementConsole < AbstractRest
161
+ ATTRS = {
162
+ :name => "ManagementConsoleName",
163
+ :build_level => "VersionInfo/BuildLevel",
164
+ :version => "BaseVersion"
165
+ }.freeze
166
+
167
+ def managed_systems_uuids
168
+ xml.get_elements("ManagedSystems/link").map do |link|
169
+ extract_uuid_from_href(link.attributes["href"])
170
+ end.compact
171
+ end
172
+ end
173
+
174
+ # Managed System information
175
+ class ManagedSystem < AbstractRest
176
+ ATTRS = {
177
+ :name => "SystemName",
178
+ :state => "State",
179
+ :hostname => "Hostname",
180
+ :ipaddr => "PrimaryIPAddress",
181
+ :fwversion => "SystemFirmware",
182
+ :memory => "AssociatedSystemMemoryConfiguration/InstalledSystemMemory",
183
+ :avail_mem => "AssociatedSystemMemoryConfiguration/CurrentAvailableSystemMemory",
184
+ :cpus => "AssociatedSystemProcessorConfiguration/InstalledSystemProcessorUnits",
185
+ :avail_cpus => "AssociatedSystemProcessorConfiguration/CurrentAvailableSystemProcessorUnits",
186
+ :mtype => "MachineTypeModelAndSerialNumber/MachineType",
187
+ :model => "MachineTypeModelAndSerialNumber/Model",
188
+ :serial => "MachineTypeModelAndSerialNumber/SerialNumber"
189
+ }.freeze
190
+
191
+ def lpars_uuids
192
+ xml.get_elements("AssociatedLogicalPartitions/link").map do |link|
193
+ extract_uuid_from_href(link.attributes["href"])
194
+ end.compact
195
+ end
196
+
197
+ def vioses_uuids
198
+ xml.get_elements("AssociatedVirtualIOServers/link").map do |link|
199
+ extract_uuid_from_href(link.attributes["href"])
200
+ end.compact
201
+ end
202
+ end
203
+
204
+ # Common class for LPAR and VIOS
205
+ class BasePartition < AbstractRest
206
+ ATTRS = {
207
+ :name => "PartitionName",
208
+ :id => "PartitionID",
209
+ :state => "PartitionState",
210
+ :type => "PartitionType",
211
+ :memory => "PartitionMemoryConfiguration/CurrentMemory",
212
+ :dedicated => "PartitionProcessorConfiguration/HasDedicatedProcessors",
213
+ :rmc_state => "ResourceMonitoringControlState",
214
+ :rmc_ipaddr => "ResourceMonitoringIPAddress",
215
+ :os => "OperatingSystemVersion",
216
+ :ref_code => "ReferenceCode",
217
+ :procs => "PartitionProcessorConfiguration/CurrentDedicatedProcessorConfiguration/CurrentProcessors",
218
+ :proc_units => "PartitionProcessorConfiguration/CurrentSharedProcessorConfiguration/CurrentProcessingUnits",
219
+ :vprocs => "PartitionProcessorConfiguration/CurrentSharedProcessorConfiguration/AllocatedVirtualProcessors"
220
+ }.freeze
221
+
222
+ def sys_uuid
223
+ sys_href = singleton("AssociatedManagedSystem", "href")
224
+ extract_uuid_from_href(sys_href)
225
+ end
226
+
227
+ def net_adap_uuids
228
+ xml.get_elements("ClientNetworkAdapters/link").map do |link|
229
+ extract_uuid_from_href(link.attributes["href"])
230
+ end.compact
231
+ end
232
+
233
+ def name=(name)
234
+ xml.elements[ATTRS[:name]].text = name
235
+ @name = name
236
+ end
237
+ end
238
+
239
+ # Logical Partition information
240
+ class LogicalPartition < BasePartition
241
+ end
242
+
243
+ # VIOS information
244
+ class VirtualIOServer < BasePartition
245
+ end
246
+
247
+ # Virtual Switch information
248
+ class VirtualSwitch < AbstractRest
249
+ ATTRS = {
250
+ :id => "SwitchID",
251
+ :mode => "SwitchMode",
252
+ :name => "SwitchName"
253
+ }.freeze
254
+
255
+ def sys_uuid
256
+ href.path.split('/')[-3]
257
+ end
258
+
259
+ def networks_uuids
260
+ xml.get_elements("VirtualNetworks/link").map do |link|
261
+ extract_uuid_from_href(link.attributes["href"])
262
+ end.compact
263
+ end
264
+ end
265
+
266
+ # Virtual Network information
267
+ class VirtualNetwork < AbstractRest
268
+ ATTRS = {
269
+ :name => "NetworkName",
270
+ :vlan_id => "NetworkVLANID",
271
+ :vswitch_id => "VswitchID",
272
+ :tagged => "TaggedNetwork"
273
+ }.freeze
274
+
275
+ def vswitch_uuid
276
+ href = singleton("AssociatedSwitch", "href")
277
+ extract_uuid_from_href(href)
278
+ end
279
+
280
+ def lpars_uuids
281
+ xml.get_elements("ConnectedPartitions/link").map do |link|
282
+ extract_uuid_from_href(link.attributes["href"])
283
+ end.compact
284
+ end
285
+ end
286
+
287
+ # Virtual I/O Adapter information
288
+ class VirtualIOAdapter < AbstractRest
289
+ ATTRS = {
290
+ :type => "AdapterType", # "Server", "Client", "Unknown"
291
+ :location => "LocationCode",
292
+ :slot => "VirtualSlotNumber",
293
+ :required => "RequiredAdapter"
294
+ }.freeze
295
+ end
296
+
297
+ # Virtual Ethernet Adapter information
298
+ class VirtualEthernetAdapter < VirtualIOAdapter
299
+ ATTRS = ATTRS.merge({
300
+ :macaddr => "MACAddress",
301
+ :vswitch_id => "VirtualSwitchID",
302
+ :vlan_id => "PortVLANID"
303
+ }.freeze)
304
+
305
+ def vswitch_uuid
306
+ href = singleton("AssociatedVirtualSwitch/link", "href")
307
+ extract_uuid_from_href(href)
308
+ end
309
+ end
310
+
311
+ # Client Network Adapter information
312
+ class ClientNetworkAdapter < VirtualEthernetAdapter
313
+ def networks_uuids
314
+ xml.get_elements("VirtualNetworks/link").map do |link|
315
+ extract_uuid_from_href(link.attributes["href"])
316
+ end.compact
317
+ end
318
+ end
319
+
320
+ # HMC Event
321
+ class Event < AbstractRest
322
+ ATTRS = {
323
+ :id => "EventID",
324
+ :type => "EventType",
325
+ :data => "EventData",
326
+ :detail => "EventDetail"
327
+ }.freeze
328
+ end
329
+
330
+ # Error response from HMC
331
+ class HttpErrorResponse < AbstractRest
332
+ ATTRS = {
333
+ :status => "HTTPStatus",
334
+ :uri => "RequestURI",
335
+ :reason => "ReasonCode",
336
+ :message => "Message"
337
+ }.freeze
338
+ end
339
+
340
+ # Job Response
341
+ class JobResponse < AbstractRest
342
+ ATTRS = {
343
+ :id => "JobID",
344
+ :status => "Status",
345
+ :message => "ResponseException/Message"
346
+ }.freeze
347
+
348
+ def results
349
+ results = {}
350
+ xml.each_element("Results/JobParameter") do |jobparam|
351
+ name = jobparam.elements["ParameterName"]&.text&.strip
352
+ value = jobparam.elements["ParameterValue"]&.text&.strip
353
+ results[name] = value unless name.nil?
354
+ end
355
+ results
356
+ end
357
+ end
358
+ end
@@ -5,26 +5,62 @@ require 'uri'
5
5
 
6
6
  module IbmPowerHmc
7
7
  class Connection
8
+ def pcm_preferences
9
+ method_url = "/rest/api/pcm/preferences"
10
+
11
+ response = request(:get, method_url)
12
+ REXML::Document.new(response.body)
13
+ end
14
+
15
+ ##
16
+ # @!method phyp_metrics(sys_uuid:, start_ts: nil, end_ts: nil, short_term: false)
17
+ # Retrieve PowerVM metrics for a given managed system.
18
+ # @param sys_uuid [String] The managed system UUID.
19
+ # @param start_ts [Time] Start timestamp.
20
+ # @param end_ts [Time] End timestamp.
21
+ # @param short_term [Boolean] Retrieve short term monitor metrics (default to long term).
22
+ # @return [Array<Hash>] The PowerVM metrics for the managed system.
23
+ def phyp_metrics(sys_uuid:, start_ts: nil, end_ts: nil, short_term: false)
24
+ type = short_term ? "ShortTermMonitor" : "LongTermMonitor"
25
+ method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/RawMetrics/#{type}"
26
+ query = {}
27
+ query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
28
+ query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
29
+ method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?
30
+
31
+ response = request(:get, method_url)
32
+ FeedParser.new(response.body).entries do |entry|
33
+ link = entry.elements["link"]
34
+ next if link.nil?
35
+
36
+ href = link.attributes["href"]
37
+ next if href.nil?
38
+
39
+ response = request(:get, href)
40
+ JSON.parse(response.body)
41
+ end.compact
42
+ end
43
+
8
44
  ##
9
- # @!method managed_system_metrics(sys_uuid:, start_ts: nil, end_ts: nil, no_samples: nil)
45
+ # @!method managed_system_metrics(sys_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
10
46
  # Retrieve metrics for a managed system.
11
47
  # @param sys_uuid [String] The managed system UUID.
12
- # @param start_ts [String] Start timestamp.
13
- # @param end_ts [String] End timestamp.
48
+ # @param start_ts [Time] Start timestamp.
49
+ # @param end_ts [Time] End timestamp.
14
50
  # @param no_samples [Integer] Number of samples.
15
- # @return [Array<Hash>] The processed metrics for the managed system.
16
- def managed_system_metrics(sys_uuid:, start_ts: nil, end_ts: nil, no_samples: nil)
17
- method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/ProcessedMetrics"
18
- query = []
19
- query << "StartTS=#{start_ts}" unless start_ts.nil?
20
- query << "EndTS=#{end_ts}" unless end_ts.nil?
21
- query << "NoOfSamples=#{no_samples}" unless no_samples.nil?
22
- method_url += "?" + query.compact.join('&') unless query.empty?
51
+ # @param aggregated [Boolean] Retrieve aggregated metrics (default to Processed).
52
+ # @return [Array<Hash>] The metrics for the managed system.
53
+ def managed_system_metrics(sys_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
54
+ type = aggregated ? "AggregatedMetrics" : "ProcessedMetrics"
55
+ method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/#{type}"
56
+ query = {}
57
+ query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
58
+ query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
59
+ query["NoOfSamples"] = no_samples unless no_samples.nil?
60
+ method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?
23
61
 
24
62
  response = request(:get, method_url)
25
- doc = REXML::Document.new(response.body)
26
- metrics = []
27
- doc.each_element("feed/entry") do |entry|
63
+ FeedParser.new(response.body).entries do |entry|
28
64
  category = entry.elements["category"]
29
65
  next if category.nil?
30
66
 
@@ -37,10 +73,50 @@ module IbmPowerHmc
37
73
  href = link.attributes["href"]
38
74
  next if href.nil?
39
75
 
40
- response = request(:get, href.to_s)
41
- metrics << JSON.parse(response.body)
42
- end
43
- metrics
76
+ response = request(:get, href)
77
+ JSON.parse(response.body)
78
+ end.compact
79
+ end
80
+
81
+ ##
82
+ # @!method lpar_metrics(sys_uuid:, lpar_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
83
+ # Retrieve metrics for a logical partition.
84
+ # @param sys_uuid [String] The managed system UUID.
85
+ # @param lpar_uuid [String] The logical partition UUID.
86
+ # @param start_ts [Time] Start timestamp.
87
+ # @param end_ts [Time] End timestamp.
88
+ # @param no_samples [Integer] Number of samples.
89
+ # @param aggregated [Boolean] Retrieve aggregated metrics (default to Processed).
90
+ # @return [Array<Hash>] The metrics for the logical partition.
91
+ def lpar_metrics(sys_uuid:, lpar_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
92
+ type = aggregated ? "AggregatedMetrics" : "ProcessedMetrics"
93
+ method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/LogicalPartition/#{lpar_uuid}/#{type}"
94
+ query = {}
95
+ query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
96
+ query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
97
+ query["NoOfSamples"] = no_samples unless no_samples.nil?
98
+ method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?
99
+
100
+ response = request(:get, method_url)
101
+ FeedParser(response.body).entries do |entry|
102
+ link = entry.elements["link"]
103
+ next if link.nil?
104
+
105
+ href = link.attributes["href"]
106
+ next if href.nil?
107
+
108
+ response = request(:get, href)
109
+ JSON.parse(response.body)
110
+ end.compact
111
+ end
112
+
113
+ ##
114
+ # @!method format_time(time)
115
+ # Convert ruby time to HMC time format.
116
+ # @param time [Time] The ruby time to convert.
117
+ # @return [String] The time in HMC format.
118
+ def self.format_time(time)
119
+ time.utc.xmlschema
44
120
  end
45
121
  end
46
122
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbmPowerHmc
4
- VERSION = "0.1.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/ibm_power_hmc.rb CHANGED
@@ -7,7 +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/objects.rb"
11
- require_relative "./ibm_power_hmc/job.rb"
12
- require_relative "./ibm_power_hmc/connection.rb"
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"
13
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.1.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IBM Power
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-29 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -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
@@ -45,7 +44,7 @@ files:
45
44
  - lib/ibm_power_hmc.rb
46
45
  - lib/ibm_power_hmc/connection.rb
47
46
  - lib/ibm_power_hmc/job.rb
48
- - lib/ibm_power_hmc/objects.rb
47
+ - lib/ibm_power_hmc/parser.rb
49
48
  - lib/ibm_power_hmc/pcm.rb
50
49
  - lib/ibm_power_hmc/version.rb
51
50
  homepage: http://github.com/IBM/ibm_power_hmc_sdk_ruby
@@ -71,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
70
  - !ruby/object:Gem::Version
72
71
  version: '0'
73
72
  requirements: []
74
- rubygems_version: 3.0.3
73
+ rubygems_version: 3.1.4
75
74
  signing_key:
76
75
  specification_version: 4
77
76
  summary: IBM Power HMC Ruby gem.
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
@@ -1,150 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
-
5
- # Module for IBM HMC Rest API Client
6
- module IbmPowerHmc
7
- # HMC generic object
8
- class HmcObject
9
- attr_reader :uuid, :xml
10
-
11
- def initialize(doc)
12
- @uuid = doc.elements["id"].text
13
- @xml = doc
14
- end
15
-
16
- def get_value(doc, xpath, varname)
17
- value = doc.elements[xpath]
18
- value = value.text unless value.nil?
19
- value = value.strip unless value.nil?
20
- self.class.__send__(:attr_reader, varname)
21
- instance_variable_set("@#{varname}", value)
22
- end
23
-
24
- def get_values(doc, hash)
25
- hash.each do |key, value|
26
- get_value(doc, key, value)
27
- end
28
- end
29
- end
30
-
31
- # HMC information
32
- class ManagementConsole < HmcObject
33
- XMLMAP = {
34
- "ManagementConsoleName" => "name",
35
- "VersionInfo/BuildLevel" => "build_level",
36
- "BaseVersion" => "version"
37
- }.freeze
38
-
39
- def initialize(doc)
40
- super(doc)
41
- info = doc.elements["content/ManagementConsole:ManagementConsole"]
42
- get_values(info, XMLMAP)
43
- end
44
- end
45
-
46
- # Managed System information
47
- class ManagedSystem < HmcObject
48
- XMLMAP = {
49
- "SystemName" => "name",
50
- "State" => "state",
51
- "Hostname" => "hostname",
52
- "PrimaryIPAddress" => "ipaddr",
53
- "SystemFirmware" => "fwversion",
54
- "AssociatedSystemMemoryConfiguration/InstalledSystemMemory" => "memory",
55
- "AssociatedSystemMemoryConfiguration/CurrentAvailableSystemMemory" => "avail_mem",
56
- "AssociatedSystemProcessorConfiguration/InstalledSystemProcessorUnits" => "cpus",
57
- "AssociatedSystemProcessorConfiguration/CurrentAvailableSystemProcessorUnits" => "avail_cpus",
58
- "MachineTypeModelAndSerialNumber/MachineType" => "mtype",
59
- "MachineTypeModelAndSerialNumber/Model" => "model",
60
- "MachineTypeModelAndSerialNumber/SerialNumber" => "serial",
61
- }.freeze
62
-
63
- def initialize(doc)
64
- super(doc)
65
- info = doc.elements["content/ManagedSystem:ManagedSystem"]
66
- get_values(info, XMLMAP)
67
- end
68
- end
69
-
70
- # Logical Partition information
71
- class LogicalPartition < HmcObject
72
- attr_reader :sys_uuid
73
-
74
- XMLMAP = {
75
- "PartitionName" => "name",
76
- "PartitionID" => "id",
77
- "PartitionState" => "state",
78
- "PartitionType" => "type",
79
- "PartitionMemoryConfiguration/CurrentMemory" => "memory",
80
- "PartitionProcessorConfiguration/HasDedicatedProcessors" => "dedicated",
81
- "ResourceMonitoringControlState" => "rmc_state",
82
- "ResourceMonitoringIPAddress" => "rmc_ipaddr"
83
- }.freeze
84
-
85
- def initialize(doc)
86
- super(doc)
87
- info = doc.elements["content/LogicalPartition:LogicalPartition"]
88
- sys_href = info.elements["AssociatedManagedSystem"].attributes["href"]
89
- @sys_uuid = URI(sys_href).path.split('/').last
90
- get_values(info, XMLMAP)
91
- end
92
- end
93
-
94
- # VIOS information
95
- class VirtualIOServer < HmcObject
96
- attr_reader :sys_uuid
97
-
98
- XMLMAP = {
99
- "PartitionName" => "name",
100
- "PartitionID" => "id",
101
- "PartitionState" => "state",
102
- "PartitionType" => "type",
103
- "PartitionMemoryConfiguration/CurrentMemory" => "memory",
104
- "PartitionProcessorConfiguration/HasDedicatedProcessors" => "dedicated"
105
- }.freeze
106
-
107
- def initialize(doc)
108
- super(doc)
109
- info = doc.elements["content/VirtualIOServer:VirtualIOServer"]
110
- sys_href = info.elements["AssociatedManagedSystem"].attributes["href"]
111
- @sys_uuid = URI(sys_href).path.split('/').last
112
- get_values(info, XMLMAP)
113
- end
114
- end
115
-
116
- # HMC Event
117
- class Event < HmcObject
118
- attr_reader :published
119
-
120
- XMLMAP = {
121
- "EventID" => "id",
122
- "EventType" => "type",
123
- "EventData" => "data",
124
- "EventDetail" => "detail",
125
- }.freeze
126
-
127
- def initialize(doc)
128
- super(doc)
129
- @published = doc.elements["published"].text
130
- info = doc.elements["content/Event:Event"]
131
- get_values(info, XMLMAP)
132
- end
133
- end
134
-
135
- # Error response from HMC
136
- class HttpErrorResponse < HmcObject
137
- XMLMAP = {
138
- "HTTPStatus" => "status",
139
- "RequestURI" => "uri",
140
- "ReasonCode" => "reason",
141
- "Message" => "message",
142
- }.freeze
143
-
144
- def initialize(doc)
145
- super(doc)
146
- info = doc.elements["content/HttpErrorResponse:HttpErrorResponse"]
147
- get_values(info, XMLMAP)
148
- end
149
- end
150
- end