ibm_power_hmc 0.10.0 → 0.11.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: ebd50ae53571c98987372d364410261fa5a5440cf23e009c9cf8219eb2e052de
4
- data.tar.gz: 7514545bd7a9be7e958597b7fdebc161f9ea253b20550165a798765930b09eec
3
+ metadata.gz: 669594ada9babea18977e0e3870c6ea0e27305cd74660dbe2d3bbc70551ed4b4
4
+ data.tar.gz: 76304c4b431924825adfc32dc14ff31c0951f0c6aae294010331c82a54ca384d
5
5
  SHA512:
6
- metadata.gz: 41c1fd98ca6750bad69416b3c29986c432c77d8168d72ae485a90a6199b53716dd214c70f74b4c5971e03845d359f847c15a3958a616debd097effcfc0a5567b
7
- data.tar.gz: 44f761a7d986716fe2338bceee413785add2fbfdece042022fec02edadcf60d02ea9deb49bad75d0752ea05b64fbe37b36a554d15f7a6e52bb09c62966ab3e9b
6
+ metadata.gz: 620c2c717f08248e38b1fec9ddec4dc4bea48537ba59a2ad5071cb16b04c93a35fdd05be492eb62de0c67b170881c3c0e7fe57bedfd7c91e92069ac51961bc06
7
+ data.tar.gz: c79795ef430594a26709e8eb71f96ffca4689cf1e362ff7b8531e15e36d9e2fd73c396387a11634c6eea7f29d2bbc82267f952053a3fe40a0a909f36107a3451
data/.gitignore CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.rubocop_local.yml CHANGED
@@ -9,3 +9,5 @@ Style/OptionalBooleanParameter:
9
9
  Enabled: false
10
10
  Style/StringConcatenation:
11
11
  Enabled: false
12
+ Style/RescueModifier:
13
+ Enabled: false
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
File without changes
@@ -157,7 +157,7 @@ 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
  ##
@@ -388,9 +388,10 @@ module IbmPowerHmc
388
388
  ##
389
389
  # @!method templates_summary
390
390
  # Retrieve the list of partition template summaries.
391
+ # @param draft [Boolean] Retrieve draft templates as well
391
392
  # @return [Array<IbmPowerHmc::PartitionTemplateSummary>] The list of partition template summaries.
392
- def templates_summary
393
- method_url = "/rest/api/templates/PartitionTemplate"
393
+ def templates_summary(draft = false)
394
+ method_url = "/rest/api/templates/PartitionTemplate#{'?draft=false' unless draft}"
394
395
  response = request(:get, method_url)
395
396
  FeedParser.new(response.body).objects(:PartitionTemplateSummary)
396
397
  end
@@ -398,9 +399,10 @@ module IbmPowerHmc
398
399
  ##
399
400
  # @!method templates
400
401
  # Retrieve the list of partition templates.
402
+ # @param draft [Boolean] Retrieve draft templates as well
401
403
  # @return [Array<IbmPowerHmc::PartitionTemplate>] The list of partition templates.
402
- def templates
403
- method_url = "/rest/api/templates/PartitionTemplate?detail=full"
404
+ def templates(draft = false)
405
+ method_url = "/rest/api/templates/PartitionTemplate?detail=full#{'&draft=false' unless draft}"
404
406
  response = request(:get, method_url)
405
407
  FeedParser.new(response.body).objects(:PartitionTemplate)
406
408
  end
@@ -439,6 +441,94 @@ module IbmPowerHmc
439
441
  job
440
442
  end
441
443
 
444
+ ##
445
+ # @!method template_check(template_uuid, target_sys_uuid, sync = true)
446
+ # Start Template Check job (first of three steps to deploy an LPAR from a Template).
447
+ # @param template_uuid [String] The UUID of the Template to deploy an LPAR from.
448
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
449
+ # @param sync [Boolean] Start the job and wait for its completion.
450
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
451
+ def template_check(template_uuid, target_sys_uuid, sync = true)
452
+ # Need to include session token in payload so make sure we are logged in
453
+ logon if @api_session_token.nil?
454
+ method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}/do/check"
455
+ params = {
456
+ "TargetUuid" => target_sys_uuid,
457
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
458
+ }
459
+ job = HmcJob.new(self, method_url, "Check", "PartitionTemplate", params)
460
+ job.run if sync
461
+ job
462
+ end
463
+
464
+ ##
465
+ # @!method template_transform(draft_template_uuid, target_sys_uuid, sync = true)
466
+ # Start Template Transform job (second of three steps to deploy an LPAR from a Template).
467
+ # @param draft_template_uuid [String] The UUID of the Draft Template created by the Template Check job.
468
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
469
+ # @param sync [Boolean] Start the job and wait for its completion.
470
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
471
+ def template_transform(draft_template_uuid, target_sys_uuid, sync = true)
472
+ # Need to include session token in payload so make sure we are logged in
473
+ logon if @api_session_token.nil?
474
+ method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/transform"
475
+ params = {
476
+ "TargetUuid" => target_sys_uuid,
477
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
478
+ }
479
+ job = HmcJob.new(self, method_url, "Transform", "PartitionTemplate", params)
480
+ job.run if sync
481
+ job
482
+ end
483
+
484
+ ##
485
+ # @!method template_deploy(draft_template_uuid, target_sys_uuid, sync = true)
486
+ # Start Template Deploy job (last of three steps to deploy an LPAR from a Template).
487
+ # @param draft_template_uuid [String] The UUID of the Draft Template created by the Template Check job.
488
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
489
+ # @param sync [Boolean] Start the job and wait for its completion.
490
+ # @return [IbmPowerHmc::HmcJob] The HMC job.
491
+ def template_deploy(draft_template_uuid, target_sys_uuid, sync = true)
492
+ # Need to include session token in payload so make sure we are logged in
493
+ logon if @api_session_token.nil?
494
+ method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/deploy"
495
+ params = {
496
+ "TargetUuid" => target_sys_uuid,
497
+ "TemplateUuid" => draft_template_uuid,
498
+ "K_X_API_SESSION_MEMENTO" => @api_session_token
499
+ }
500
+ job = HmcJob.new(self, method_url, "Deploy", "PartitionTemplate", params)
501
+ job.run if sync
502
+ job
503
+ end
504
+
505
+ ##
506
+ # @!method template_provision(template_uuid, target_sys_uuid, changes)
507
+ # Deploy Logical Partition from a Template (performs Check, Transform and Deploy steps in a single method).
508
+ # @param template_uuid [String] The UUID of the Template to deploy an LPAR from.
509
+ # @param target_sys_uuid [String] The UUID of the Managed System to deploy the LPAR on.
510
+ # @param changes [Hash] Modifications to apply to the Template before deploying Logical Partition.
511
+ # @return [String] The UUID of the deployed Logical Partition.
512
+ def template_provision(template_uuid, target_sys_uuid, changes)
513
+ # Need to include session token in payload so make sure we are logged in
514
+ logon if @api_session_token.nil?
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
+
442
532
  ##
443
533
  # @!method poweron_lpar(lpar_uuid, params = {}, sync = true)
444
534
  # Power on a logical partition.
@@ -701,6 +791,22 @@ module IbmPowerHmc
701
791
  end
702
792
  end
703
793
 
794
+ # @!method modify_object_attributes(method_url, headers = {}, attempts = 5)
795
+ # Modify an object at a specified URI.
796
+ # @param method_url [String] The URL of the object to modify.
797
+ # @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.
798
+ # @param headers [Hash] HTTP headers.
799
+ # @param attempts [Integer] Maximum number of retries.
800
+ # @yield [obj] The object to modify.
801
+ # @yieldparam obj [IbmPowerHmc::AbstractRest] The object to modify.
802
+ def modify_object_attributes(method_url, changes, headers = {}, attempts = 5)
803
+ modify_object(method_url, headers, attempts) do |obj|
804
+ changes.each do |key, value|
805
+ obj.send("#{key}=", value)
806
+ end
807
+ end
808
+ end
809
+
704
810
  ##
705
811
  # @!method network_adapter(vm_type, lpar_uuid, netadap_uuid)
706
812
  # Retrieve one or all virtual ethernet network adapters attached to a Logical Partition or a Virtual I/O Server.
@@ -5,6 +5,16 @@ module IbmPowerHmc
5
5
  # HMC Job for long running operations.
6
6
  class HmcJob
7
7
  class JobNotStarted < StandardError; end
8
+ class JobFailed < StandardError
9
+ def initialize(job)
10
+ super
11
+ @job = job
12
+ end
13
+
14
+ def to_s
15
+ "id=\"#{@job.id}\" operation=\"#{@job.group}/#{@job.operation}\" status=\"#{@job.status}\" message=\"#{@job.message}\" exception_text=\"#{@job.results['ExceptionText']}\""
16
+ end
17
+ end
8
18
 
9
19
  ##
10
20
  # @!method initialize(conn, method_url, operation, group, params = {})
@@ -52,7 +62,7 @@ module IbmPowerHmc
52
62
  end
53
63
 
54
64
  # @return [Hash] The job results returned by the HMC.
55
- attr_reader :results
65
+ attr_reader :results, :last_status
56
66
 
57
67
  ##
58
68
  # @!method status
@@ -65,9 +75,9 @@ module IbmPowerHmc
65
75
  :content_type => "application/vnd.ibm.powervm.web+xml; type=JobRequest"
66
76
  }
67
77
  response = @conn.request(:get, @href, headers)
68
- jobresp = Parser.new(response.body).object(:JobResponse)
69
- @results = jobresp.results
70
- jobresp.status
78
+ @last_status = Parser.new(response.body).object(:JobResponse)
79
+ @results = @last_status.results
80
+ @last_status.status
71
81
  end
72
82
 
73
83
  ##
@@ -99,6 +109,7 @@ module IbmPowerHmc
99
109
  def run(timeout = 120, poll_interval = 0)
100
110
  start
101
111
  wait(timeout, poll_interval)
112
+ raise JobFailed.new(@last_status) unless @last_status.status.eql?("COMPLETED_OK")
102
113
  ensure
103
114
  delete if defined?(@href)
104
115
  end
@@ -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.
@@ -327,13 +352,6 @@ module IbmPowerHmc
327
352
  def sriov_elp_uuids
328
353
  uuids_from_links("SRIOVEthernetLogicalPorts")
329
354
  end
330
-
331
- # Setters
332
-
333
- def name=(name)
334
- xml.elements[ATTRS[:name]].text = name
335
- @name = name
336
- end
337
355
  end
338
356
 
339
357
  # Logical Partition information
@@ -882,6 +900,8 @@ module IbmPowerHmc
882
900
  ATTRS = {
883
901
  :name => "partitionTemplateName",
884
902
  :description => "description",
903
+ :lpar_name => "logicalPartitionConfig/partitionName",
904
+ :lpar_id => "logicalPartitionConfig/partitionId",
885
905
  :os => "logicalPartitionConfig/osVersion",
886
906
  :memory => "logicalPartitionConfig/memoryConfiguration/currMemory",
887
907
  :dedicated => "logicalPartitionConfig/processorConfiguration/hasDedicatedProcessors",
@@ -890,6 +910,87 @@ module IbmPowerHmc
890
910
  :proc_units => "logicalPartitionConfig/processorConfiguration/sharedProcessorConfiguration/desiredProcessingUnits",
891
911
  :procs => "logicalPartitionConfig/processorConfiguration/dedicatedProcessorConfiguration/desiredProcessors"
892
912
  }.freeze
913
+
914
+ def vscsi
915
+ REXML::XPath.match(xml, 'logicalPartitionConfig/virtualSCSIClientAdapters/VirtualSCSIClientAdapter').map do |adap|
916
+ {
917
+ :vios => adap.elements['connectingPartitionName']&.text,
918
+ :physvol => adap.elements['associatedPhysicalVolume/PhysicalVolume/name']&.text,
919
+ }
920
+ end
921
+ end
922
+
923
+ def vscsi=(list = [])
924
+ adaps = REXML::Element.new('virtualSCSIClientAdapters')
925
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
926
+ list.each do |vlan|
927
+ adaps.add_element('VirtualSCSIClientAdapter', {'schemaVersion' => 'V1_5_0'}).tap do |v|
928
+ v.add_element('associatedLogicalUnits', {'schemaVersion' => 'V1_5_0'})
929
+ v.add_element('associatedPhysicalVolume', {'schemaVersion' => 'V1_5_0'}).tap do |e|
930
+ e.add_element('PhysicalVolume', {'schemaVersion' => 'V1_5_0'}).add_element('name').text = vlan[:physvol] if vlan[:physvol]
931
+ end
932
+ v.add_element('connectingPartitionName').text = vlan[:vios]
933
+ v.add_element('AssociatedTargetDevices', {'schemaVersion' => 'V1_5_0'})
934
+ v.add_element('associatedVirtualOpticalMedia', {'schemaVersion' => 'V1_5_0'})
935
+ end
936
+ end
937
+ if xml.elements['logicalPartitionConfig/virtualSCSIClientAdapters']
938
+ xml.elements['logicalPartitionConfig/virtualSCSIClientAdapters'] = adaps
939
+ else
940
+ xml.elements['logicalPartitionConfig'].add_element(adaps)
941
+ end
942
+ end
943
+
944
+ def vfc
945
+ REXML::XPath.match(xml, 'logicalPartitionConfig/virtualFibreChannelClientAdapters/VirtualFibreChannelClientAdapter').map do |adap|
946
+ {
947
+ :vios => adap.elements['connectingPartitionName']&.text,
948
+ :port => adap.elements['portName']&.text
949
+ }
950
+ end
951
+ end
952
+
953
+ def vfc=(list = [])
954
+ adaps = REXML::Element.new('virtualFibreChannelClientAdapters')
955
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
956
+ list.each do |vlan|
957
+ adaps.add_element('VirtualFibreChannelClientAdapter', {'schemaVersion' => 'V1_5_0'}).tap do |v|
958
+ v.add_element('connectingPartitionName').text = vlan[:vios]
959
+ v.add_element('portName').text = vlan[:port]
960
+ end
961
+ end
962
+ if xml.elements['logicalPartitionConfig/virtualFibreChannelClientAdapters']
963
+ xml.elements['logicalPartitionConfig/virtualFibreChannelClientAdapters'] = adaps
964
+ else
965
+ xml.elements['logicalPartitionConfig'].add_element(adaps)
966
+ end
967
+ end
968
+
969
+ def vlans
970
+ REXML::XPath.match(xml, 'logicalPartitionConfig/clientNetworkAdapters/ClientNetworkAdapter/clientVirtualNetworks/ClientVirtualNetwork').map do |vlan|
971
+ {
972
+ :name => vlan.elements['name']&.text,
973
+ :vlan_id => vlan.elements['vlanId']&.text,
974
+ :switch => vlan.elements['associatedSwitchName']&.text
975
+ }
976
+ end
977
+ end
978
+
979
+ def vlans=(list = [])
980
+ adaps = REXML::Element.new('clientNetworkAdapters')
981
+ adaps.add_attribute('schemaVersion', 'V1_5_0')
982
+ list.each do |vlan|
983
+ adaps.add_element('ClientNetworkAdapter', {'schemaVersion' => 'V1_5_0'}).
984
+ add_element('clientVirtualNetworks', {'schemaVersion' => 'V1_5_0'}).
985
+ add_element('ClientVirtualNetwork', {'schemaVersion' => 'V1_5_0'}).
986
+ tap do |v|
987
+ v.add_element('name').text = vlan[:name]
988
+ v.add_element('vlanId').text = vlan[:vlan_id]
989
+ v.add_element('associatedSwitchName').text = vlan[:switch]
990
+ end
991
+ end
992
+ xml.elements['logicalPartitionConfig/clientNetworkAdapters'] = adaps
993
+ end
893
994
  end
894
995
 
895
996
  # HMC Event
@@ -917,9 +1018,11 @@ module IbmPowerHmc
917
1018
  # Job Response
918
1019
  class JobResponse < AbstractRest
919
1020
  ATTRS = {
920
- :id => "JobID",
921
- :status => "Status",
922
- :message => "ResponseException/Message"
1021
+ :id => "JobID",
1022
+ :status => "Status",
1023
+ :operation => "JobRequestInstance/RequestedOperation/OperationName",
1024
+ :group => "JobRequestInstance/RequestedOperation/GroupName",
1025
+ :message => "ResponseException/Message"
923
1026
  }.freeze
924
1027
 
925
1028
  def results
File without changes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbmPowerHmc
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.0"
5
5
  end
data/lib/ibm_power_hmc.rb CHANGED
File without changes
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.10.0
4
+ version: 0.11.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: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  description: A Ruby gem for interacting with the IBM Hardware Management Console (HMC).
42
- email:
42
+ email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -69,7 +69,7 @@ metadata:
69
69
  homepage_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby
70
70
  source_code_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby
71
71
  changelog_uri: http://github.com/IBM/ibm_power_hmc_sdk_ruby/blob/master/CHANGELOG.md
72
- post_install_message:
72
+ post_install_message:
73
73
  rdoc_options: []
74
74
  require_paths:
75
75
  - lib
@@ -84,8 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.1.2
88
- signing_key:
87
+ rubygems_version: 3.1.4
88
+ signing_key:
89
89
  specification_version: 4
90
90
  summary: IBM Power HMC Ruby gem.
91
91
  test_files: []