Parent

Included Modules

Class/Module Index [+]

Quicksearch

Fog::HP::BlockStorage::Real

Public Class Methods

new(options={}) click to toggle source
# 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

Public Instance Methods

create_snapshot(name, description, volume_id, options={}) click to toggle source

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

# 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={}) click to toggle source

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

# 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) click to toggle source

Delete an existing block storage snapshot

Parameters

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

# 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) click to toggle source

Delete an existing block storage volume

Parameters

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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_volumes() click to toggle source

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

# 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_snapshots() click to toggle source

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

# 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_volumes() click to toggle source

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

# 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
reload() click to toggle source
# File lib/fog/hp/block_storage.rb, line 138
def reload
  @connection.reset
end
request(params, parse_json = true, &block) click to toggle source
# 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'] =~ %{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.