Class: Fog::HP::BlockStorage::Real

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/fog/hp/block_storage.rb,
lib/fog/hp/requests/block_storage/list_volumes.rb,
lib/fog/hp/requests/block_storage/create_volume.rb,
lib/fog/hp/requests/block_storage/delete_volume.rb,
lib/fog/hp/requests/block_storage/list_snapshots.rb,
lib/fog/hp/requests/block_storage/create_snapshot.rb,
lib/fog/hp/requests/block_storage/delete_snapshot.rb,
lib/fog/hp/requests/block_storage/get_volume_details.rb,
lib/fog/hp/requests/block_storage/get_snapshot_details.rb,
lib/fog/hp/requests/block_storage/list_bootable_volumes.rb,
lib/fog/hp/requests/block_storage/get_bootable_volume_details.rb

Instance Method Summary collapse

Methods included from Utils

#compute

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fog/hp/block_storage.rb', line 93

def initialize(options={})
  # deprecate hp_account_id
  if options[:hp_account_id]
    Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.")
    options[:hp_access_key] = options.delete(:hp_account_id)
  end
  @hp_access_key = options[:hp_access_key]
  unless @hp_access_key
    raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.")
  end
  @hp_secret_key = options[:hp_secret_key]
  @hp_auth_uri   = options[:hp_auth_uri]
  @connection_options = options[:connection_options] || {}
  ### Set an option to use the style of authentication desired; :v1 or :v2 (default)
  auth_version = options[:hp_auth_version] || :v2
  ### Pass the service name for object storage to the authentication call
  options[:hp_service_type] = "Block Storage"
  @hp_tenant_id = options[:hp_tenant_id]
  @hp_avl_zone  = options[:hp_avl_zone]

  ### Make the authentication call
  if (auth_version == :v2)
    # Call the control services authentication
    credentials = Fog::HP.authenticate_v2(options, @connection_options)
    # the CS service catalog returns the block storage endpoint
    @hp_block_uri = credentials[:endpoint_url]
  else
    # Call the legacy v1.0/v1.1 authentication
    credentials = Fog::HP.authenticate_v1(options, @connection_options)
    # the user sends in the block storage endpoint
    @hp_block_uri = options[:hp_auth_uri]
  end

  @auth_token = credentials[:auth_token]
  @persistent = options[:persistent] || false

  uri = URI.parse(@hp_block_uri)
  @host   = uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme

  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#create_snapshot(name, description, volume_id, options = {}) ⇒ Object

Create a new block storage snapshot

Parameters

  • name<~String> - Name of the snapshot

  • description<~String> - Description of the snapshot

  • volume_id<~Integer> - Id of the volume to create snapshot of

  • options<~Hash>:

    • ‘force’<~Boolean> - Not implemented yet. True or False, to allow online snapshots (i.e. when volume is attached)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • snapshot<~Hash>:

        • ‘id’<~Integer>: - Id for the snapshot

        • ‘displayName’<~String>: - Name of the snapshot

        • ‘displayDescription’<~String>: - Description of the snapshot

        • ‘size’<~Integer>: - Size in GB for the snapshot

        • ‘status’<~String>: - Status of the snapshot i.e. “creating”

        • ‘volumeId’<~Integer>: - Id of the volume from which the snapshot was created

        • ‘createdAt’<~String>: - Timestamp in UTC when snapshot was created



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/hp/requests/block_storage/create_snapshot.rb', line 26

def create_snapshot(name, description, volume_id, options={})
  data = {
    'snapshot' => {
      'display_name'        => name,
      'display_description' => description,
      'volume_id'           => volume_id
    }
  }

  l_options = ['force']
  l_options.select{|o| options[o]}.each do |key|
    data['snapshot'][key] = options[key]
  end

  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 200,
    :method   => 'POST',
    :path     => "os-snapshots"
  )
end

#create_volume(name, description, size, options = {}) ⇒ Object

Create a new block storage volume

Parameters

  • name<~String> - Name of the volume

  • description<~String> - Description of the volume

  • size<~Integer> - Size of the volume (in GBs)

  • options<~Hash>:

    • ‘snapshot_id’<~String> - Id of the volume snapshot to create the volume from. The request is invalid if both the snapshot_id and the imageRef parameters are specified and are not null.

    • ‘imageRef’<~String> - Id of the image to create the volume from. This creates a bootable volume. The request is invalid if both the snapshot_id and the imageRef parameters are specified and are not null.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • volume<~Hash>:

        • ‘id’<~Integer> - Id for the volume

        • ‘displayName’<~String> - Name of the volume

        • ‘displayDescription’<~String> - Description of the volume

        • ‘size’<~Integer> - Size in GB for the volume

        • ‘status’<~String> - Status of the volume i.e. “creating”

        • ‘volumeType’<~String> - Type of the volume

        • ‘snapshotId’<~String> - Id of the snapshot, the volume was created from.

        • ‘imageRef’<~String> - Id of the image, the volume was created from. A not null value means it is a bootable volume.

        • ‘createdAt’<~String> - Timestamp in UTC when volume was created

        • ‘availabilityZone’<~String> - Availability zone i.e. “nova”

        • attachments<~Array>: Array of hashes of attachments

        • metadata<~Hash>: Hash of metadata for the volume



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/hp/requests/block_storage/create_volume.rb', line 32

def create_volume(name, description, size, options={})
  data = {
    'volume' => {
      'display_name'        => name,
      'display_description' => description,
      'size'                => size
    }
  }

  l_options = ['snapshot_id', 'imageRef', 'metadata']
  l_options.select{|o| options[o]}.each do |key|
    data['volume'][key] = options[key]
  end

  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 200,
    :method   => 'POST',
    :path     => "os-volumes"
  )
end

#delete_snapshot(snapshot_id) ⇒ Object

Delete an existing block storage snapshot

Parameters

  • snapshot_id<~Integer> - Id of the snapshot to delete



11
12
13
14
15
16
17
18
# File 'lib/fog/hp/requests/block_storage/delete_snapshot.rb', line 11

def delete_snapshot(snapshot_id)
  response = request(
    :expects  => 202,
    :method   => 'DELETE',
    :path     => "os-snapshots/#{snapshot_id}"
  )
  response
end

#delete_volume(volume_id) ⇒ Object

Delete an existing block storage volume

Parameters

  • volume_id<~Integer> - Id of the volume to delete



11
12
13
14
15
16
17
18
# File 'lib/fog/hp/requests/block_storage/delete_volume.rb', line 11

def delete_volume(volume_id)
  response = request(
    :expects  => 202,
    :method   => 'DELETE',
    :path     => "os-volumes/#{volume_id}"
  )
  response
end

#get_bootable_volume_details(volume_id) ⇒ Object

Get details for existing block storage bootable volume

Parameters

  • volume_id<~Integer> - Id of the volume to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • volume<~Hash>:

        • ‘id’<~Integer> - Id for the volume

        • ‘displayName’<~String> - Name of the volume

        • ‘displayDescription’<~String> - Description of the volume

        • ‘size’<~Integer> - Size in GB for the volume

        • ‘status’<~String> - Status of the volume i.e. “available”

        • ‘volumeType’<~String> - Type of the volume

        • ‘snapshotId’<~String> - Id of the volume snapshot

        • ‘sourceImageRef’<~String> - Id of the volume snapshot

        • ‘createdAt’<~String> - Timestamp in UTC when volume was created

        • ‘availabilityZone’<~String> - Availability zone i.e. “nova”

        • attachments<~Array> Array of hashes of attachments

        • metadata<~Hash> Hash of metadata for the volume



28
29
30
31
32
33
34
35
# File 'lib/fog/hp/requests/block_storage/get_bootable_volume_details.rb', line 28

def get_bootable_volume_details(volume_id)
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "hp-bootable-volumes/#{volume_id}"
  )
  response
end

#get_snapshot_details(snapshot_id) ⇒ Object

Get details for existing block storage snapshot

Parameters

  • snapshot_id<~Integer> - Id of the snapshot to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • snapshot<~Hash>:

        • ‘id’<~Integer>: - Id for the snapshot

        • ‘displayName’<~String>: - Name of the snapshot

        • ‘displayDescription’<~String>: - Description of the snapshot

        • ‘size’<~Integer>: - Size in GB for the snapshot

        • ‘status’<~String>: - Status of the snapshot i.e. “available”

        • ‘volumeId’<~Integer>: - Id of the volume from which the snapshot was created

        • ‘createdAt’<~String>: - Timestamp in UTC when volume was created



23
24
25
26
27
28
29
30
# File 'lib/fog/hp/requests/block_storage/get_snapshot_details.rb', line 23

def get_snapshot_details(snapshot_id)
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "os-snapshots/#{snapshot_id}"
  )
  response
end

#get_volume_details(volume_id) ⇒ Object

Get details for existing block storage volume

Parameters

  • volume_id<~Integer> - Id of the volume to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • volume<~Hash>:

        • ‘id’<~Integer>: - Id for the volume

        • ‘displayName’<~String>: - Name of the volume

        • ‘displayDescription’<~String>: - Description of the volume

        • ‘size’<~Integer>: - Size in GB for the volume

        • ‘status’<~String>: - Status of the volume i.e. “available”

        • ‘volumeType’<~String>: - Type of the volume

        • ‘snapshotId’<~String>: - Id of the volume snapshot

        • ‘createdAt’<~String>: - Timestamp in UTC when volume was created

        • ‘availabilityZone’<~String>: - Availability zone i.e. “nova”

        • attachments<~Array>: Array of hashes of attachments

        • metadata<~Hash>: Hash of metadata for the volume



27
28
29
30
31
32
33
34
# File 'lib/fog/hp/requests/block_storage/get_volume_details.rb', line 27

def get_volume_details(volume_id)
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "os-volumes/#{volume_id}"
  )
  response
end

#list_bootable_volumesObject

List existing block storage bootbale volumes

Parameters

None

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • volumes<~Hash>:

        • ‘id’<~Integer>: - Id for the volume

        • ‘displayName’<~String>: - Name of the volume

        • ‘displayDescription’<~String>: - Description of the volume

        • ‘size’<~Integer>: - Size in GB for the volume

        • ‘status’<~String>: - Status of the volume i.e. “available”

        • ‘volumeType’<~String>: - Type of the volume

        • ‘snapshotId’<~String>: - Id of the source snapshot used to create volume

        • ‘sourceImageRef’<~String>: - Id of the source image used to create volume

        • ‘createdAt’<~String>: - Timestamp in UTC when volume was created

        • ‘availabilityZone’<~String>: - Availability zone i.e. “nova”

        • attachments<~Array>: Array of hashes of attachments

        • metadata<~Hash>: Hash of metadata for the volume



27
28
29
30
31
32
33
34
# File 'lib/fog/hp/requests/block_storage/list_bootable_volumes.rb', line 27

def list_bootable_volumes
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "hp-bootable-volumes"
  )
  response
end

#list_snapshotsObject

List existing block storage snapshots

Parameters

None

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • snapshots<~Hash>:

        • ‘id’<~Integer>: - Id for the snapshot

        • ‘displayName’<~String>: - Name of the snapshot

        • ‘displayDescription’<~String>: - Description of the snapshot

        • ‘size’<~Integer>: - Size in GB for the snapshot

        • ‘status’<~String>: - Status of the snapshot i.e. “available”

        • ‘volumeId’<~Integer>: - Id of the volume from which the snapshot was created

        • ‘createdAt’<~String>: - Timestamp in UTC when volume was created



22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/block_storage/list_snapshots.rb', line 22

def list_snapshots
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'os-snapshots'
  )
  response
end

#list_volumesObject

List existing block storage volumes

Parameters

None

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • volumes<~Hash>:

        • ‘id’<~Integer>: - Id for the volume

        • ‘displayName’<~String>: - Name of the volume

        • ‘displayDescription’<~String>: - Description of the volume

        • ‘size’<~Integer>: - Size in GB for the volume

        • ‘status’<~String>: - Status of the volume i.e. “available”

        • ‘volumeType’<~String>: - Type of the volume

        • ‘snapshotId’<~String>: - Id of the volume snapshot

        • ‘createdAt’<~String>: - Timestamp in UTC when volume was created

        • ‘availabilityZone’<~String>: - Availability zone i.e. “nova”

        • attachments<~Array>: Array of hashes of attachments

        • metadata<~Hash>: Hash of metadata for the volume



26
27
28
29
30
31
32
33
# File 'lib/fog/hp/requests/block_storage/list_volumes.rb', line 26

def list_volumes
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'os-volumes'
  )
  response
end

#reloadObject



138
139
140
# File 'lib/fog/hp/block_storage.rb', line 138

def reload
  @connection.reset
end

#request(params, parse_json = true, &block) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fog/hp/block_storage.rb', line 142

def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge!({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept'       => 'application/json',
        'X-Auth-Token' => @auth_token
      }.merge!(params[:headers] || {}),
      :host     => @host,
      :path     => "#{@path}/#{params[:path]}",
    }), &block)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::HP::BlockStorage::NotFound.slurp(error)
    else
      error
    end
  end
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end