Class: OneviewSDK::ImageStreamer::API300::GoldenImage
- Defined in:
- lib/oneview-sdk/image-streamer/resource/api300/golden_image.rb
Overview
Golden Image resource implementation for Image Streamer
Direct Known Subclasses
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
-
.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.
Instance Method Summary collapse
-
#download(file_path) ⇒ True
Downloads the content of the selected golden image to the specified file path.
-
#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.
-
#initialize(client, params = {}, api_ver = nil) ⇒ GoldenImage
constructor
Create a resource object, associate it with a client, and set its properties.
-
#set_build_plan(build_plan) ⇒ Object
Sets the build plan.
-
#set_os_volume(os_volume) ⇒ Object
Sets the OS volume.
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.
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.
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, , timeout = OneviewSDK::Rest::READ_TIMEOUT) = Hash[.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 ['name'] raise IncompleteResource, 'Please set the description of the golden image!' unless ['description'] data = client.upload_file(file_path, BASE_URI, { 'body' => }, 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.
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.
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
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
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 |