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 sucessful, 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
# 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|
      response = http.request(req)
      data = client.response_handler(response)
      return OneviewSDK::FirmwareDriver.new(client, data)
    end
  end
end