ibm_power_hmc 0.9.0 → 0.12.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: 49b7980e12490365221b3fcc8dcb6a867078dc62f44cd1f0646c75d5d1c7c8cc
4
- data.tar.gz: a2f7776c0039c188685e84b72c1a5217cda5252cea0d7d4e142ac734ad32305a
3
+ metadata.gz: e162db8e4002c4b1fbee71faceaa8c4a859f5e7e92e33e4cbbdb59862da9cde6
4
+ data.tar.gz: 97bc18d7e606bddd79f6ed83b9f2f5b562f5121c433d613085e7da5e695f71df
5
5
  SHA512:
6
- metadata.gz: f3bf7576a9eda74a292c74c088c8ed3e88fdde40d94472980600d561563e5998415da26815bfd4d78bf3faade900b22a5a142c67a42e600e7b9c530d8a67e7f8
7
- data.tar.gz: ec3563218f5a20515179073d391a5bb54bc32f361c63eab190193462b3560185354bc2cc9ff73cb78023ece6ca4550d9584abcfabc0a1a2fac2998a63ff8b820
6
+ metadata.gz: 3a36c85b010b6e67bd91e67fa380c4edb6cc27a34aee732237b5c95eaee2f6a983ee1c461bc6ab5830d4952743360f848a1228f85121f9ac8cf150b194440dac
7
+ data.tar.gz: 741c9dedab5f6bd5fd7af0038e8bdab555c6b71274f3cecded7aaf4cabb21371b744e3fd355140e61bc9c7a36128a473a81fffd6983662d2def0c0e22ac1fcc5
@@ -157,19 +157,21 @@ module IbmPowerHmc
157
157
  # @param new_name [String] The new name of the logical partition.
158
158
  def rename_lpar(lpar_uuid, new_name)
159
159
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"
160
- modify_object(method_url) { |lpar| lpar.name = new_name }
160
+ modify_object_attributes(method_url, {:name => new_name})
161
161
  end
162
162
 
163
163
  ##
164
- # @!method vioses(sys_uuid = nil, search = {})
164
+ # @!method vioses(sys_uuid = nil, search = {}, permissive = true)
165
165
  # Retrieve the list of virtual I/O servers managed by the HMC.
166
166
  # @param sys_uuid [String] The UUID of the managed system.
167
167
  # @param search [Hash] The optional property name and value to match.
168
+ # @param permissive [Boolean] Skip virtual I/O servers that have error conditions.
168
169
  # @return [Array<IbmPowerHmc::VirtualIOServer>] The list of virtual I/O servers.
169
- def vioses(sys_uuid = nil, search = {})
170
+ def vioses(sys_uuid = nil, search = {}, permissive = true)
170
171
  if sys_uuid.nil?
171
172
  method_url = "/rest/api/uom/VirtualIOServer"
172
173
  search.each { |key, value| method_url += "/search/(#{key}==#{value})" }
174
+ method_url += "?ignoreError=true" if permissive
173
175
  else
174
176
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualIOServer"
175
177
  end
@@ -386,21 +388,23 @@ module IbmPowerHmc
386
388
  end
387
389
 
388
390
  ##
389
- # @!method templates_summary
391
+ # @!method templates_summary(draft = false)
390
392
  # Retrieve the list of partition template summaries.
393
+ # @param draft [Boolean] Retrieve draft templates as well
391
394
  # @return [Array<IbmPowerHmc::PartitionTemplateSummary>] The list of partition template summaries.
392
- def templates_summary
393
- method_url = "/rest/api/templates/PartitionTemplate"
395
+ def templates_summary(draft = false)
396
+ method_url = "/rest/api/templates/PartitionTemplate#{'?draft=false' unless draft}"
394
397
  response = request(:get, method_url)
395
398
  FeedParser.new(response.body).objects(:PartitionTemplateSummary)
396
399
  end
397
400
 
398
401
  ##
399
- # @!method templates
402
+ # @!method templates(draft = false)
400
403
  # Retrieve the list of partition templates.
404
+ # @param draft [Boolean] Retrieve draft templates as well
401
405
  # @return [Array<IbmPowerHmc::PartitionTemplate>] The list of partition templates.
402
- def templates
403
- method_url = "/rest/api/templates/PartitionTemplate?detail=full"
406
+ def templates(draft = false)
407
+ method_url = "/rest/api/templates/PartitionTemplate?detail=full#{'&draft=false' unless draft}"
404
408
  response = request(:get, method_url)
405
409
  FeedParser.new(response.body).objects(:PartitionTemplate)
406
410
  end
@@ -439,6 +443,109 @@ module IbmPowerHmc
439
443
  job
440
444
  end
441
445
 
446
+ ##
447
+ # @!method template_check(template_uuid, target_sys_uuid, sync = true)
448
+ # Start Template Check job (first of three steps to deploy an LPAR from a Template).
449
+ # @param template_uuid [String] The UUID of the Template to deploy an LPAR from.
450
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
451
+ # @param sync [Boolean] Start the job and wait for its completion.
452
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
453
+ def template_check(template_uuid, target_sys_uuid, sync = true)
454
+ # Need to include session token in payload so make sure we are logged in
455
+ logon if @api_session_token.nil?
456
+ method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}/do/check"
457
+ params = {
458
+ "TargetUuid" => target_sys_uuid,
459
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
460
+ }
461
+ job = HmcJob.new(self, method_url, "Check", "PartitionTemplate", params)
462
+ job.run if sync
463
+ job
464
+ end
465
+
466
+ ##
467
+ # @!method template_transform(draft_template_uuid, target_sys_uuid, sync = true)
468
+ # Start Template Transform job (second of three steps to deploy an LPAR from a Template).
469
+ # @param draft_template_uuid [String] The UUID of the Draft Template created by the Template Check job.
470
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
471
+ # @param sync [Boolean] Start the job and wait for its completion.
472
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
473
+ def template_transform(draft_template_uuid, target_sys_uuid, sync = true)
474
+ # Need to include session token in payload so make sure we are logged in
475
+ logon if @api_session_token.nil?
476
+ method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/transform"
477
+ params = {
478
+ "TargetUuid" => target_sys_uuid,
479
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
480
+ }
481
+ job = HmcJob.new(self, method_url, "Transform", "PartitionTemplate", params)
482
+ job.run if sync
483
+ job
484
+ end
485
+
486
+ ##
487
+ # @!method template_deploy(draft_template_uuid, target_sys_uuid, sync = true)
488
+ # Start Template Deploy job (last of three steps to deploy an LPAR from a Template).
489
+ # @param draft_template_uuid [String] The UUID of the Draft Template created by the Template Check job.
490
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
491
+ # @param sync [Boolean] Start the job and wait for its completion.
492
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
493
+ def template_deploy(draft_template_uuid, target_sys_uuid, sync = true)
494
+ # Need to include session token in payload so make sure we are logged in
495
+ logon if @api_session_token.nil?
496
+ method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/deploy"
497
+ params = {
498
+ "TargetUuid" => target_sys_uuid,
499
+ "TemplateUuid" => draft_template_uuid,
500
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
501
+ }
502
+ job = HmcJob.new(self, method_url, "Deploy", "PartitionTemplate", params)
503
+ job.run if sync
504
+ job
505
+ end
506
+
507
+ ##
508
+ # @!method template_provision(template_uuid, target_sys_uuid, changes)
509
+ # Deploy Logical Partition from a Template (performs Check, Transform and Deploy steps in a single method).
510
+ # @param template_uuid [String] The UUID of the Template to deploy an LPAR from.
511
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
512
+ # @param changes [Hash] Modifications to apply to the Template before deploying Logical Partition.
513
+ # @return [String] The UUID of the deployed Logical Partition.
514
+ def template_provision(template_uuid, target_sys_uuid, changes)
515
+ draft_uuid = template_check(template_uuid, target_sys_uuid).results["TEMPLATE_UUID"]
516
+ template_transform(draft_uuid, target_sys_uuid)
517
+ template_modify(draft_uuid, changes)
518
+ template_deploy(draft_uuid, target_sys_uuid).results["PartitionUuid"]
519
+ end
520
+
521
+ ##
522
+ # @!method template(template_uuid, changes)
523
+ # modify_object_attributes wrapper for templates.
524
+ # @param template_uuid [String] UUID of the partition template to modify.
525
+ # @param changes [Hash] Hash of changes to make.
526
+ # @return [IbmPowerHmc::PartitionTemplate] The partition template.
527
+ def template_modify(template_uuid, changes)
528
+ method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}"
529
+ modify_object_attributes(method_url, changes)
530
+ end
531
+
532
+ ##
533
+ # @!method template_copy(template_uuid, new_name)
534
+ # Copy existing template to a new one.
535
+ # @param template_uuid [String] UUID of the partition template to copy.
536
+ # @param new_name [String] Name of the new template.
537
+ # @return [IbmPowerHmc::PartitionTemplate] The new partition template.
538
+ def template_copy(template_uuid, new_name)
539
+ method_url = "/rest/api/templates/PartitionTemplate"
540
+ headers = {
541
+ :content_type => "application/vnd.ibm.powervm.templates+xml;type=PartitionTemplate"
542
+ }
543
+ original = template(template_uuid)
544
+ original.name = new_name
545
+ response = request(:put, method_url, headers, original.xml.to_s)
546
+ Parser.new(response.body).object(:PartitionTemplate)
547
+ end
548
+
442
549
  ##
443
550
  # @!method poweron_lpar(lpar_uuid, params = {}, sync = true)
444
551
  # Power on a logical partition.
@@ -622,13 +729,15 @@ module IbmPowerHmc
622
729
  @status = err.http_code
623
730
  @message = err.message
624
731
 
625
- # Try to parse body as an HttpErrorResponse
732
+ # Try to parse body as an HttpErrorResponse.
626
733
  unless err.response.nil?
627
- resp = Parser.new(err.response.body).object(:HttpErrorResponse) rescue nil
628
- unless resp.nil?
734
+ begin
735
+ resp = Parser.new(err.response.body).object(:HttpErrorResponse)
629
736
  @uri = resp.uri
630
737
  @reason = resp.reason
631
738
  @message = resp.message
739
+ rescue
740
+ # not an XML body
632
741
  end
633
742
  end
634
743
  end
@@ -661,9 +770,9 @@ module IbmPowerHmc
661
770
  :headers => headers
662
771
  )
663
772
  rescue RestClient::Exception => e
664
- # Do not retry on failed logon attempts
773
+ # Do not retry on failed logon attempts.
665
774
  if e.http_code == 401 && @api_session_token != "" && !reauth
666
- # Try to reauth
775
+ # Try to reauth.
667
776
  reauth = true
668
777
  logon
669
778
  retry
@@ -695,12 +804,26 @@ module IbmPowerHmc
695
804
  break
696
805
  rescue HttpError => e
697
806
  attempts -= 1
698
- # Will get 412 ("Precondition Failed") if ETag mismatches
807
+ # Will get 412 ("Precondition Failed") if ETag mismatches.
699
808
  raise if e.status != 412 || attempts == 0
700
809
  end
701
810
  end
702
811
  end
703
812
 
813
+ # @!method modify_object_attributes(method_url, changes, headers = {}, attempts = 5)
814
+ # Modify an object at a specified URI.
815
+ # @param method_url [String] The URL of the object to modify.
816
+ # @param changes [Hash] Hash of changes to make. Key is the attribute modify/create (as defined in the AbstractNonRest subclass). A value of nil removes the attribute.
817
+ # @param headers [Hash] HTTP headers.
818
+ # @param attempts [Integer] Maximum number of retries.
819
+ def modify_object_attributes(method_url, changes, headers = {}, attempts = 5)
820
+ modify_object(method_url, headers, attempts) do |obj|
821
+ changes.each do |key, value|
822
+ obj.send("#{key}=", value)
823
+ end
824
+ end
825
+ end
826
+
704
827
  ##
705
828
  # @!method network_adapter(vm_type, lpar_uuid, netadap_uuid)
706
829
  # Retrieve one or all virtual ethernet network adapters attached to a Logical Partition or a Virtual I/O Server.
@@ -6,6 +6,17 @@ module IbmPowerHmc
6
6
  class HmcJob
7
7
  class JobNotStarted < StandardError; end
8
8
 
9
+ class JobFailed < StandardError
10
+ def initialize(job)
11
+ super
12
+ @job = job
13
+ end
14
+
15
+ def to_s
16
+ "id=\"#{@job.id}\" operation=\"#{@job.group}/#{@job.operation}\" status=\"#{@job.status}\" message=\"#{@job.message}\" exception_text=\"#{@job.results['ExceptionText']}\""
17
+ end
18
+ end
19
+
9
20
  ##
10
21
  # @!method initialize(conn, method_url, operation, group, params = {})
11
22
  # Construct a new HMC Job.
@@ -52,7 +63,7 @@ module IbmPowerHmc
52
63
  end
53
64
 
54
65
  # @return [Hash] The job results returned by the HMC.
55
- attr_reader :results
66
+ attr_reader :results, :last_status
56
67
 
57
68
  ##
58
69
  # @!method status
@@ -65,9 +76,9 @@ module IbmPowerHmc
65
76
  :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest"
66
77
  }
67
78
  response = @conn.request(:get, @href, headers)
68
- jobresp = Parser.new(response.body).object(:JobResponse)
69
- @results = jobresp.results
70
- jobresp.status
79
+ @last_status = Parser.new(response.body).object(:JobResponse)
80
+ @results = @last_status.results
81
+ @last_status.status
71
82
  end
72
83
 
73
84
  ##
@@ -99,6 +110,7 @@ module IbmPowerHmc
99
110
  def run(timeout = 120, poll_interval = 0)
100
111
  start
101
112
  wait(timeout, poll_interval)
113
+ raise JobFailed.new(@last_status), "Job failed" unless @last_status.status.eql?("COMPLETED_OK")
102
114
  ensure
103
115
  delete if defined?(@href)
104
116
  end
@@ -34,7 +34,7 @@ module IbmPowerHmc
34
34
  content = entry.elements["content[@type]"]
35
35
  return if content.nil?
36
36
 
37
- type = content.attributes["type"].split("=").last
37
+ type = content.attributes["type"].split("=")[1] || filter_type.to_s
38
38
  return unless filter_type.nil? || filter_type.to_s == type
39
39
 
40
40
  Module.const_get("IbmPowerHmc::#{type}").new(entry)
@@ -95,10 +95,35 @@ module IbmPowerHmc
95
95
  def define_attr(varname, xpath)
96
96
  value = singleton(xpath)
97
97
  self.class.__send__(:attr_reader, varname)
98
+ self.class.__send__(:define_method, "#{varname}=") do |v|
99
+ if v.nil?
100
+ xml.elements.delete(xpath)
101
+ else
102
+ create_element(xpath) if xml.elements[xpath].nil?
103
+ xml.elements[xpath].text = v
104
+ end
105
+ instance_variable_set("@#{varname}", v)
106
+ end
98
107
  instance_variable_set("@#{varname}", value)
99
108
  end
100
109
  private :define_attr
101
110
 
111
+ ##
112
+ # @!method create_element(xpath)
113
+ # Create a new XML element.
114
+ # @param xpath [String] The XPath of the XML element to create.
115
+ def create_element(xpath)
116
+ cur = xml
117
+ xpath.split("/").each do |el|
118
+ p = cur.elements[el]
119
+ if p.nil?
120
+ cur = cur.add_element(el)
121
+ else
122
+ cur = p
123
+ end
124
+ end
125
+ end
126
+
102
127
  ##
103
128
  # @!method singleton(xpath, attr = nil)
104
129
  # Get the text (or the value of a specified attribute) of an XML element.
@@ -135,7 +160,7 @@ module IbmPowerHmc
135
160
 
136
161
  def collection_of(name, type)
137
162
  objtype = Module.const_get("IbmPowerHmc::#{type}")
138
- xml.get_elements("#{name}/#{type}").map do |elem|
163
+ xml.get_elements([name, type].compact.join("/")).map do |elem|
139
164
  objtype.new(elem)
140
165
  end
141
166
  rescue
@@ -198,9 +223,15 @@ module IbmPowerHmc
198
223
  :build_level => "VersionInfo/BuildLevel",
199
224
  :version => "BaseVersion",
200
225
  :ssh_pubkey => "PublicSSHKeyValue",
201
- :uvmid => "UVMID"
226
+ :uvmid => "UVMID",
227
+ :tz => "CurrentTimezone",
228
+ :uptime => "ManagementConsoleUpTime"
202
229
  }.freeze
203
230
 
231
+ def time
232
+ Time.at(0, singleton("ManagementConsoleTime").to_i, :millisecond).utc
233
+ end
234
+
204
235
  def managed_systems_uuids
205
236
  uuids_from_links("ManagedSystems")
206
237
  end
@@ -327,13 +358,6 @@ module IbmPowerHmc
327
358
  def sriov_elp_uuids
328
359
  uuids_from_links("SRIOVEthernetLogicalPorts")
329
360
  end
330
-
331
- # Setters
332
-
333
- def name=(name)
334
- xml.elements[ATTRS[:name]].text = name
335
- @name = name
336
- end
337
361
  end
338
362
 
339
363
  # Logical Partition information
@@ -401,7 +425,7 @@ module IbmPowerHmc
401
425
  :location => "LocationCode",
402
426
  :description => "Description",
403
427
  :is_available => "AvailableForUsage",
404
- :capacity => "VolumeCapacity",
428
+ :capacity => "VolumeCapacity", # in MiB
405
429
  :name => "VolumeName",
406
430
  :is_fc => "IsFibreChannelBacked",
407
431
  :udid => "VolumeUniqueID"
@@ -413,7 +437,7 @@ module IbmPowerHmc
413
437
  ATTRS = {
414
438
  :name => "DiskName",
415
439
  :label => "DiskLabel",
416
- :capacity => "DiskCapacity", # In GiB
440
+ :capacity => "DiskCapacity", # in GiB
417
441
  :psize => "PartitionSize",
418
442
  :vg => "VolumeGroup",
419
443
  :udid => "UniqueDeviceID"
@@ -882,6 +906,8 @@ module IbmPowerHmc
882
906
  ATTRS = {
883
907
  :name => "partitionTemplateName",
884
908
  :description => "description",
909
+ :lpar_name => "logicalPartitionConfig/partitionName",
910
+ :lpar_id => "logicalPartitionConfig/partitionId",
885
911
  :os => "logicalPartitionConfig/osVersion",
886
912
  :memory => "logicalPartitionConfig/memoryConfiguration/currMemory",
887
913
  :dedicated => "logicalPartitionConfig/processorConfiguration/hasDedicatedProcessors",
@@ -890,6 +916,87 @@ module IbmPowerHmc
890
916
  :proc_units => "logicalPartitionConfig/processorConfiguration/sharedProcessorConfiguration/desiredProcessingUnits",
891
917
  :procs => "logicalPartitionConfig/processorConfiguration/dedicatedProcessorConfiguration/desiredProcessors"
892
918
  }.freeze
919
+
920
+ def vscsi
921
+ REXML::XPath.match(xml, 'logicalPartitionConfig/virtualSCSIClientAdapters/VirtualSCSIClientAdapter').map do |adap|
922
+ {
923
+ :vios => adap.elements['connectingPartitionName']&.text,
924
+ :physvol => adap.elements['associatedPhysicalVolume/PhysicalVolume/name']&.text,
925
+ }
926
+ end
927
+ end
928
+
929
+ def vscsi=(list = [])
930
+ adaps = REXML::Element.new('virtualSCSIClientAdapters')
931
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
932
+ list.each do |vscsi|
933
+ adaps.add_element('VirtualSCSIClientAdapter', {'schemaVersion' => 'V1_5_0'}).tap do |v|
934
+ v.add_element('associatedLogicalUnits', {'schemaVersion' => 'V1_5_0'})
935
+ v.add_element('associatedPhysicalVolume', {'schemaVersion' => 'V1_5_0'}).tap do |e|
936
+ e.add_element('PhysicalVolume', {'schemaVersion' => 'V1_5_0'}).add_element('name').text = vscsi[:physvol] if vscsi[:physvol]
937
+ end
938
+ v.add_element('connectingPartitionName').text = vscsi[:vios]
939
+ v.add_element('AssociatedTargetDevices', {'schemaVersion' => 'V1_5_0'})
940
+ v.add_element('associatedVirtualOpticalMedia', {'schemaVersion' => 'V1_5_0'})
941
+ end
942
+ end
943
+ if xml.elements['logicalPartitionConfig/virtualSCSIClientAdapters']
944
+ xml.elements['logicalPartitionConfig/virtualSCSIClientAdapters'] = adaps
945
+ else
946
+ xml.elements['logicalPartitionConfig'].add_element(adaps)
947
+ end
948
+ end
949
+
950
+ def vfc
951
+ REXML::XPath.match(xml, 'logicalPartitionConfig/virtualFibreChannelClientAdapters/VirtualFibreChannelClientAdapter').map do |adap|
952
+ {
953
+ :vios => adap.elements['connectingPartitionName']&.text,
954
+ :port => adap.elements['portName']&.text
955
+ }
956
+ end
957
+ end
958
+
959
+ def vfc=(list = [])
960
+ adaps = REXML::Element.new('virtualFibreChannelClientAdapters')
961
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
962
+ list.each do |vfc|
963
+ adaps.add_element('VirtualFibreChannelClientAdapter', {'schemaVersion' => 'V1_5_0'}).tap do |v|
964
+ v.add_element('connectingPartitionName').text = vfc[:vios]
965
+ v.add_element('portName').text = vfc[:port]
966
+ end
967
+ end
968
+ if xml.elements['logicalPartitionConfig/virtualFibreChannelClientAdapters']
969
+ xml.elements['logicalPartitionConfig/virtualFibreChannelClientAdapters'] = adaps
970
+ else
971
+ xml.elements['logicalPartitionConfig'].add_element(adaps)
972
+ end
973
+ end
974
+
975
+ def vlans
976
+ REXML::XPath.match(xml, 'logicalPartitionConfig/clientNetworkAdapters/ClientNetworkAdapter/clientVirtualNetworks/ClientVirtualNetwork').map do |vlan|
977
+ {
978
+ :name => vlan.elements['name']&.text,
979
+ :vlan_id => vlan.elements['vlanId']&.text,
980
+ :switch => vlan.elements['associatedSwitchName']&.text
981
+ }
982
+ end
983
+ end
984
+
985
+ def vlans=(list = [])
986
+ adaps = REXML::Element.new('clientNetworkAdapters')
987
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
988
+ list.each do |vlan|
989
+ adaps.add_element('ClientNetworkAdapter', {'schemaVersion' => 'V1_5_0'})
990
+ .add_element('clientVirtualNetworks', {'schemaVersion' => 'V1_5_0'})
991
+ .add_element('ClientVirtualNetwork', {'schemaVersion' => 'V1_5_0'})
992
+ .tap do |v|
993
+ v.add_element('name').text = vlan[:name]
994
+ v.add_element('vlanId').text = vlan[:vlan_id]
995
+ v.add_element('associatedSwitchName').text = vlan[:switch]
996
+ end
997
+ end
998
+ xml.elements['logicalPartitionConfig/clientNetworkAdapters'] = adaps
999
+ end
893
1000
  end
894
1001
 
895
1002
  # HMC Event
@@ -917,9 +1024,11 @@ module IbmPowerHmc
917
1024
  # Job Response
918
1025
  class JobResponse < AbstractRest
919
1026
  ATTRS = {
920
- :id => "JobID",
921
- :status => "Status",
922
- :message => "ResponseException/Message"
1027
+ :id => "JobID",
1028
+ :status => "Status",
1029
+ :operation => "JobRequestInstance/RequestedOperation/OperationName",
1030
+ :group => "JobRequestInstance/RequestedOperation/GroupName",
1031
+ :message => "ResponseException/Message"
923
1032
  }.freeze
924
1033
 
925
1034
  def results
@@ -932,4 +1041,32 @@ module IbmPowerHmc
932
1041
  results
933
1042
  end
934
1043
  end
1044
+
1045
+ # Performance and Capacity Monitoring preferences
1046
+ class ManagementConsolePcmPreference < AbstractRest
1047
+ ATTRS = {
1048
+ :max_ltm => "MaximumManagedSystemsForLongTermMonitor",
1049
+ :max_compute_ltm => "MaximumManagedSystemsForComputeLTM",
1050
+ :max_aggregation => "MaximumManagedSystemsForAggregation",
1051
+ :max_stm => "MaximumManagedSystemsForShortTermMonitor",
1052
+ :max_em => "MaximumManagedSystemsForEnergyMonitor",
1053
+ :aggregated_storage_duration => "AggregatedMetricsStorageDuration"
1054
+ }.freeze
1055
+
1056
+ def managed_system_preferences
1057
+ collection_of(nil, "ManagedSystemPcmPreference")
1058
+ end
1059
+ end
1060
+
1061
+ class ManagedSystemPcmPreference < AbstractNonRest
1062
+ ATTRS = {
1063
+ :id => "Metadata/Atom/AtomID",
1064
+ :name => "SystemName",
1065
+ :long_term_monitor => "LongTermMonitorEnabled",
1066
+ :aggregation => "AggregationEnabled",
1067
+ :short_term_monitor => "ShortTermMonitorEnabled",
1068
+ :compute_ltm => "ComputeLTMEnabled",
1069
+ :energy_monitor => "EnergyMonitorEnabled"
1070
+ }.freeze
1071
+ end
935
1072
  end
@@ -5,11 +5,24 @@ require 'uri'
5
5
 
6
6
  module IbmPowerHmc
7
7
  class Connection
8
+ ##
9
+ # @!method pcm_preferences
10
+ # Retrieve global Performance and Capacity Monitor preferences for the HMC.
11
+ # @return [Array<IbmPowerHmc::ManagementConsolePcmPreference>] The PCM preferences for the HMC.
8
12
  def pcm_preferences
9
13
  method_url = "/rest/api/pcm/preferences"
10
14
 
11
15
  response = request(:get, method_url)
12
- REXML::Document.new(response.body)
16
+ FeedParser.new(response.body).objects(:ManagementConsolePcmPreference)
17
+ end
18
+
19
+ ##
20
+ # @!method managed_system_pcm_preferences(sys_uuid)
21
+ # Return Performance and Capacity Monitor preferences for a Managed System.
22
+ # @param sys_uuid [String] The managed system UUID.
23
+ # @return [IbmPowerHmc::ManagedSystemPcmPreference] The PCM preferences for the Managed System.
24
+ def managed_system_pcm_preferences(sys_uuid)
25
+ pcm_preferences.first.managed_system_preferences.find { |p| p.id.eql?(sys_uuid) }
13
26
  end
14
27
 
15
28
  ##
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbmPowerHmc
4
- VERSION = "0.9.0"
4
+ VERSION = "0.12.0"
5
5
  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.9.0
4
+ version: 0.12.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: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.0.3
87
+ rubygems_version: 3.1.4
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: IBM Power HMC Ruby gem.