Class: OneviewSDK::ImageStreamer::API300::GoldenImage

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb

Overview

Golden Image resource implementation for Image Streamer

Constant Summary collapse

BASE_URI =
'/rest/golden-images'.freeze
ACCEPTED_FORMATS =

Supported upload extensions

%w[.zip .ZIP].freeze

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create, #create!, #deep_merge!, #delete, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file, #update

Constructor Details

#initialize(client, params = {}, api_ver = nil) ⇒ GoldenImage

Create a resource object, associate it with a client, and set its properties.

Parameters:

  • client (OneviewSDK::ImageStreamer::Client)

    The client object for the Image Streamer appliance

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

    The options for this resource (key-value pairs)

  • api_ver (Integer) (defaults to: nil)

    The api version to use when interracting with this resource.



26
27
28
29
30
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 26

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values:
  @data['type'] ||= 'GoldenImage'
end

Class Method Details

.add(client, file_path, data_options, timeout = OneviewSDK::Rest::READ_TIMEOUT) ⇒ OneviewSDK::ImageStreamer::API300::GoldenImage

Upload a golden image from the specified local file path. Only the .zip format file can be used for upload.

Parameters:

  • client (OneviewSDK::ImageStreamer::Client)

    The client object for the Image Streamer appliance

  • file_path (String)
  • data_options (Hash)

    Attributes of the golden image, passed in the request

  • timeout (Integer) (defaults to: OneviewSDK::Rest::READ_TIMEOUT)

    The number of seconds to wait for the request to complete

Options Hash (data_options):

  • :name (String)

    The name of the Golden Image (required)

  • :description (String)

    The description of the Golden Image (required)

Returns:

Raises:



60
61
62
63
64
65
66
67
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 60

def self.add(client, file_path, data_options, timeout = OneviewSDK::Rest::READ_TIMEOUT)
  data_options = Hash[data_options.map { |k, v| [k.to_s, v] }] # Convert symbols hash keys to string
  raise InvalidFormat, 'ERROR: File with extension not supported!' unless ACCEPTED_FORMATS.include? File.extname(file_path)
  raise IncompleteResource, 'Please set the name of the golden image!' unless data_options['name']
  raise IncompleteResource, 'Please set the description of the golden image!' unless data_options['description']
  data = client.upload_file(file_path, BASE_URI, { 'body' => data_options }, timeout)
  GoldenImage.new(client, data)
end

Instance Method Details

#download(file_path) ⇒ True

Downloads the content of the selected golden image to the specified file path.

Parameters:

  • file_path (String)
  • timeout (Integer)

    The number of seconds to wait for the request to complete

Returns:

  • (True)

    When it was saved successfully



46
47
48
49
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 46

def download(file_path)
  ensure_client && ensure_uri
  client.download_file("#{BASE_URI}/download/#{@data['uri'].split('/').last}", file_path)
end

#download_details_archive(file_path) ⇒ True

Download the details of the golden image capture logs which has been archived based on the specific attribute ID.

Parameters:

  • file_path (String)

Returns:

  • (True)

    When was saved successfully



35
36
37
38
39
40
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 35

def download_details_archive(file_path)
  ensure_client && ensure_uri
  resp = @client.rest_api(:get, "#{BASE_URI}/archive/#{@data['uri'].split('/').last}")
  File.open(file_path, 'wb') { |file| file.write(resp.body) }
  true
end

#set_build_plan(build_plan) ⇒ Object

Sets the build plan

Parameters:

Raises:



81
82
83
84
85
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 81

def set_build_plan(build_plan)
  build_plan.retrieve! unless build_plan['uri']
  raise NotFound, 'The build plan was not found!' unless build_plan['uri']
  set('buildPlanUri', build_plan['uri'])
end

#set_os_volume(os_volume) ⇒ Object

Sets the OS volume

Parameters:

Raises:



72
73
74
75
76
# File 'lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb', line 72

def set_os_volume(os_volume)
  os_volume.retrieve! unless os_volume['uri']
  raise NotFound, 'The os volume was not found!' unless os_volume['uri']
  set('osVolumeURI', os_volume['uri'])
end