Class: OneviewSDK::API200::FirmwareBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/oneview-sdk/resource/api200/firmware_bundle.rb

Overview

Firmware bundle resource implementation

Constant Summary collapse

BASE_URI =
'/rest/firmware-bundles'.freeze
READ_TIMEOUT =

in seconds, 5 minutes

300

Class Method Summary collapse

Class Method Details

.add(client, file_path, timeout = READ_TIMEOUT) ⇒ OneviewSDK::FirmwareDriver

Uploads a firmware bundle file

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • file_path (String)
  • timeout (Integer) (defaults to: READ_TIMEOUT)

    The number of seconds to wait for completing the request

Returns:

  • (OneviewSDK::FirmwareDriver)

    if the upload was successful, return a FirmwareDriver object

Raises:


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/oneview-sdk/resource/api200/firmware_bundle.rb', line 26

def self.add(client, file_path, timeout = READ_TIMEOUT)
  raise NotFound, "ERROR: File '#{file_path}' not found!" unless File.file?(file_path)
  options = {}
  options['Content-Type'] = 'multipart/form-data'
  options['X-Api-Version'] = client.api_version.to_s
  options['auth'] = client.token
  options['uploadfilename'] = File.basename(file_path)
  url = URI.parse(URI.escape("#{client.url}#{BASE_URI}"))

  File.open(file_path) do |file|
    req = Net::HTTP::Post::Multipart.new(
      url.path,
      { 'file' => UploadIO.new(file, 'application/octet-stream', File.basename(file_path)) },
      options
    )

    http_request = Net::HTTP.new(url.host, url.port)
    http_request.use_ssl = true
    http_request.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http_request.read_timeout = timeout

    http_request.start do |http|
      begin
        response = http.request(req)
        data = client.response_handler(response)
        return OneviewSDK::FirmwareDriver.new(client, data)
      rescue Net::ReadTimeout
        raise "The connection was closed because the timeout of #{timeout} seconds has expired."\
          'You can specify the timeout in seconds by passing the timeout on the method call.'\
          'Interrupted firmware uploads may result in corrupted firmware remaining in the appliance.'\
          'HPE recommends checking the appliance for corrupted firmware and removing it.'
      end
    end
  end
end