Class: OneviewSDK::API200::VolumeTemplate

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/resource/api200/volume_template.rb

Overview

Volume template resource implementation

Constant Summary collapse

BASE_URI =
'/rest/storage-volume-templates'.freeze
DEFAULT_REQUEST_HEADER =
{ 'Accept-Language' => 'en_US' }.freeze

Constants inherited from Resource

Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create!, #deep_merge!, #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

Constructor Details

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

Create the client object, establishes connection, and set up the logging and api version. Defaults to client.api_version if exists, or OneviewSDK::Client::DEFAULT_API_VERSION. Defaults type to StorageVolumeTemplate when API version is 120 Defaults type to StorageVolumeTemplateV3 when API version is 200

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView 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.



28
29
30
31
32
33
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 28

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

Instance Method Details

#create(header = {}) ⇒ Resource

Note:

Calls refresh method to set additional data

Create the resource on OneView using the current data

Parameters:

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

    The header options for the request (key-value pairs)

Returns:

Raises:



41
42
43
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 41

def create(header = {})
  super(DEFAULT_REQUEST_HEADER.merge(header))
end

#delete(header = {}) ⇒ TrueClass

Deletes the volume template from OneView

Parameters:

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

    The header options for the request (key-value pairs)

Returns:

  • (TrueClass)

    if the volume template was deleted successfully



48
49
50
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 48

def delete(header = {})
  super(DEFAULT_REQUEST_HEADER.merge(header))
end

#get_connectable_volume_templates(attributes = {}) ⇒ Object

Gets the connectable volume templates by its attributes

Parameters:

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

    Hash containing the attributes name and value



91
92
93
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 91

def get_connectable_volume_templates(attributes = {})
  OneviewSDK::Resource.find_by(@client, attributes, BASE_URI + '/connectable-volume-templates')
end

#set_provisioning(shareable, provisionType, capacity, storage_pool) ⇒ Object

Sets the storage pool

Parameters:

  • shareable (Boolean)
  • provisionType (String)

    ‘Thin’ or ‘Full’

  • capacity (String)

    (in bytes)

  • storage_pool (OneviewSDK::StoragePool)


67
68
69
70
71
72
73
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 67

def set_provisioning(shareable, provisionType, capacity, storage_pool)
  @data['provisioning']['shareable'] = shareable
  @data['provisioning']['provisionType'] = provisionType
  @data['provisioning']['capacity'] = capacity
  storage_pool.retrieve! unless storage_pool['uri']
  @data['provisioning']['storagePoolUri'] = storage_pool['uri']
end

#set_snapshot_pool(storage_pool) ⇒ Object

Sets the snapshot pool

Parameters:

  • storage_pool (OneviewSDK::StoragePool)

    Storage Pool to generate the template



84
85
86
87
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 84

def set_snapshot_pool(storage_pool)
  storage_pool.retrieve! unless storage_pool['uri']
  @data['snapshotPoolUri'] = storage_pool['uri']
end

#set_storage_system(storage_system) ⇒ Object

Sets the storage system

Parameters:

  • storage_system (OneviewSDK::StorageSystem)

    Storage System to be used to create the template



77
78
79
80
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 77

def set_storage_system(storage_system)
  storage_system.retrieve! unless storage_system['uri']
  @data['storageSystemUri'] = storage_system['uri']
end

#update(attributes = {}) ⇒ Resource

Updates the volume template from OneView

Returns:



54
55
56
57
58
59
60
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 54

def update(attributes = {})
  set_all(attributes)
  ensure_client && ensure_uri
  response = @client.rest_put(@data['uri'], { 'Accept-Language' => 'en_US', 'body' => @data }, @api_version)
  @client.response_handler(response)
  self
end