Class: IbmPowerHmc::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_power_hmc/apis/connection.rb,
lib/ibm_power_hmc/utils.rb,
lib/ibm_power_hmc/apis/pcm.rb,
lib/ibm_power_hmc/apis/sem.rb,
lib/ibm_power_hmc/apis/uom.rb,
lib/ibm_power_hmc/apis/templates.rb

Overview

HMC REST Client connection.

Defined Under Namespace

Classes: HttpError, HttpNotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: , password: , username: "hscroot", port: 12_443, validate_ssl: true, timeout: 60) ⇒ Connection

Create a new HMC connection.

Parameters:

  • host (String) (defaults to: )

    Hostname of the HMC.

  • password (String) (defaults to: )

    Password.

  • username (String) (defaults to: "hscroot")

    User name.

  • port (Integer) (defaults to: 12_443)

    TCP port number.

  • validate_ssl (Boolean) (defaults to: true)

    Verify SSL certificates.

  • timeout (Integer) (defaults to: 60)

    The default HTTP timeout in seconds.



23
24
25
26
27
28
29
30
# File 'lib/ibm_power_hmc/apis/connection.rb', line 23

def initialize(host:, password:, username: "hscroot", port: 12_443, validate_ssl: true, timeout: 60)
  @hostname = "#{host}:#{port}"
  @username = username
  @password = password
  @verify_ssl = validate_ssl
  @api_session_token = nil
  @timeout = timeout
end

Class Method Details

.format_time(time) ⇒ String

Convert ruby time to HMC time format.

Parameters:

  • time (Time)

    The ruby time to convert.

Returns:

  • (String)

    The time in HMC format.



131
132
133
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 131

def self.format_time(time)
  time.utc.xmlschema
end

Instance Method Details

#capture_lpar(lpar_uuid, sys_uuid, template_name, sync = true) ⇒ IbmPowerHmc::HmcJob

Capture partition configuration as template.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition.

  • sys_uuid (String)

    The UUID of the managed system.

  • template_name (String)

    The name to be given for the new template.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ibm_power_hmc/apis/templates.rb', line 46

def capture_lpar(lpar_uuid, sys_uuid, template_name, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/templates/PartitionTemplate/do/capture"
  params = {
    "TargetUuid"              => lpar_uuid,
    "NewTemplateName"         => template_name,
    "ManagedSystemUuid"       => sys_uuid,
    "K_X_API_SESSION_MEMENTO" => @api_session_token
  }
  job = HmcJob.new(self, method_url, "Capture", "PartitionTemplate", params)
  job.run if sync
  job
end

#chcomgmt(sys_uuid, status) ⇒ IbmPowerHmc::HmcJob

Change the co-management settings for a managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • status (String)

    The new co-management status (“rel”, “norm”, “keep”).

Returns:



692
693
694
695
696
697
698
699
# File 'lib/ibm_power_hmc/apis/uom.rb', line 692

def chcomgmt(sys_uuid, status)
  operation = status == "rel" ? "ReleaseController" : "RequestController"
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/do/#{operation}"

  params = {}
  params["coManagementControllerStatus"] = status unless status == "rel"
  HmcJob.new(self, method_url, operation, "ManagedSystem", params).tap(&:run)
end

#cli_run(hmc_uuid, cmd, sync = true) ⇒ IbmPowerHmc::HmcJob

Run a CLI command on the HMC as a job.

Parameters:

  • hmc_uuid (String)

    The UUID of the management console.

  • cmd (String)

    The command to run.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



708
709
710
711
712
713
714
715
716
717
718
# File 'lib/ibm_power_hmc/apis/uom.rb', line 708

def cli_run(hmc_uuid, cmd, sync = true)
  method_url = "/rest/api/uom/ManagementConsole/#{hmc_uuid}/do/CLIRunner"

  params = {
    "cmd" => cmd,
    "acknowledgeThisAPIMayGoAwayInTheFuture" => "true",
  }
  job = HmcJob.new(self, method_url, "CLIRunner", "ManagementConsole", params)
  job.run if sync
  job
end

#cluster(cl_uuid) ⇒ IbmPowerHmc::Cluster

Retrieve information about a cluster.

Parameters:

  • cl_uuid (String)

    The UUID of the cluster.

Returns:



488
489
490
491
492
# File 'lib/ibm_power_hmc/apis/uom.rb', line 488

def cluster(cl_uuid)
  method_url = "/rest/api/uom/Cluster/#{cl_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:Cluster)
end

#clusters(permissive = true) ⇒ Array<IbmPowerHmc::Cluster>

Retrieve the list of clusters managed by the HMC.

Parameters:

  • permissive (Boolean) (defaults to: true)

    Ignore errors generated from bad clusters.

Returns:



477
478
479
480
481
# File 'lib/ibm_power_hmc/apis/uom.rb', line 477

def clusters(permissive = true)
  method_url = "/rest/api/uom/Cluster#{'?ignoreError=true' if permissive}"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:Cluster)
end

#format_time(time) ⇒ String

Convert ruby time to HMC time format.

Parameters:

  • time (Time)

    The ruby time to convert.

Returns:

  • (String)

    The time in HMC format.



131
132
133
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 131

def self.format_time(time)
  time.utc.xmlschema
end

#groupsArray<IbmPowerHmc::Group>

Retrieve the list of groups defined on the HMC. A logical partition, a virtual I/O server or a managed system can be associated with multiple group tags.

Returns:



270
271
272
273
274
# File 'lib/ibm_power_hmc/apis/uom.rb', line 270

def groups
  method_url = "/rest/api/uom/Group"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:Group)
end

#grow_lu(cl_uuid, lu_uuid, capacity) ⇒ IbmPowerHmc::HmcJob

Increase the size of a logical unit in a cluster.

Parameters:

  • cl_uuid (String)

    The UUID of the cluster.

  • lu_uuid (String)

    The UUID of the logical unit.

  • capacity (Float)

    The new logical unit size (in GB).

Returns:



727
728
729
730
731
732
733
734
735
# File 'lib/ibm_power_hmc/apis/uom.rb', line 727

def grow_lu(cl_uuid, lu_uuid, capacity)
  method_url = "/rest/api/uom/Cluster/#{cl_uuid}/do/GrowLogicalUnit"

  params = {
    "LogicalUnitUDID" => lu_uuid,
    "Capacity" => capacity
  }
  HmcJob.new(self, method_url, "GrowLogicalUnit", "Cluster", params).tap(&:run)
end

#logoffObject

Close the session.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ibm_power_hmc/apis/connection.rb', line 59

def logoff
  # Don't want to trigger automatic logon here!
  return if @api_session_token.nil?

  method_url = "/rest/api/web/Logon"
  begin
    request(:delete, method_url)
  rescue
    # Ignore exceptions as this is best effort attempt to log off.
  end
  @api_session_token = nil
end

#logonString

Establish a trusted session with the Web Services APIs.

Returns:

  • (String)

    The X-API-Session token.

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ibm_power_hmc/apis/connection.rb', line 36

def logon
  method_url = "/rest/api/web/Logon"
  headers = {
    :content_type => "application/vnd.ibm.powervm.web+xml; type=LogonRequest"
  }
  doc = REXML::Document.new("")
  doc.add_element("LogonRequest", "schemaVersion" => "V1_1_0")
  doc.root.add_namespace(WEB_XMLNS)
  doc.root.add_element("UserID").text = @username
  doc.root.add_element("Password").text = @password

  @api_session_token = ""
  response = request(:put, method_url, headers, doc.to_s)
  doc = REXML::Document.new(response.body)
  elem = doc.elements["LogonResponse/X-API-Session"]
  raise Error, "LogonResponse/X-API-Session not found" if elem.nil?

  @api_session_token = elem.text
end

#lpar(lpar_uuid, sys_uuid = nil, group_name = nil) ⇒ IbmPowerHmc::LogicalPartition

Retrieve information about a logical partition.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition.

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



94
95
96
97
98
99
100
101
102
103
# File 'lib/ibm_power_hmc/apis/uom.rb', line 94

def lpar(lpar_uuid, sys_uuid = nil, group_name = nil)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/LogicalPartition/#{lpar_uuid}"
  end
  method_url += "?group=#{group_name}" unless group_name.nil?
  response = request(:get, method_url)
  Parser.new(response.body).object(:LogicalPartition)
end

#lpar_delete(lpar_uuid, delete_vios_mappings: false) ⇒ Object

Delete a logical partition.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition to delete.

  • delete_vios_mappings (Boolean) (defaults to: false)

    Delete associated VIOS VFC and VSCSI server adapters.



175
176
177
178
179
180
181
182
# File 'lib/ibm_power_hmc/apis/uom.rb', line 175

def lpar_delete(lpar_uuid, delete_vios_mappings: false)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}"

  lpar_delete_vios_mappings(lpar_uuid) if delete_vios_mappings

  request(:delete, method_url)
  # Returns HTTP 204 if ok
end

#lpar_delete_vios_mappings(lpar_uuid) ⇒ Object

Delete VIOS VSCSI and VFC mappings associated to a given logical partition.

Parameters:

  • lpar_uuid (String)

    The logical partition UUID.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ibm_power_hmc/utils.rb', line 9

def lpar_delete_vios_mappings(lpar_uuid)
  vscsi_client_adapter(lpar_uuid).concat(vfc_client_adapter(lpar_uuid)).group_by(&:vios_uuid).each do |vios_uuid, adapters|
    modify_object do
      vios(vios_uuid, nil, "ViosSCSIMapping,ViosFCMapping").tap do |vios|
        adapters.collect(&:server).each do |server|
          case server
          when VirtualSCSIServerAdapter
            vios.vscsi_mapping_delete!(server.location)
          when VirtualFibreChannelServerAdapter
            vios.vfc_mapping_delete!(server.location)
          end
        end
      end
    end
  end
end

#lpar_metrics(sys_uuid: , lpar_uuid: , start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false) ⇒ Array<Hash>

Retrieve metrics for a logical partition.

Parameters:

  • sys_uuid (String) (defaults to: )

    The managed system UUID.

  • lpar_uuid (String) (defaults to: )

    The logical partition UUID.

  • start_ts (Time) (defaults to: nil)

    Start timestamp.

  • end_ts (Time) (defaults to: nil)

    End timestamp.

  • no_samples (Integer) (defaults to: nil)

    Number of samples.

  • aggregated (Boolean) (defaults to: false)

    Retrieve aggregated metrics (default to Processed).

Returns:

  • (Array<Hash>)

    The metrics for the logical partition.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 104

def lpar_metrics(sys_uuid:, lpar_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
  type = aggregated ? "AggregatedMetrics" : "ProcessedMetrics"
  method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/LogicalPartition/#{lpar_uuid}/#{type}"
  query = {}
  query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
  query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
  query["NoOfSamples"] = no_samples unless no_samples.nil?
  method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?

  response = request(:get, method_url)
  FeedParser.new(response.body).entries do |entry|
    link = entry.elements["link"]
    next if link.nil?

    href = link.attributes["href"]
    next if href.nil?

    response = request(:get, href)
    JSON.parse(response.body)
  end.compact
end

#lpar_migrate(lpar_uuid, target_sys_name, sync = true) ⇒ Object

Migrate a logical partition to another managed system.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition to migrate.

  • target_sys_name (String)

    The managed system to migrate partition to.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/ibm_power_hmc/apis/uom.rb', line 158

def lpar_migrate(lpar_uuid, target_sys_name, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/Migrate"
  params = {
    "TargetManagedSystemName" => target_sys_name
  }
  HmcJob.new(self, method_url, "Migrate", "LogicalPartition", params).tap do |job|
    job.run if sync
  end
end

#lpar_migrate_validate(lpar_uuid, target_sys_name, sync = true) ⇒ Object

Validate if a logical partition can be migrated to another managed system.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition to migrate.

  • target_sys_name (String)

    The managed system to migrate partition to.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Raises:

  • (IbmPowerHmc::JobFailed)

    if validation fails



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ibm_power_hmc/apis/uom.rb', line 140

def lpar_migrate_validate(lpar_uuid, target_sys_name, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/MigrateValidate"
  params = {
    "TargetManagedSystemName" => target_sys_name
  }
  HmcJob.new(self, method_url, "MigrateValidate", "LogicalPartition", params).tap do |job|
    job.run if sync
  end
end

#lpar_quick_property(lpar_uuid, property_name) ⇒ String

Retrieve a quick property of a logical partition.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition.

  • property_name (String)

    The quick property name.

Returns:

  • (String)

    The quick property value.



126
127
128
129
130
131
# File 'lib/ibm_power_hmc/apis/uom.rb', line 126

def lpar_quick_property(lpar_uuid, property_name)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/quick/#{property_name}"

  response = request(:get, method_url)
  response.body[1..-2]
end

#lpars(sys_uuid = nil, search = nil, group_name = nil) ⇒ Array<IbmPowerHmc::LogicalPartition>

Retrieve the list of logical partitions managed by the HMC.

Parameters:

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

  • search (String) (defaults to: nil)

    The optional search criteria.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ibm_power_hmc/apis/uom.rb', line 75

def lpars(sys_uuid = nil, search = nil, group_name = nil)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition"
    method_url += "/search/(#{ERB::Util.url_encode(search)})" unless search.nil?
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/LogicalPartition"
  end
  method_url += "?group=#{group_name}" unless group_name.nil?
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:LogicalPartition)
end

#lpars_quick(sys_uuid = nil) ⇒ Array<Hash>

Retrieve the list of logical partitions managed by the HMC (using Quick API).

Parameters:

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

Returns:

  • (Array<Hash>)

    The list of logical partitions.



110
111
112
113
114
115
116
117
118
# File 'lib/ibm_power_hmc/apis/uom.rb', line 110

def lpars_quick(sys_uuid = nil)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition/quick/All"
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/LogicalPartition/quick/All"
  end
  response = request(:get, method_url)
  JSON.parse(response.body)
end

#managed_system(sys_uuid, group_name = nil) ⇒ IbmPowerHmc::ManagedSystem

Retrieve information about a managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



38
39
40
41
42
43
# File 'lib/ibm_power_hmc/apis/uom.rb', line 38

def managed_system(sys_uuid, group_name = nil)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}"
  method_url += "?group=#{group_name}" unless group_name.nil?
  response = request(:get, method_url)
  Parser.new(response.body).object(:ManagedSystem)
end

#managed_system_metrics(sys_uuid: , start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false) ⇒ Array<Hash>

Retrieve metrics for a managed system.

Parameters:

  • sys_uuid (String) (defaults to: )

    The managed system UUID.

  • start_ts (Time) (defaults to: nil)

    Start timestamp.

  • end_ts (Time) (defaults to: nil)

    End timestamp.

  • no_samples (Integer) (defaults to: nil)

    Number of samples.

  • aggregated (Boolean) (defaults to: false)

    Retrieve aggregated metrics (default to Processed).

Returns:

  • (Array<Hash>)

    The metrics for the managed system.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 66

def managed_system_metrics(sys_uuid:, start_ts: nil, end_ts: nil, no_samples: nil, aggregated: false)
  type = aggregated ? "AggregatedMetrics" : "ProcessedMetrics"
  method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/#{type}"
  query = {}
  query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
  query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
  query["NoOfSamples"] = no_samples unless no_samples.nil?
  method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?

  response = request(:get, method_url)
  FeedParser.new(response.body).entries do |entry|
    category = entry.elements["category"]
    next if category.nil?

    term = category.attributes["term"]
    next if term.nil? || term != "ManagedSystem"

    link = entry.elements["link"]
    next if link.nil?

    href = link.attributes["href"]
    next if href.nil?

    response = request(:get, href)
    JSON.parse(response.body)
  end.compact
end

#managed_system_pcm_preferences(sys_uuid) ⇒ IbmPowerHmc::ManagedSystemPcmPreference

Return Performance and Capacity Monitor preferences for a Managed System.

Parameters:

  • sys_uuid (String)

    The managed system UUID.

Returns:



24
25
26
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 24

def managed_system_pcm_preferences(sys_uuid)
  pcm_preferences.first.managed_system_preferences.find { |p| p.id.eql?(sys_uuid) }
end

#managed_system_quick(sys_uuid, property = nil) ⇒ Hash

Retrieve information about a managed system (using Quick API).

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • property (String) (defaults to: nil)

    The quick property name (optional).

Returns:

  • (Hash)

    The managed system.



61
62
63
64
65
66
# File 'lib/ibm_power_hmc/apis/uom.rb', line 61

def managed_system_quick(sys_uuid, property = nil)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/quick"
  method_url += "/#{property}" unless property.nil?
  response = request(:get, method_url)
  JSON.parse(response.body)
end

#managed_systems(search = nil, group_name = nil) ⇒ Array<IbmPowerHmc::ManagedSystem>

Retrieve the list of systems managed by the HMC.

Parameters:

  • search (String) (defaults to: nil)

    The optional search criteria.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



24
25
26
27
28
29
30
# File 'lib/ibm_power_hmc/apis/uom.rb', line 24

def managed_systems(search = nil, group_name = nil)
  method_url = "/rest/api/uom/ManagedSystem"
  method_url += "/search/(#{ERB::Util.url_encode(search)})" unless search.nil?
  method_url += "?group=#{group_name}" unless group_name.nil?
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:ManagedSystem)
end

#managed_systems_quickArray<Hash>

Retrieve the list of systems managed by the HMC (using Quick API).

Returns:

  • (Array<Hash>)

    The list of managed systems.



49
50
51
52
53
# File 'lib/ibm_power_hmc/apis/uom.rb', line 49

def managed_systems_quick
  method_url = "/rest/api/uom/ManagedSystem/quick/All"
  response = request(:get, method_url)
  JSON.parse(response.body)
end

#management_consoleIbmPowerHmc::ManagementConsole

Retrieve information about the management console.

Returns:



11
12
13
14
15
16
# File 'lib/ibm_power_hmc/apis/uom.rb', line 11

def management_console
  method_url = "/rest/api/uom/ManagementConsole"
  response = request(:get, method_url)
  # This request returns a feed with a single entry.
  FeedParser.new(response.body).objects(:ManagementConsole).first
end

#modify_object(headers = {}, attempts = 5) ⇒ Object

Post an IbmPowerHmc::AbstractRest object iteratively using ETag.

Parameters:

  • headers (Hash) (defaults to: {})

    HTTP headers.

  • attempts (Integer) (defaults to: 5)

    Maximum number of retries.

Yield Returns:



176
177
178
# File 'lib/ibm_power_hmc/apis/connection.rb', line 176

def modify_object(headers = {}, attempts = 5, &block)
  modify_object_url(nil, headers, attempts, &block)
end

#network_adapter_lpar(lpar_uuid, netadap_uuid = nil) ⇒ Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter

Retrieve one or all virtual ethernet network adapters attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • netadap_uuid (String) (defaults to: nil)

    UUID of the adapter to match (returns all adapters if omitted).

Returns:



328
329
330
# File 'lib/ibm_power_hmc/apis/uom.rb', line 328

def network_adapter_lpar(lpar_uuid, netadap_uuid = nil)
  network_adapter("LogicalPartition", lpar_uuid, netadap_uuid)
end

#network_adapter_lpar_create(lpar_uuid, sys_uuid, vswitch_uuid, **args) ⇒ IbmPowerHmc::ClientNetworkAdapter

Create a virtual ethernet network adapter attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • sys_uuid (String)

    UUID of the managed system of the virtual switch.

  • vswitch_uuid (String)

    UUID of the virtual switch.

  • args (Hash)

    The network adapter properties.

Returns:



363
364
365
366
367
368
369
370
371
372
# File 'lib/ibm_power_hmc/apis/uom.rb', line 363

def network_adapter_lpar_create(lpar_uuid, sys_uuid, vswitch_uuid, **args)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/ClientNetworkAdapter"
  headers = {
    :content_type => "application/vnd.ibm.powervm.uom+xml; type=ClientNetworkAdapter"
  }
  args[:vswitch_href] = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualSwitch/#{vswitch_uuid}"
  netadap = ClientNetworkAdapter.marshal(args)
  response = request(:put, method_url, headers, netadap.xml.to_s)
  Parser.new(response.body).object(:ClientNetworkAdapter)
end

#network_adapter_lpar_delete(lpar_uuid, netadap_uuid) ⇒ Object

Delete a virtual ethernet network adapter attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • netadap_uuid (String)

    UUID of the adapter to delete.



379
380
381
382
383
# File 'lib/ibm_power_hmc/apis/uom.rb', line 379

def network_adapter_lpar_delete(lpar_uuid, netadap_uuid)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/ClientNetworkAdapter/#{netadap_uuid}"
  request(:delete, method_url)
  # Returns HTTP 204 if ok
end

#network_adapter_vios(vios_uuid, netadap_uuid = nil) ⇒ Array<IbmPowerHmc::ClientNetworkAdapter>, IbmPowerHmc::ClientNetworkAdapter

Retrieve one or all virtual ethernet network adapters attached to a Virtual I/O Server.

Parameters:

  • vios_uuid (String)

    UUID of the Virtual I/O Server.

  • netadap_uuid (String) (defaults to: nil)

    UUID of the adapter to match (returns all adapters if omitted).

Returns:



338
339
340
# File 'lib/ibm_power_hmc/apis/uom.rb', line 338

def network_adapter_vios(vios_uuid, netadap_uuid = nil)
  network_adapter("VirtualIOServer", vios_uuid, netadap_uuid)
end

#next_events(wait = true) ⇒ Array<IbmPowerHmc::Event>

Retrieve a list of events that occured since last call.

Parameters:

  • wait (Boolean) (defaults to: true)

    If no event is available, block until new events occur.

Returns:



742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# File 'lib/ibm_power_hmc/apis/uom.rb', line 742

def next_events(wait = true)
  method_url = "/rest/api/uom/Event"

  response = nil
  loop do
    response = request(:get, method_url)
    # The HMC waits 10 seconds before returning 204 if there is no event.
    # There is a hidden "?timeout=X" option but it does not always work.
    # It will return "REST026C Maximum number of event requests exceeded"
    # after a while.
    break if response.code != 204 || !wait
  end
  FeedParser.new(response.body).objects(:Event).map do |e|
    data = e.data.split("/") unless e.data.nil?
    if !data.nil? && data.length >= 2 && data[-2].eql?("UserTask")
      e.usertask = usertask(data.last)
    end
    e
  end.compact
end

#pcm_preferencesArray<IbmPowerHmc::ManagementConsolePcmPreference>

Retrieve global Performance and Capacity Monitor preferences for the HMC.

Returns:



12
13
14
15
16
17
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 12

def pcm_preferences
  method_url = "/rest/api/pcm/preferences"

  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:ManagementConsolePcmPreference)
end

#phyp_metrics(sys_uuid: , start_ts: nil, end_ts: nil, short_term: false) ⇒ Array<Hash>

Retrieve PowerVM metrics for a given managed system.

Parameters:

  • sys_uuid (String) (defaults to: )

    The managed system UUID.

  • start_ts (Time) (defaults to: nil)

    Start timestamp.

  • end_ts (Time) (defaults to: nil)

    End timestamp.

  • short_term (Boolean) (defaults to: false)

    Retrieve short term monitor metrics (default to long term).

Returns:

  • (Array<Hash>)

    The PowerVM metrics for the managed system.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ibm_power_hmc/apis/pcm.rb', line 36

def phyp_metrics(sys_uuid:, start_ts: nil, end_ts: nil, short_term: false)
  type = short_term ? "ShortTermMonitor" : "LongTermMonitor"
  method_url = "/rest/api/pcm/ManagedSystem/#{sys_uuid}/RawMetrics/#{type}"
  query = {}
  query["StartTS"] = self.class.format_time(start_ts) unless start_ts.nil?
  query["EndTS"] = self.class.format_time(end_ts) unless end_ts.nil?
  method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?

  response = request(:get, method_url)
  FeedParser.new(response.body).entries do |entry|
    link = entry.elements["link"]
    next if link.nil?

    href = link.attributes["href"]
    next if href.nil?

    response = request(:get, href)
    JSON.parse(response.body)
  end.compact
end

#poweroff_lpar(lpar_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power off a logical partition.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



607
608
609
610
611
612
613
# File 'lib/ibm_power_hmc/apis/uom.rb', line 607

def poweroff_lpar(lpar_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/PowerOff"

  job = HmcJob.new(self, method_url, "PowerOff", "LogicalPartition", params)
  job.run if sync
  job
end

#poweroff_managed_system(sys_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power off a managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



663
664
665
666
667
668
669
# File 'lib/ibm_power_hmc/apis/uom.rb', line 663

def poweroff_managed_system(sys_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/do/PowerOff"

  job = HmcJob.new(self, method_url, "PowerOff", "ManagedSystem", params)
  job.run if sync
  job
end

#poweroff_vios(vios_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power off a virtual I/O server.

Parameters:

  • vios_uuid (String)

    The UUID of the virtual I/O server.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



635
636
637
638
639
640
641
# File 'lib/ibm_power_hmc/apis/uom.rb', line 635

def poweroff_vios(vios_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/do/PowerOff"

  job = HmcJob.new(self, method_url, "PowerOff", "VirtualIOServer", params)
  job.run if sync
  job
end

#poweron_lpar(lpar_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power on a logical partition.

Parameters:

  • lpar_uuid (String)

    The UUID of the logical partition.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



594
595
596
597
598
599
600
# File 'lib/ibm_power_hmc/apis/uom.rb', line 594

def poweron_lpar(lpar_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/do/PowerOn"

  job = HmcJob.new(self, method_url, "PowerOn", "LogicalPartition", params)
  job.run if sync
  job
end

#poweron_managed_system(sys_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power on a managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



650
651
652
653
654
655
656
# File 'lib/ibm_power_hmc/apis/uom.rb', line 650

def poweron_managed_system(sys_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/do/PowerOn"

  job = HmcJob.new(self, method_url, "PowerOn", "ManagedSystem", params)
  job.run if sync
  job
end

#poweron_vios(vios_uuid, params = {}, sync = true) ⇒ IbmPowerHmc::HmcJob

Power on a virtual I/O server.

Parameters:

  • vios_uuid (String)

    The UUID of the virtual I/O server.

  • params (Hash) (defaults to: {})

    Job parameters.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



622
623
624
625
626
627
628
# File 'lib/ibm_power_hmc/apis/uom.rb', line 622

def poweron_vios(vios_uuid, params = {}, sync = true)
  method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/do/PowerOn"

  job = HmcJob.new(self, method_url, "PowerOn", "VirtualIOServer", params)
  job.run if sync
  job
end

#remove_connection(hmc_uuid, sys_uuid, sync = true) ⇒ IbmPowerHmc::HmcJob

Remove a managed system from the management console.

Parameters:

  • hmc_uuid (String)

    The UUID of the management console.

  • sys_uuid (String)

    The UUID of the managed system.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



678
679
680
681
682
683
684
# File 'lib/ibm_power_hmc/apis/uom.rb', line 678

def remove_connection(hmc_uuid, sys_uuid, sync = true)
  method_url = "/rest/api/uom/ManagementConsole/#{hmc_uuid}/ManagedSystem/#{sys_uuid}/do/RemoveConnection"

  job = HmcJob.new(self, method_url, "RemoveConnection", "ManagedSystem")
  job.run if sync
  job
end

#request(method, url, headers = {}, payload = nil) ⇒ RestClient::Response

Perform a REST API request.

Parameters:

  • method (String)

    The HTTP method.

  • url (String)

    The method URL.

  • headers (Hash) (defaults to: {})

    HTTP headers.

  • payload (String) (defaults to: nil)

    HTTP request payload.

Returns:

  • (RestClient::Response)

    The response from the HMC.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/ibm_power_hmc/apis/connection.rb', line 142

def request(method, url, headers = {}, payload = nil)
  logon if @api_session_token.nil?
  reauth = false
  # Check for relative URLs
  url = "https://#{@hostname}#{url}" if url.start_with?("/")
  begin
    headers = headers.merge("X-API-Session" => @api_session_token)
    RestClient::Request.execute(
      :method => method,
      :url => url,
      :verify_ssl => @verify_ssl,
      :payload => payload,
      :headers => headers,
      :timeout => @timeout
    )
  rescue RestClient::Exception => e
    raise HttpNotFound.new(e), "Not found" if e.http_code == 404

    # Do not retry on failed logon attempts.
    if e.http_code == 401 && @api_session_token != "" && !reauth
      # Try to reauth.
      reauth = true
      logon
      retry
    end
    raise HttpError.new(e), "REST request failed"
  end
end

#schema(type) ⇒ REXML::Document

Retrieve the XML schema file for a given object type.

Parameters:

  • type (String)

    The object type (e.g. “LogicalPartition”, “inc/Types”)

Returns:

  • (REXML::Document)

    The XML schema file.



95
96
97
98
99
# File 'lib/ibm_power_hmc/apis/connection.rb', line 95

def schema(type)
  method_url = "/rest/api/web/schema/#{type}.xsd"
  response = request(:get, method_url)
  REXML::Document.new(response.body)
end

#serviceable_events(status = nil) ⇒ Array<IbmPowerHmc::ServiceableEvent>

Retrieve serviceable events from the HMC.

Parameters:

  • status (String) (defaults to: nil)

    Query only events in that state.

Returns:



13
14
15
16
17
18
# File 'lib/ibm_power_hmc/apis/sem.rb', line 13

def serviceable_events(status = nil)
  method_url = "/rest/api/sem/ServiceableEvent"
  method_url += "?status=#{status}" unless status.nil?
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:ServiceableEvent)
end

#shared_memory_pool(sys_uuid, pool_uuid = nil) ⇒ Array<IbmPowerHmc::SharedMemoryPool>, IbmPowerHmc::SharedMemoryPool

Retrieve information about Shared Memory Pools.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • pool_uuid (String) (defaults to: nil)

    The UUID of the shared memory pool (return all pools if omitted)

Returns:



575
576
577
578
579
580
581
582
583
584
585
# File 'lib/ibm_power_hmc/apis/uom.rb', line 575

def shared_memory_pool(sys_uuid, pool_uuid = nil)
  if pool_uuid.nil?
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/SharedMemoryPool"
    response = request(:get, method_url)
    FeedParser.new(response.body).objects(:SharedMemoryPool)
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/SharedMemoryPool/#{pool_uuid}"
    response = request(:get, method_url)
    Parser.new(response.body).object(:SharedMemoryPool)
  end
end

#shared_processor_pool(sys_uuid, pool_uuid = nil) ⇒ Array<IbmPowerHmc::SharedProcessorPool>, IbmPowerHmc::SharedProcessorPool

Retrieve information about Shared Processor Pools.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

  • pool_uuid (String) (defaults to: nil)

    The UUID of the shared processor pool (return all pools if omitted)

Returns:



557
558
559
560
561
562
563
564
565
566
567
# File 'lib/ibm_power_hmc/apis/uom.rb', line 557

def shared_processor_pool(sys_uuid, pool_uuid = nil)
  if pool_uuid.nil?
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/SharedProcessorPool"
    response = request(:get, method_url)
    FeedParser.new(response.body).objects(:SharedProcessorPool)
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/SharedProcessorPool/#{pool_uuid}"
    response = request(:get, method_url)
    Parser.new(response.body).object(:SharedProcessorPool)
  end
end

#sriov_elp_lpar(lpar_uuid, sriov_elp_uuid = nil) ⇒ Array<IbmPowerHmc::SRIOVEthernetLogicalPort>, IbmPowerHmc::SRIOVEthernetLogicalPort

Retrieve one or all SR-IOV ethernet logical ports attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • sriov_elp_uuid (String) (defaults to: nil)

    UUID of the port to match (returns all ports if omitted).

Returns:



391
392
393
# File 'lib/ibm_power_hmc/apis/uom.rb', line 391

def sriov_elp_lpar(lpar_uuid, sriov_elp_uuid = nil)
  sriov_elp("LogicalPartition", lpar_uuid, sriov_elp_uuid)
end

#sriov_elp_vios(vios_uuid, sriov_elp_uuid = nil) ⇒ Array<IbmPowerHmc::SRIOVEthernetLogicalPort>, IbmPowerHmc::SRIOVEthernetLogicalPort

Retrieve one or all SR-IOV ethernet logical ports attached to a Virtual I/O Server.

Parameters:

  • vios_uuid (String)

    UUID of the Virtual I/O Server.

  • sriov_elp_uuid (String) (defaults to: nil)

    UUID of the port to match (returns all ports if omitted).

Returns:



401
402
403
# File 'lib/ibm_power_hmc/apis/uom.rb', line 401

def sriov_elp_vios(vios_uuid, sriov_elp_uuid = nil)
  sriov_elp("VirtualIOServer", vios_uuid, sriov_elp_uuid)
end

#ssp(ssp_uuid) ⇒ IbmPowerHmc::SharedStoragePool

Retrieve information about a shared storage pool.

Parameters:

  • ssp_uuid (String)

    The UUID of the shared storage pool.

Returns:



510
511
512
513
514
# File 'lib/ibm_power_hmc/apis/uom.rb', line 510

def ssp(ssp_uuid)
  method_url = "/rest/api/uom/SharedStoragePool/#{ssp_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:SharedStoragePool)
end

#ssps(permissive = true) ⇒ Array<IbmPowerHmc::SharedStoragePool>

Retrieve the list of shared storage pools managed by the HMC.

Parameters:

  • permissive (Boolean) (defaults to: true)

    Ignore errors generated from bad clusters.

Returns:



499
500
501
502
503
# File 'lib/ibm_power_hmc/apis/uom.rb', line 499

def ssps(permissive = true)
  method_url = "/rest/api/uom/SharedStoragePool#{'?ignoreError=true' if permissive}"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:SharedStoragePool)
end

#template(template_uuid) ⇒ IbmPowerHmc::PartitionTemplate

Retrieve details for a particular partition template.

Parameters:

  • template_uuid (String)

    UUID of the partition template.

Returns:



32
33
34
35
36
# File 'lib/ibm_power_hmc/apis/templates.rb', line 32

def template(template_uuid)
  method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:PartitionTemplate)
end

#template_check(template_uuid, target_sys_uuid, sync = true) ⇒ IbmPowerHmc::HmcJob

Start Template Check job (first of three steps to deploy an LPAR from a Template).

Parameters:

  • template_uuid (String)

    The UUID of the Template to deploy an LPAR from.

  • target_sys_uuid (String)

    The UUID of the Managed System to deploy the LPAR on.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ibm_power_hmc/apis/templates.rb', line 68

def template_check(template_uuid, target_sys_uuid, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}/do/check"
  params = {
    "TargetUuid"              => target_sys_uuid,
    "K_X_API_SESSION_MEMENTO" => @api_session_token
  }
  job = HmcJob.new(self, method_url, "Check", "PartitionTemplate", params)
  job.run if sync
  job
end

#template_copy(template_uuid, new_name) ⇒ IbmPowerHmc::PartitionTemplate

Copy existing template to a new one.

Parameters:

  • template_uuid (String)

    UUID of the partition template to copy.

  • new_name (String)

    Name of the new template.

Returns:



146
147
148
149
150
151
152
153
154
155
# File 'lib/ibm_power_hmc/apis/templates.rb', line 146

def template_copy(template_uuid, new_name)
  method_url = "/rest/api/templates/PartitionTemplate"
  headers = {
    :content_type => "application/vnd.ibm.powervm.templates+xml;type=PartitionTemplate"
  }
  original = template(template_uuid)
  original.name = new_name
  response = request(:put, method_url, headers, original.xml.to_s)
  Parser.new(response.body).object(:PartitionTemplate)
end

#template_deploy(draft_template_uuid, target_sys_uuid, sync = true) ⇒ IbmPowerHmc::HmcJob

Start Template Deploy job (last of three steps to deploy an LPAR from a Template).

Parameters:

  • draft_template_uuid (String)

    The UUID of the Draft Template created by the Template Check job.

  • target_sys_uuid (String)

    The UUID of the Managed System to deploy the LPAR on.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ibm_power_hmc/apis/templates.rb', line 108

def template_deploy(draft_template_uuid, target_sys_uuid, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/deploy"
  params = {
    "TargetUuid"              => target_sys_uuid,
    "TemplateUuid"            => draft_template_uuid,
    "K_X_API_SESSION_MEMENTO" => @api_session_token
  }
  job = HmcJob.new(self, method_url, "Deploy", "PartitionTemplate", params)
  job.run if sync
  job
end

#template_modify(template_uuid, changes) ⇒ Object

Modify a template.

Parameters:

  • template_uuid (String)

    UUID of the partition template to modify.

  • changes (Hash)

    Hash of changes to make.



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ibm_power_hmc/apis/templates.rb', line 127

def template_modify(template_uuid, changes)
  method_url = "/rest/api/templates/PartitionTemplate/#{template_uuid}"

  # Templates have no href so need to use modify_object_url.
  modify_object_url(method_url) do
    template(template_uuid).tap do |obj|
      changes.each do |key, value|
        obj.send("#{key}=", value)
      end
    end
  end
end

#template_provision(template_uuid, target_sys_uuid, changes) ⇒ String

Deploy Logical Partition from a Template (performs Check, Transform and Deploy steps in a single method).

Parameters:

  • template_uuid (String)

    The UUID of the Template to deploy an LPAR from.

  • target_sys_uuid (String)

    The UUID of the Managed System to deploy the LPAR on.

  • changes (Hash)

    Modifications to apply to the Template before deploying Logical Partition.

Returns:

  • (String)

    The UUID of the deployed Logical Partition.



33
34
35
36
37
38
# File 'lib/ibm_power_hmc/utils.rb', line 33

def template_provision(template_uuid, target_sys_uuid, changes)
  draft_uuid = template_check(template_uuid, target_sys_uuid).results["TEMPLATE_UUID"]
  template_transform(draft_uuid, target_sys_uuid)
  template_modify(draft_uuid, changes)
  template_deploy(draft_uuid, target_sys_uuid).results["PartitionUuid"]
end

#template_transform(draft_template_uuid, target_sys_uuid, sync = true) ⇒ IbmPowerHmc::HmcJob

Start Template Transform job (second of three steps to deploy an LPAR from a Template).

Parameters:

  • draft_template_uuid (String)

    The UUID of the Draft Template created by the Template Check job.

  • target_sys_uuid (String)

    The UUID of the Managed System to deploy the LPAR on.

  • sync (Boolean) (defaults to: true)

    Start the job and wait for its completion.

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ibm_power_hmc/apis/templates.rb', line 88

def template_transform(draft_template_uuid, target_sys_uuid, sync = true)
  # Need to include session token in payload so make sure we are logged in
  logon if @api_session_token.nil?
  method_url = "/rest/api/templates/PartitionTemplate/#{draft_template_uuid}/do/transform"
  params = {
    "TargetUuid"              => target_sys_uuid,
    "K_X_API_SESSION_MEMENTO" => @api_session_token
  }
  job = HmcJob.new(self, method_url, "Transform", "PartitionTemplate", params)
  job.run if sync
  job
end

#templates(draft = false) ⇒ Array<IbmPowerHmc::PartitionTemplate>

Retrieve the list of partition templates.

Parameters:

  • draft (Boolean) (defaults to: false)

    Retrieve draft templates as well

Returns:



21
22
23
24
25
# File 'lib/ibm_power_hmc/apis/templates.rb', line 21

def templates(draft = false)
  method_url = "/rest/api/templates/PartitionTemplate?detail=full#{'&draft=false' unless draft}"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:PartitionTemplate)
end

#templates_summary(draft = false) ⇒ Array<IbmPowerHmc::PartitionTemplateSummary>

Retrieve the list of partition template summaries.

Parameters:

  • draft (Boolean) (defaults to: false)

    Retrieve draft templates as well

Returns:



10
11
12
13
14
# File 'lib/ibm_power_hmc/apis/templates.rb', line 10

def templates_summary(draft = false)
  method_url = "/rest/api/templates/PartitionTemplate#{'?draft=false' unless draft}"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:PartitionTemplateSummary)
end

#tier(tier_uuid, ssp_uuid = nil, group_name = nil) ⇒ IbmPowerHmc::Tier

Retrieve information about a tier.

Parameters:

  • tier_uuid (String)

    The UUID of the tier.

  • ssp_uuid (String) (defaults to: nil)

    The UUID of the shared storage pool.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



539
540
541
542
543
544
545
546
547
548
549
# File 'lib/ibm_power_hmc/apis/uom.rb', line 539

def tier(tier_uuid, ssp_uuid = nil, group_name = nil)
  if ssp_uuid.nil?
    method_url = "/rest/api/uom/Tier/#{tier_uuid}"
  else
    method_url = "/rest/api/uom/SharedStoragePool/#{ssp_uuid}/Tier/#{tier_uuid}"
  end
  method_url += "?group=#{group_name}" unless group_name.nil?

  response = request(:get, method_url)
  Parser.new(response.body).object(:Tier)
end

#tiers(group_name = nil, permissive = true) ⇒ Array<IbmPowerHmc::Tier>

Retrieve the list of tiers that are part of shared storage pools managed by the HMC.

Parameters:

  • group_name (String) (defaults to: nil)

    The extended group attributes.

  • permissive (Boolean) (defaults to: true)

    Ignore errors generated from bad clusters.

Returns:



522
523
524
525
526
527
528
529
530
# File 'lib/ibm_power_hmc/apis/uom.rb', line 522

def tiers(group_name = nil, permissive = true)
  method_url = "/rest/api/uom/Tier"
  query = {}
  query["group"] = group_name unless group_name.nil?
  query["ignoreError"] = "true" if permissive
  method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:Tier)
end

#usertask(uuid = true) ⇒ Hash

Retrieve details of an event of type “user task”.

Parameters:

  • uuid (String) (defaults to: true)

    UUID of user task.

Returns:

  • (Hash)

    Hash of user task attributes.



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ibm_power_hmc/apis/connection.rb', line 77

def usertask(uuid)
  method_url = "/rest/api/ui/UserTask/#{uuid}"
  response = request(:get, method_url)
  j = JSON.parse(response.body)
  if j['status'].eql?("Completed")
    case j['key']
    when "TEMPLATE_PARTITION_SAVE", "TEMPLATE_PARTITION_SAVE_AS", "TEMPLATE_PARTITION_CAPTURE"
      j['template_uuid'] = templates_summary.find { |t| t.name.eql?(j['labelParams'].first) }&.uuid
    end
  end
  j
end

#vfc_client_adapter(lpar_uuid, adap_uuid = nil) ⇒ Array<IbmPowerHmc::VirtualFibreChannelClientAdapter>, IbmPowerHmc::VirtualFibreChannelClientAdapter

Retrieve one or all virtual Fibre Channel storage client adapters attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • adap_uuid (String) (defaults to: nil)

    UUID of the adapter to match (returns all adapters if omitted).

Returns:



460
461
462
463
464
465
466
467
468
469
470
# File 'lib/ibm_power_hmc/apis/uom.rb', line 460

def vfc_client_adapter(lpar_uuid, adap_uuid = nil)
  if adap_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualFibreChannelClientAdapter"
    response = request(:get, method_url)
    FeedParser.new(response.body).objects(:VirtualFibreChannelClientAdapter)
  else
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualFibreChannelClientAdapter/#{adap_uuid}"
    response = request(:get, method_url)
    Parser.new(response.body).object(:VirtualFibreChannelClientAdapter)
  end
end

#vios(vios_uuid, sys_uuid = nil, group_name = nil) ⇒ IbmPowerHmc::VirtualIOServer

Retrieve information about a virtual I/O server.

Parameters:

  • vios_uuid (String)

    The UUID of the virtual I/O server.

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

Returns:



215
216
217
218
219
220
221
222
223
224
# File 'lib/ibm_power_hmc/apis/uom.rb', line 215

def vios(vios_uuid, sys_uuid = nil, group_name = nil)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}"
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualIOServer/#{vios_uuid}"
  end
  method_url += "?group=#{group_name}" unless group_name.nil?
  response = request(:get, method_url)
  Parser.new(response.body).object(:VirtualIOServer)
end

#vioses(sys_uuid = nil, search = nil, group_name = nil, permissive = true) ⇒ Array<IbmPowerHmc::VirtualIOServer>

Retrieve the list of virtual I/O servers managed by the HMC.

Parameters:

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

  • search (String) (defaults to: nil)

    The optional search criteria.

  • group_name (String) (defaults to: nil)

    The extended group attributes.

  • permissive (Boolean) (defaults to: true)

    Skip virtual I/O servers that have error conditions.

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/ibm_power_hmc/apis/uom.rb', line 192

def vioses(sys_uuid = nil, search = nil, group_name = nil, permissive = true)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/VirtualIOServer"
    method_url += "/search/(#{ERB::Util.url_encode(search)})" unless search.nil?
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualIOServer"
  end
  query = {}
  query["group"] = group_name unless group_name.nil?
  query["ignoreError"] = "true" if permissive
  method_url += "?" + query.map { |h| h.join("=") }.join("&") unless query.empty?

  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:VirtualIOServer)
end

#vioses_quick(sys_uuid = nil) ⇒ Array<Hash>

Retrieve the list of virtual I/O servers managed by the HMC (using Quick API).

Parameters:

  • sys_uuid (String) (defaults to: nil)

    The UUID of the managed system.

Returns:

  • (Array<Hash>)

    The list of virtual I/O servers.



231
232
233
234
235
236
237
238
239
# File 'lib/ibm_power_hmc/apis/uom.rb', line 231

def vioses_quick(sys_uuid = nil)
  if sys_uuid.nil?
    method_url = "/rest/api/uom/VirtualIOServer/quick/All"
  else
    method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualIOServer/quick/All"
  end
  response = request(:get, method_url)
  JSON.parse(response.body)
end

#virtual_network(vnet_uuid, sys_uuid) ⇒ IbmPowerHmc::VirtualNetwork

Retrieve information about a virtual network.

Parameters:

  • vnet_uuid (String)

    The UUID of the virtual network.

  • sys_uuid (String)

    The UUID of the managed system.

Returns:



316
317
318
319
320
# File 'lib/ibm_power_hmc/apis/uom.rb', line 316

def virtual_network(vnet_uuid, sys_uuid)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualNetwork/#{vnet_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:VirtualNetwork)
end

#virtual_networks(sys_uuid) ⇒ Array<IbmPowerHmc::VirtualNetwork>

Retrieve the list of virtual networks from a specified managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

Returns:



304
305
306
307
308
# File 'lib/ibm_power_hmc/apis/uom.rb', line 304

def virtual_networks(sys_uuid)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualNetwork"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:VirtualNetwork)
end

#virtual_switch(vswitch_uuid, sys_uuid) ⇒ IbmPowerHmc::VirtualSwitch

Retrieve information about a virtual switch.

Parameters:

  • vswitch_uuid (String)

    The UUID of the virtual switch.

  • sys_uuid (String)

    The UUID of the managed system.

Returns:



293
294
295
296
297
# File 'lib/ibm_power_hmc/apis/uom.rb', line 293

def virtual_switch(vswitch_uuid, sys_uuid)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualSwitch/#{vswitch_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:VirtualSwitch)
end

#virtual_switches(sys_uuid) ⇒ Array<IbmPowerHmc::VirtualSwitch>

Retrieve the list of virtual switches from a specified managed system.

Parameters:

  • sys_uuid (String)

    The UUID of the managed system.

Returns:



281
282
283
284
285
# File 'lib/ibm_power_hmc/apis/uom.rb', line 281

def virtual_switches(sys_uuid)
  method_url = "/rest/api/uom/ManagedSystem/#{sys_uuid}/VirtualSwitch"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:VirtualSwitch)
end

#vnic_dedicated(lpar_uuid, vnic_uuid = nil) ⇒ Array<IbmPowerHmc::VirtualNICDedicated>, IbmPowerHmc::VirtualNICDedicated

Retrieve one or all dedicated virtual network interface controller (vNIC) attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • vnic_uuid (String) (defaults to: nil)

    UUID of the vNIC to match (returns all vNICs if omitted).

Returns:



424
425
426
427
428
429
430
431
432
433
434
# File 'lib/ibm_power_hmc/apis/uom.rb', line 424

def vnic_dedicated(lpar_uuid, vnic_uuid = nil)
  if vnic_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualNICDedicated"
    response = request(:get, method_url)
    FeedParser.new(response.body).objects(:VirtualNICDedicated)
  else
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualNICDedicated/#{vnic_uuid}"
    response = request(:get, method_url)
    Parser.new(response.body).object(:VirtualNICDedicated)
  end
end

#volume_group(vios_uuid, vg_uuid) ⇒ IbmPowerHmc::VolumeGroup

Retrieve information about a volume group on a virtual I/O server.

Parameters:

  • vios_uuid (String)

    The UUID of the virtual I/O server.

  • vg_uuid (String)

    The UUID of the volume group.

Returns:



258
259
260
261
262
# File 'lib/ibm_power_hmc/apis/uom.rb', line 258

def volume_group(vios_uuid, vg_uuid)
  method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/VolumeGroup/#{vg_uuid}"
  response = request(:get, method_url)
  Parser.new(response.body).object(:VolumeGroup)
end

#volume_groups(vios_uuid) ⇒ Array<IbmPowerHmc::VolumeGroup>

Retrieve the list of volume groups available on a virtual I/O server.

Parameters:

  • vios_uuid (String)

    The UUID of the virtual I/O server.

Returns:



246
247
248
249
250
# File 'lib/ibm_power_hmc/apis/uom.rb', line 246

def volume_groups(vios_uuid)
  method_url = "/rest/api/uom/VirtualIOServer/#{vios_uuid}/VolumeGroup"
  response = request(:get, method_url)
  FeedParser.new(response.body).objects(:VolumeGroup)
end

#vscsi_client_adapter(lpar_uuid, adap_uuid = nil) ⇒ Array<IbmPowerHmc::VirtualSCSIClientAdapter>, IbmPowerHmc::VirtualSCSIClientAdapter

Retrieve one or all virtual SCSI storage client adapters attached to a logical partition.

Parameters:

  • lpar_uuid (String)

    UUID of the logical partition.

  • adap_uuid (String) (defaults to: nil)

    UUID of the adapter to match (returns all adapters if omitted).

Returns:



442
443
444
445
446
447
448
449
450
451
452
# File 'lib/ibm_power_hmc/apis/uom.rb', line 442

def vscsi_client_adapter(lpar_uuid, adap_uuid = nil)
  if adap_uuid.nil?
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualSCSIClientAdapter"
    response = request(:get, method_url)
    FeedParser.new(response.body).objects(:VirtualSCSIClientAdapter)
  else
    method_url = "/rest/api/uom/LogicalPartition/#{lpar_uuid}/VirtualSCSIClientAdapter/#{adap_uuid}"
    response = request(:get, method_url)
    Parser.new(response.body).object(:VirtualSCSIClientAdapter)
  end
end