Class: Fog::Rackspace::BlockStorage::Real

Inherits:
Service
  • Object
show all
Defined in:
lib/fog/rackspace/block_storage.rb,
lib/fog/rackspace/requests/block_storage/get_volume.rb,
lib/fog/rackspace/requests/block_storage/get_snapshot.rb,
lib/fog/rackspace/requests/block_storage/list_volumes.rb,
lib/fog/rackspace/requests/block_storage/create_volume.rb,
lib/fog/rackspace/requests/block_storage/delete_volume.rb,
lib/fog/rackspace/requests/block_storage/list_snapshots.rb,
lib/fog/rackspace/requests/block_storage/create_snapshot.rb,
lib/fog/rackspace/requests/block_storage/delete_snapshot.rb,
lib/fog/rackspace/requests/block_storage/get_volume_type.rb,
lib/fog/rackspace/requests/block_storage/list_volume_types.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fog/rackspace/block_storage.rb', line 73

def initialize(options = {})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}
  setup_custom_endpoint(options)

  authenticate

  deprecation_warnings(options)

  @persistent = options[:persistent] || false
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Instance Method Details

#authenticateObject



115
116
117
118
119
120
121
122
# File 'lib/fog/rackspace/block_storage.rb', line 115

def authenticate
  options = {
    :rackspace_api_key => @rackspace_api_key,
    :rackspace_username => @rackspace_username,
    :rackspace_auth_url => @rackspace_auth_url
  }
  super(options)
end

#create_snapshot(volume_id, options = {}) ⇒ Excon::Response

Note:

All writes to the volume should be flushed before creating the snapshot, either by un-mounting any file systems on the volume or by detaching the volume.

Create a snapshot from a volume

Parameters:

  • volume_id (String)

    Id of server to create image from

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

Options Hash (options):

  • :display_name (String)

    display name for snapshot

  • :display_description (String)

    display description for snapshot

  • :force (Boolean)

    Set to true to force service to create snapshot

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘snapshot’ [Hash]:

        • ‘volume_id’ [String]: - the volume_id of the snapshot

          • ‘display_description’ [String]: - display description of snapshot

          • ‘status’ [String]: - status of snapshot

          • ‘id’ [String]: - id of snapshot

          • ‘size’ [Fixnum]: - size of the snapshot in GB

          • ‘display_name’ [String]: - display name of snapshot

          • ‘created_at’ [String]: - creation time of snapshot

See Also:



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

def create_snapshot(volume_id, options = {})
  data = {
    'snapshot' => {
      'volume_id' => volume_id
    }
  }

  data['snapshot']['display_name'] = options[:display_name] unless options[:display_name].nil?
  data['snapshot']['display_description'] = options[:display_description] unless options[:display_description].nil?
  data['snapshot']['force'] = options[:force] unless options[:force].nil?

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

#create_volume(size, options = {}) ⇒ Excon::Response

Create volume

Parameters:

  • size (Integer)

    size of volume in GB. Minimum size is 100

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

Options Hash (options):

  • :display_name (String)

    display name for volume

  • :display_description (String)

    display description for volume

  • :volume_type (String)

    type of volume

  • :snapshot_id (String)

    The optional snapshot from which to create a volume.

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘volume’ [Hash]:

        • ‘volume_type’ [String]: - type of volume

        • ‘display_description’ [String]: - volume description

        • ‘metadata’ [Hash]: - volume metadata

        • availability_zone’: - region of the volume

        • ‘status’ [String]: - status of volume

        • ‘id’ [String]: - id of volume

        • ‘attachments’ [Array<Hash]: - array of hashes containing attachment information

        • ‘size’ [Fixnum]: - size of volume in GB (100 GB minimum)

        • ‘snapshot_id’ [String]: - The optional snapshot from which to create a volume.

        • ‘display_name’ [String]: - display name of volume

        • ‘created_at’ [String]: - the volume creation time

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/rackspace/requests/block_storage/create_volume.rb', line 29

def create_volume(size, options = {})
  data = {
    'volume' => {
      'size' => size
    }
  }

  data['volume']['display_name'] = options[:display_name] unless options[:display_name].nil?
  data['volume']['display_description'] = options[:display_description] unless options[:display_description].nil?
  data['volume']['volume_type'] = options[:volume_type] unless options[:volume_type].nil?
  data['volume']['availability_zone'] = options[:availability_zone] unless options[:availability_zone].nil?
  data['volume']['snapshot_id'] = options[:snapshot_id] unless options[:snapshot_id].nil?

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

#delete_snapshot(snapshot_id) ⇒ Excon::Response

Delete snapshot

Parameters:

  • snapshot_id (String)

    Id of snapshot to delete

Returns:

  • (Excon::Response)

    response

See Also:



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

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

#delete_volume(volume_id) ⇒ Excon::Response

Note:

You cannot delete a volume until all of its dependent snaphosts have been deleted.

Delete volume

Parameters:

  • volume_id (String)

    Id of volume to delete

Returns:

  • (Excon::Response)

    response

See Also:



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

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

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



132
133
134
# File 'lib/fog/rackspace/block_storage.rb', line 132

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_block_storage_url)
end

#get_snapshot(snapshot_id) ⇒ Excon::Response

Retrieves snapshot detail

Parameters:

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘snapshot’ [Hash]:

        • ‘volume_id’ [String]: - volume_id of the snapshot

        • ‘display_description’ [String]: - snapshot display description

        • ‘status’ [String]: - snapshot status

        • ‘os-extended-snapshot-attributes:project_id’ [String]: -

        • ‘id’ [String]: - snapshot id

        • ‘size’ [Fixnum]: - size of the snapshot in GB

        • ‘os-extended-snapshot-attributes:progress’ [String]: -

        • ‘display_name’ [String]: - display name of snapshot

        • ‘created_at’ [String]: - creation time of snapshot

See Also:



21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/block_storage/get_snapshot.rb', line 21

def get_snapshot(snapshot_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "snapshots/#{snapshot_id}"
  )
end

#get_volume(volume_id) ⇒ Excon::Response

Retrieves volume detail

Parameters:

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘volume’ [Hash]:

        • ‘volume_type’ [String]: - volume type

        • ‘display_description’ [String]: - volume display description

        • ‘metadata’ [Hash]: - volume metadata

        • ‘availability_zone’ [String]: - region of volume

        • ‘status’ [String]: - status of volume

        • ‘id’ [String]: - id of volume

        • ‘attachments’ [Array<Hash]: - array of hashes containing attachment information

        • ‘size’ [Fixnum]: - size of volume in GB (100 GB minimum)

        • ‘snapshot_id’ [String]: - The optional snapshot from which to create a volume.

        • ‘os-vol-host-attr:host’ [String]: -

        • ‘display_name’ [String]: - display name of volume

        • ‘created_at’ [String]: - the volume creation time

        • ‘os-vol-tenant-attr:tenant_id’ [String]: -

    @see docs.rackspace.com/cbs/api/v1.0/cbs-devguide/content/GET_getVolume__v1__tenant_id__volumes.html



25
26
27
28
29
30
31
# File 'lib/fog/rackspace/requests/block_storage/get_volume.rb', line 25

def get_volume(volume_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "volumes/#{volume_id}"
  )
end

#get_volume_type(volume_type_id) ⇒ Excon::Response

Retrieves volume type detail

Parameters:

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘volume_type’ [Hash]: -

        • ‘name’ [String]: - name of volume type

        • ‘extra_specs’ [Hash]: -

        • ‘id’ [String]: - id of volume type

See Also:



15
16
17
18
19
20
21
# File 'lib/fog/rackspace/requests/block_storage/get_volume_type.rb', line 15

def get_volume_type(volume_type_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "types/#{volume_type_id}"
  )
end

#list_snapshotsExcon::Response

Retrieves list of snapshots

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘snapshots’ [Array]: -

        • ‘volume_id’ [String]: - volume_id of the snapshot

        • ‘display_description’ [String]: - display description of snapshot

        • ‘status’ [String]: - status of snapshot

        • ‘id’ [String]: - id of snapshot

        • ‘size’ [Fixnum]: - size of the snapshot in GB

        • ‘display_name’ [String]: - display name of snapshot

        • ‘created_at’ [String]: - creation time of snapshot

See Also:



18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/block_storage/list_snapshots.rb', line 18

def list_snapshots
  request(
    :expects => [200],
    :method => 'GET',
    :path => 'snapshots'
  )
end

#list_volume_typesExcon::Response

Retrieves list of volume types

Returns:

  • (Excon::Response)

    response

    • body [Hash]:

      • ‘volume_types’ [Array]: -

        • ‘name’ [String]: - name of volume type

        • ‘extra_specs’ [Hash]: -

        • ‘id’ [Fixnum]: - id of volume type

See Also:



14
15
16
17
18
19
20
# File 'lib/fog/rackspace/requests/block_storage/list_volume_types.rb', line 14

def list_volume_types
  request(
    :expects => [200],
    :method => 'GET',
    :path => 'types'
  )
end

#list_volumesExcon::Response

Retrieves list of volumes

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • ‘volumes’ [Array]: -

        • ‘volume_type’ [String]: - volume type

        • ‘display_description’ [String]: - display desciption for volume

        • ‘metadata’ [Hash]: - metadata for volume

        • ‘availability_zone’ [String]: - region for volume

        • ‘status’ [String]: - status of volume

        • ‘id’ [String]: - id of volume

        • ‘attachments’ [Array]: - array of hashes containing attachment information

        • ‘size’ [Fixnum]: - size of volume in GB (100 GB minimum)

        • ‘snapshot_id’ [String]: - optional snapshot from which to create a volume.

        • ‘display_name’ [String]: - display name of bolume

        • ‘created_at’ [String]: - volume creation time

See Also:



22
23
24
25
26
27
28
# File 'lib/fog/rackspace/requests/block_storage/list_volumes.rb', line 22

def list_volumes
  request(
    :expects => [200],
    :method => 'GET',
    :path => 'volumes'
  )
end

#regionObject



128
129
130
# File 'lib/fog/rackspace/block_storage.rb', line 128

def region
  @rackspace_region
end

#request(params) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fog/rackspace/block_storage.rb', line 89

def request(params)
  begin
    response = @connection.request(params.merge!({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'X-Auth-Token' => auth_token
      }.merge!(params[:headers] || {}),
      :host     => endpoint_uri.host,
      :path     => "#{endpoint_uri.path}/#{params[:path]}"
    }))
  rescue Excon::Errors::NotFound => error
    raise NotFound.slurp error
  rescue Excon::Errors::BadRequest => error
    raise BadRequest.slurp error
  rescue Excon::Errors::InternalServerError => error
    raise InternalServerError.slurp error
  rescue Excon::Errors::HTTPStatusError => error
    raise ServiceError.slurp error
  end
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#service_nameObject



124
125
126
# File 'lib/fog/rackspace/block_storage.rb', line 124

def service_name
  :cloudBlockStorage
end