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

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!, #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) ⇒ 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.


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

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

Instance Method Details

#createResource

Note:

Calls refresh method to set additional data

Create the resource on OneView using the current data

Returns:

Raises:


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

def create
  ensure_client
  response = @client.rest_post(self.class::BASE_URI, { 'Accept-Language' => 'en_US', 'body' => @data }, @api_version)
  body = @client.response_handler(response)
  set_all(body)
end

#deleteTrueClass

Deletes the volume template from OneView

Returns:

  • (TrueClass)

    if the volume template was deleted successfully


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

def delete
  ensure_client && ensure_uri
  response = @client.rest_delete(@data['uri'], { 'Accept-Language' => 'en_US' }, @api_version)
  @client.response_handler(response)
  true
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


94
95
96
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 94

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)

70
71
72
73
74
75
76
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 70

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


87
88
89
90
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 87

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


80
81
82
83
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 80

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:


57
58
59
60
61
62
63
# File 'lib/oneview-sdk/resource/api200/volume_template.rb', line 57

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