Class: OneviewSDK::ImageStreamer::API300::ArtifactBundle

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

Overview

Artifacts Bundle resource implementation for Image Streamer

Constant Summary collapse

ACCEPTED_FORMATS =

Supported upload extensions

%w(.zip .ZIP).freeze
BASE_URI =
'/rest/artifact-bundles'.freeze
BACKUPS_URI =
"#{BASE_URI}/backups".freeze
BACKUPS_ARCHIVE_URI =
"#{BACKUPS_URI}/archive".freeze

Constants inherited from Resource

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!, #delete, #each, #eql?, #exists?, find_by, from_file, get_all, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file

Constructor Details

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

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.



29
30
31
32
33
34
35
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 29

def initialize(client, params = {}, api_ver = nil)
  super
  @data['buildPlans']      ||= []
  @data['planScripts']     ||= []
  @data['deploymentPlans'] ||= []
  @data['goldenImages']    ||= []
end

Class Method Details

.create_backup(client, deployment_group) ⇒ Hash

Creates a backup bundle with all the artifacts present on the appliance.

Parameters:

Returns:

  • (Hash)

    The result hash with DeploymentGroup data



69
70
71
72
73
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 69

def self.create_backup(client, deployment_group)
  ensure_resource!(deployment_group)
  response = client.rest_post(BACKUPS_URI, 'body' => { 'deploymentGroupURI' => deployment_group['uri'] })
  client.response_handler(response)
end

.create_backup_from_file!(client, deployment_group, file_path, artifact_name, timeout = OneviewSDK::Rest::READ_TIMEOUT) ⇒ Hash

Creates a backup bundle from the zip file and extract all the artifacts present in the uploaded file

If there are any artifacts existing, they will be removed before the extract operation.

Parameters:

  • client (OneviewSDK::ImageStreamer::Client)

    The client object for the Image Streamer appliance

  • file_path (String)

    The file path with file extension

  • artifact_name (String)

    The name for the artifact that will be created

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

    The number of seconds to wait for completing the request. Default is 300.

Returns:

  • (Hash)

    The result hash with DeploymentGroup data



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 82

def self.create_backup_from_file!(client, deployment_group, file_path, artifact_name, timeout = OneviewSDK::Rest::READ_TIMEOUT)
  ensure_resource!(deployment_group)
  ensure_file_path_extension!(file_path)

  file_name = artifact_name.dup
  if file_name && !file_name.empty?
    file_name += File.extname(file_path)
  else
    file_name = File.basename(file_path)
  end

  params = { 'name' => file_name, 'deploymentGrpUri' => deployment_group['uri'] }
  client.upload_file(file_path, BACKUPS_ARCHIVE_URI, params, timeout)
end

.create_from_file(client, file_path, artifact_name, timeout = OneviewSDK::Rest::READ_TIMEOUT) ⇒ OneviewSDK::ImageStreamer::API300::ArtifactBundle

Creates an artifact bundle resource from the file that is uploaded from admin’s local drive

Parameters:

  • client (OneviewSDK::ImageStreamer::Client)

    The client object for the Image Streamer appliance

  • file_path (String)

    The file path with file extension

  • artifact_name (String)

    The name for the artifact that will be created

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

    The number of seconds to wait for completing the request. Default is 300.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 43

def self.create_from_file(client, file_path, artifact_name, timeout = OneviewSDK::Rest::READ_TIMEOUT)
  ensure_file_path_extension!(file_path)

  file_name = artifact_name.dup
  if file_name && !file_name.empty?
    file_name += File.extname(file_path)
  else
    file_name = File.basename(file_path)
  end

  params = { 'name' => file_name }
  body = client.upload_file(file_path, BASE_URI, params, timeout)
  ArtifactBundle.new(client, body)
end

.download_backup(client, local_drive_path, bundle_backup) ⇒ Boolean

Download the backup bundle

Parameters:

  • client (OneviewSDK::ImageStreamer::Client)

    The client object for the Image Streamer appliance

  • local_drive_path (String)

    The path where file will be saved

  • bundle_backup (ArtifactBundle)

    The backup ArtifactBundle with ‘downloadURI’

Returns:

  • (Boolean)

    true if backup was downloaded

Raises:



102
103
104
105
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 102

def self.download_backup(client, local_drive_path, bundle_backup)
  raise IncompleteResource, "Missing required attribute 'downloadURI'" unless bundle_backup['downloadURI']
  client.download_file(bundle_backup['downloadURI'], local_drive_path)
end

.ensure_file_path_extension!(file_path) ⇒ Object

Fail unless file extension of file_path is in ACCEPTED_FORMATS array

Raises:



198
199
200
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 198

def self.ensure_file_path_extension!(file_path)
  raise InvalidFormat, "File extension should be #{ACCEPTED_FORMATS}" unless ACCEPTED_FORMATS.include?(File.extname(file_path))
end

.ensure_resource!(resource) ⇒ Object

Fail unless resource can be retrieved

Raises:



193
194
195
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 193

def self.ensure_resource!(resource)
  raise IncompleteResource, "The resource #{resource.class} can not be retrieved. Ensure it can be retrieved." unless resource.retrieve!
end

.extract_backup(client, deployment_group, bundle_backup) ⇒ Boolean

Extracts the existing backup bundle on the appliance and creates all the artifacts.

If there are any artifacts existing, they will be removed before the extract operation.

Parameters:

  • deployment_group (DeploymentGroup)

    The DeploymentGroup with ‘name’ or ‘uri’

  • bundle_backup (ArtifactBundle)

    The backup ArtifactBundle with ‘uri’

Returns:

  • (Boolean)

    true if backup bundle was extracted

Raises:



113
114
115
116
117
118
119
120
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 113

def self.extract_backup(client, deployment_group, bundle_backup)
  ensure_resource!(deployment_group)
  raise IncompleteResource, "Missing required attribute 'uri' of backup bundle" unless bundle_backup['uri']
  id = bundle_backup['uri'].split('/').last
  response = client.rest_put("#{BACKUPS_URI}/#{id}", 'body' => { 'deploymentGroupURI' => deployment_group['uri'] })
  client.response_handler(response)
  true
end

.get_backups(client) ⇒ Array<ArtifactBundle>

Gets the backup bundles created

Parameters:

Returns:



61
62
63
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 61

def self.get_backups(client)
  find_by(client, {}, BACKUPS_URI)
end

Instance Method Details

#add_build_plan(resource, read_only = true) ⇒ Object

Add a Build Plan to this ArtifactBundle

Parameters:

  • resource (OneviewSDK::ImageStreamer::API300::BuildPlan)

    The BuildPlan resource with uri

  • read_only (TrueClass, FalseClass) (defaults to: true)

    Indicates whether the BuildPlan will be readonly in artifact bundle package

Raises:

  • (RuntimeError)

    if the BuildPlan uri is not set or it is not valid



164
165
166
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 164

def add_build_plan(resource, read_only = true)
  add_resource(resource, 'buildPlans', read_only)
end

#add_deployment_plan(resource, read_only = true) ⇒ Object

Add a Deployment Plan to this ArtifactBundle

Parameters:

  • resource (OneviewSDK::ImageStreamer::API300::DeploymentPlans)

    The DeploymentPlans resource with uri

  • read_only (TrueClass, FalseClass) (defaults to: true)

    Indicates whether the DeploymentPlans will be readonly in artifact bundle package

Raises:

  • (RuntimeError)

    if the DeploymentPlans uri is not set or it is not valid



180
181
182
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 180

def add_deployment_plan(resource, read_only = true)
  add_resource(resource, 'deploymentPlans', read_only)
end

#add_golden_image(resource, read_only = true) ⇒ Object

Add a Golden Image to this ArtifactBundle

Parameters:

  • resource (OneviewSDK::ImageStreamer::API300::GoldenImage)

    The GoldenImage resource with uri

  • read_only (TrueClass, FalseClass) (defaults to: true)

    Indicates whether the GoldenImage will be readonly in artifact bundle package

Raises:

  • (RuntimeError)

    if the GoldenImage uri is not set or it is not valid



188
189
190
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 188

def add_golden_image(resource, read_only = true)
  add_resource(resource, 'goldenImages', read_only)
end

#add_plan_script(resource, read_only = true) ⇒ Object

Add a Plan Script to this ArtifactBundle

Parameters:

  • resource (OneviewSDK::ImageStreamer::API300::PlanScript)

    The PlanScripts resource with uri

  • read_only (TrueClass, FalseClass) (defaults to: true)

    Indicates whether the PlanScripts will be readonly in artifact bundle package

Raises:

  • (RuntimeError)

    if the PlanScripts uri is not set or it is not valid



172
173
174
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 172

def add_plan_script(resource, read_only = true)
  add_resource(resource, 'planScripts', read_only)
end

#download(local_drive_path) ⇒ Boolean

Downloads the content of the selected artifact bundle to the admin’s local drive.

Parameters:

  • local_drive_path (String)

    Path to save file downloaded

Returns:

  • (Boolean)

    true if the file was downloaded

Raises:



155
156
157
158
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 155

def download(local_drive_path)
  raise IncompleteResource, "Missing required attribute 'downloadURI'" unless @data['downloadURI']
  client.download_file(@data['downloadURI'], local_drive_path)
end

#extract(force = true) ⇒ Boolean

Extracts the artifact bundle and creates the artifacts on the appliance

Parameters:

  • force (Boolean) (defaults to: true)

    Forces the extract operation even when there are any conflicts

Returns:

  • (Boolean)

    true if artifact bundle was extracted

Raises:



144
145
146
147
148
149
150
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 144

def extract(force = true)
  ensure_uri
  options = { 'Content-Type' => 'text/plain' }
  response = @client.rest_put(@data['uri'] + "?extract=true&forceImport=#{force}", options)
  @client.response_handler(response)
  true
end

#updateObject

Method is not available

Raises:



124
125
126
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 124

def update(*)
  unavailable_method
end

#update_name(new_name) ⇒ Boolean

Update the name of Artifact Bundle

Parameters:

  • new_name (String)

    Name to update the Artifact Bundle

Returns:

  • (Boolean)

    true if name was updated

Raises:



132
133
134
135
136
137
138
# File 'lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb', line 132

def update_name(new_name)
  ensure_uri
  response = @client.rest_put(@data['uri'], 'body' => { 'name' => new_name, 'type' => 'ArtifactsBundle' })
  @client.response_handler(response)
  @data['name'] = new_name
  true
end