ibm_power_hmc 0.14.0 → 0.16.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: 3162f83d1c3168407716f683401e5f3f1b3c49489728561e52ab49410209beaa
4
- data.tar.gz: c50f1ac36cda911c01262b06762fd928c06790d4df116f020958edd10ca0713e
3
+ metadata.gz: faeaaee474f96b0beb9747a2d346110a1321e9060b2b196770598f1bccfd85a8
4
+ data.tar.gz: 3af51fcdb06f722a95e44bcea28f8ed4f4fef9cdfd9e1332063c3bf288a00c61
5
5
  SHA512:
6
- metadata.gz: 014ff944d75d5dccf07d894628a0b41c08fe99d3478558f57b22aff2a1e86cc9589368c3a55696dc0f196edabd59f0d9e47b0f2aa09f726b7d6b18c5d250e775
7
- data.tar.gz: 68a388e0a6a75c9cc61e9befeca8644fa64f92e95ca8411948fe166ba81c44997bd67c0247d943567fb0f345671bb9164dbc77294bdeb153f534b394c4637334
6
+ metadata.gz: 1756c8a220a30ba88da0cd0d518a681657f9d08a231c11715e461d0fe5be1c171b17e98bb290fd29f9cdb551da48cdfc699707147abded7cfa204dcde26067be
7
+ data.tar.gz: 8906b25b90865262000331f4c371b546cac852eeb14714e8c75b0e7ae937422d441a1c920687d4e8913dad088a9eadbbbb7a5d740fceccd57f9733e9112ce2bc
data/README.md CHANGED
@@ -45,7 +45,7 @@ puts hmc.version
45
45
  Retrieving managed systems that are powered on:
46
46
 
47
47
  ```ruby
48
- hc.managed_systems("State" => "operating")
48
+ hc.managed_systems("State==operating")
49
49
  ```
50
50
 
51
51
  Listing the logical partitions and virtual I/O servers of each managed system:
@@ -10,7 +10,7 @@ module IbmPowerHmc
10
10
  # HMC REST Client connection.
11
11
  class Connection
12
12
  ##
13
- # @!method initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true)
13
+ # @!method initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true, timeout: 60)
14
14
  # Create a new HMC connection.
15
15
  #
16
16
  # @param host [String] Hostname of the HMC.
@@ -18,6 +18,7 @@ module IbmPowerHmc
18
18
  # @param username [String] User name.
19
19
  # @param port [Integer] TCP port number.
20
20
  # @param validate_ssl [Boolean] Verify SSL certificates.
21
+ # @param timeout [Integer] The default HTTP timeout in seconds.
21
22
  def initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true, timeout: 60)
22
23
  @hostname = "#{host}:#{port}"
23
24
  @username = username
@@ -90,6 +91,29 @@ module IbmPowerHmc
90
91
  FeedParser.new(response.body).objects(:ManagedSystem)
91
92
  end
92
93
 
94
+ ##
95
+ # @!method managed_systems_quick
96
+ # Retrieve the list of systems managed by the HMC (using Quick API).
97
+ # @return [Array<Hash>] The list of managed systems.
98
+ def managed_systems_quick
99
+ method_url = "/rest/api/uom/ManagedSystem/quick/All"
100
+ response = request(:get, method_url)
101
+ JSON.parse(response.body)
102
+ end
103
+
104
+ ##
105
+ # @!method managed_system_quick(sys_uuid, property = nil)
106
+ # Retrieve information about a managed system (using Quick API).
107
+ # @param sys_uuid [String] The UUID of the managed system.
108
+ # @param property [String] The quick property name (optional).
109
+ # @return [Hash] The managed system.
110
+ def managed_system_quick(sys_uuid, property = nil)
111
+ method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/quick"
112
+ method_url += "/#{property}" unless property.nil?
113
+ response = request(:get, method_url)
114
+ JSON.parse(response.body)
115
+ end
116
+
93
117
  ##
94
118
  # @!method managed_system(lpar_uuid, sys_uuid = nil, group_name = nil)
95
119
  # Retrieve information about a managed system.
@@ -159,8 +183,9 @@ module IbmPowerHmc
159
183
  # @param lpar_uuid [String] The UUID of the logical partition.
160
184
  # @param new_name [String] The new name of the logical partition.
161
185
  def rename_lpar(lpar_uuid, new_name)
162
- method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"
163
- modify_object_attributes(method_url, {:name => new_name})
186
+ modify_object do
187
+ lpar(lpar_uuid).tap { |lpar| lpar.name = new_name }
188
+ end
164
189
  end
165
190
 
166
191
  ##
@@ -613,14 +638,21 @@ module IbmPowerHmc
613
638
  end
614
639
 
615
640
  ##
616
- # @!method template(template_uuid, changes)
617
- # modify_object_attributes wrapper for templates.
641
+ # @!method template_modify(template_uuid, changes)
642
+ # Modify a template.
618
643
  # @param template_uuid [String] UUID of the partition template to modify.
619
644
  # @param changes [Hash] Hash of changes to make.
620
- # @return [IbmPowerHmc::PartitionTemplate] The partition template.
621
645
  def template_modify(template_uuid, changes)
622
646
  method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}"
623
- modify_object_attributes(method_url, changes)
647
+
648
+ # Templates have no href so need to use modify_object_url.
649
+ modify_object_url(method_url) do
650
+ template(template_uuid).tap do |obj|
651
+ changes.each do |key, value|
652
+ obj.send("#{key}=", value)
653
+ end
654
+ end
655
+ end
624
656
  end
625
657
 
626
658
  ##
@@ -759,18 +791,20 @@ module IbmPowerHmc
759
791
  end
760
792
 
761
793
  ##
762
- # @!method next_events(wait = true)
794
+ # @!method next_events(timeout = -1)
763
795
  # Retrieve a list of events that occured since last call.
764
- # @param wait [Boolean] If no event is available, block until new events occur.
796
+ # @param timeout [Integer] The number of seconds to wait if no event is available.
797
+ # Specify -1 to wait indefinitely.
765
798
  # @return [Array<IbmPowerHmc::Event>] The list of events.
766
- def next_events(wait = true)
799
+ def next_events(timeout = -1)
767
800
  method_url = "/rest/api/uom/Event"
801
+ method_url += "?timeout=#{timeout}" if timeout >= 0
768
802
 
769
803
  response = nil
770
804
  loop do
771
805
  response = request(:get, method_url)
772
- # No need to sleep as the HMC already waits a bit before returning 204
773
- break if response.code != 204 || !wait
806
+ # The HMC waits "timeout" seconds (10 if not specified) before returning 204.
807
+ break if response.code != 204 || timeout >= 0
774
808
  end
775
809
  FeedParser.new(response.body).objects(:Event).map do |e|
776
810
  data = e.data.split("/") unless e.data.nil?
@@ -876,26 +910,26 @@ module IbmPowerHmc
876
910
  end
877
911
  end
878
912
 
879
- private
880
-
881
- # @!method modify_object(method_url, headers = {}, attempts = 5)
882
- # Modify an object at a specified URI.
883
- # @param method_url [String] The URL of the object to modify.
913
+ # @!method modify_object(headers = {}, attempts = 5)
914
+ # Post an IbmPowerHmc::AbstractRest object iteratively using ETag.
884
915
  # @param headers [Hash] HTTP headers.
885
916
  # @param attempts [Integer] Maximum number of retries.
886
- # @yield [obj] The object to modify.
887
- # @yieldparam obj [IbmPowerHmc::AbstractRest] The object to modify.
888
- def modify_object(method_url, headers = {}, attempts = 5)
889
- while attempts > 0
890
- response = request(:get, method_url)
891
- obj = Parser.new(response.body).object
917
+ # @yieldreturn [IbmPowerHmc::AbstractRest] The object to modify.
918
+ def modify_object(headers = {}, attempts = 5, &block)
919
+ modify_object_url(nil, headers, attempts, &block)
920
+ end
921
+
922
+ private
892
923
 
893
- yield obj
924
+ def modify_object_url(method_url = nil, headers = {}, attempts = 5)
925
+ while attempts > 0
926
+ obj = yield
927
+ raise "object has no href" if method_url.nil? && (!obj.kind_of?(AbstractRest) || obj.href.nil?)
894
928
 
895
929
  # Use ETag to ensure object has not changed.
896
930
  headers = headers.merge("If-Match" => obj.etag, :content_type => obj.content_type)
897
931
  begin
898
- request(:post, method_url, headers, obj.xml.to_s)
932
+ request(:post, method_url.nil? ? obj.href.path : method_url, headers, obj.xml.to_s)
899
933
  break
900
934
  rescue HttpError => e
901
935
  attempts -= 1
@@ -905,20 +939,6 @@ module IbmPowerHmc
905
939
  end
906
940
  end
907
941
 
908
- # @!method modify_object_attributes(method_url, changes, headers = {}, attempts = 5)
909
- # Modify an object at a specified URI.
910
- # @param method_url [String] The URL of the object to modify.
911
- # @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.
912
- # @param headers [Hash] HTTP headers.
913
- # @param attempts [Integer] Maximum number of retries.
914
- def modify_object_attributes(method_url, changes, headers = {}, attempts = 5)
915
- modify_object(method_url, headers, attempts) do |obj|
916
- changes.each do |key, value|
917
- obj.send("#{key}=", value)
918
- end
919
- end
920
- end
921
-
922
942
  ##
923
943
  # @!method network_adapter(vm_type, lpar_uuid, netadap_uuid)
924
944
  # Retrieve one or all virtual ethernet network adapters attached to a Logical Partition or a Virtual I/O Server.
@@ -159,12 +159,11 @@ module IbmPowerHmc
159
159
  end
160
160
 
161
161
  def collection_of(name, type)
162
- objtype = Module.const_get("IbmPowerHmc::#{type}")
163
162
  xml.get_elements([name, type].compact.join("/")).map do |elem|
164
- objtype.new(elem)
165
- end
166
- rescue
167
- []
163
+ Module.const_get("IbmPowerHmc::#{elem.name}").new(elem)
164
+ rescue NameError
165
+ nil
166
+ end.compact
168
167
  end
169
168
  end
170
169
 
@@ -221,11 +220,23 @@ module IbmPowerHmc
221
220
  ATTRS = {
222
221
  :name => "ManagementConsoleName",
223
222
  :build_level => "VersionInfo/BuildLevel",
223
+ :maint_level => "VersionInfo/Maintenance",
224
+ :sp_name => "VersionInfo/ServicePackName",
224
225
  :version => "BaseVersion",
225
226
  :ssh_pubkey => "PublicSSHKeyValue",
226
227
  :uvmid => "UVMID",
227
228
  :tz => "CurrentTimezone",
228
- :uptime => "ManagementConsoleUpTime"
229
+ :uptime => "ManagementConsoleUpTime",
230
+ :uom_version => "UserObjectModelVersion/MinorVersion",
231
+ :uom_schema => "UserObjectModelVersion/SchemaNamespace",
232
+ :templates_version => "TemplateObjectModelVersion/MinorVersion",
233
+ :templates_schema => "TemplateObjectModelVersion/SchemaNamespace",
234
+ :web_version => "WebObjectModelVersion/MinorVersion",
235
+ :web_schema => "WebObjectModelVersion/SchemaNamespace",
236
+ :session_timeout => "SessionTimeout",
237
+ :web_access => "RemoteWebAccess",
238
+ :ssh_access => "RemoteCommandAccess",
239
+ :vterm_access => "RemoteVirtualTerminalAccess"
229
240
  }.freeze
230
241
 
231
242
  def time
@@ -320,6 +331,10 @@ module IbmPowerHmc
320
331
  }.freeze
321
332
  end
322
333
 
334
+ class HostChannelAdapter < IOAdapter; end
335
+ class PhysicalFibreChannelAdapter < IOAdapter; end
336
+ class SRIOVAdapter < IOAdapter; end
337
+
323
338
  # Common class for LPAR and VIOS
324
339
  class BasePartition < AbstractRest
325
340
  ATTRS = {
@@ -360,6 +375,10 @@ module IbmPowerHmc
360
375
  def sriov_elp_uuids
361
376
  uuids_from_links("SRIOVEthernetLogicalPorts")
362
377
  end
378
+
379
+ def io_adapters
380
+ collection_of("PartitionIOConfiguration/ProfileIOSlots/ProfileIOSlot/AssociatedIOSlot/RelatedIOAdapter", "*[1]")
381
+ end
363
382
  end
364
383
 
365
384
  # Logical Partition information
@@ -927,6 +946,7 @@ module IbmPowerHmc
927
946
  :name => "partitionTemplateName",
928
947
  :description => "description",
929
948
  :lpar_name => "logicalPartitionConfig/partitionName",
949
+ :lpar_type => "logicalPartitionConfig/partitionType",
930
950
  :lpar_id => "logicalPartitionConfig/partitionId",
931
951
  :os => "logicalPartitionConfig/osVersion",
932
952
  :memory => "logicalPartitionConfig/memoryConfiguration/currMemory",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbmPowerHmc
4
- VERSION = "0.14.0"
4
+ VERSION = "0.16.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.14.0
4
+ version: 0.16.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-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client