diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 66f4b7267..8b00a822b 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -42,15 +42,15 @@ module Fog end end - service(:block_storage, 'rackspace/block_storage', 'BlockStorage') - service(:cdn, 'rackspace/cdn', 'CDN') - service(:compute, 'rackspace/compute', 'Compute') - service(:compute_v2, 'rackspace/compute_v2', 'Compute v2') - service(:dns, 'rackspace/dns', 'DNS') - service(:storage, 'rackspace/storage', 'Storage') - service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers') - service(:identity, 'rackspace/identity', 'Identity') - service(:databases, 'rackspace/databases', 'Databases') + service(:block_storage, 'rackspace/block_storage', 'BlockStorage') + service(:cdn, 'rackspace/cdn', 'CDN') + service(:compute, 'rackspace/compute', 'Compute') + service(:compute_v2, 'rackspace/compute_v2', 'Compute v2') + service(:dns, 'rackspace/dns', 'DNS') + service(:storage, 'rackspace/storage', 'Storage') + service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers') + service(:identity, 'rackspace/identity', 'Identity') + service(:databases, 'rackspace/databases', 'Databases') def self.authenticate(options, connection_options = {}) rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com" diff --git a/lib/fog/rackspace/block_storage.rb b/lib/fog/rackspace/block_storage.rb index e371f6f8e..1e4e404e3 100644 --- a/lib/fog/rackspace/block_storage.rb +++ b/lib/fog/rackspace/block_storage.rb @@ -19,17 +19,28 @@ module Fog model_path 'fog/rackspace/models/block_storage' model :volume collection :volumes + model :volume_type collection :volume_types + model :snapshot + collection :snapshots + + model :snapshot + collection :snapshots request_path 'fog/rackspace/requests/block_storage' request :create_volume request :delete_volume request :get_volume request :list_volumes + request :get_volume_type request :list_volume_types + request :create_snapshot + request :delete_snapshot + request :get_snapshot + request :list_snapshots class Mock def request(params) diff --git a/lib/fog/rackspace/models/block_storage/snapshot.rb b/lib/fog/rackspace/models/block_storage/snapshot.rb new file mode 100644 index 000000000..5f0e653d5 --- /dev/null +++ b/lib/fog/rackspace/models/block_storage/snapshot.rb @@ -0,0 +1,46 @@ +require 'fog/core/model' + +module Fog + module Rackspace + class BlockStorage + class Snapshot < Fog::Model + AVAILABLE = 'available' + CREATING = 'creating' + DELETING = 'deleting' + ERROR = 'error' + ERROR_DELETING = 'error_deleting' + + identity :id + + attribute :created_at, :aliases => 'createdAt' + attribute :state, :aliases => 'status' + attribute :display_name + attribute :display_description + attribute :size + attribute :volume_id + attribute :availability_zone + + def ready? + state == AVAILABLE + end + + def save(force = false) + requires :volume_id + data = connection.create_snapshot(volume_id, { + :display_name => display_name, + :display_description => display_description, + :force => force + }) + merge_attributes(data.body['snapshot']) + true + end + + def destroy + requires :identity + connection.delete_snapshot(identity) + true + end + end + end + end +end diff --git a/lib/fog/rackspace/models/block_storage/snapshots.rb b/lib/fog/rackspace/models/block_storage/snapshots.rb new file mode 100644 index 000000000..b25d99bc3 --- /dev/null +++ b/lib/fog/rackspace/models/block_storage/snapshots.rb @@ -0,0 +1,25 @@ +require 'fog/core/collection' +require 'fog/rackspace/models/block_storage/snapshot' + +module Fog + module Rackspace + class BlockStorage + class Snapshots < Fog::Collection + + model Fog::Rackspace::BlockStorage::Snapshot + + def all + data = connection.list_snapshots.body['snapshots'] + load(data) + end + + def get(snapshot_id) + data = connection.get_snapshot(snapshot_id).body['snapshot'] + new(data) + rescue Fog::Rackspace::BlockStorage::NotFound + nil + end + end + end + end +end diff --git a/lib/fog/rackspace/requests/block_storage/create_snapshot.rb b/lib/fog/rackspace/requests/block_storage/create_snapshot.rb new file mode 100644 index 000000000..5bdc9a773 --- /dev/null +++ b/lib/fog/rackspace/requests/block_storage/create_snapshot.rb @@ -0,0 +1,26 @@ +module Fog + module Rackspace + class BlockStorage + class Real + 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 + end + end + end +end diff --git a/lib/fog/rackspace/requests/block_storage/delete_snapshot.rb b/lib/fog/rackspace/requests/block_storage/delete_snapshot.rb new file mode 100644 index 000000000..dd9cf52b6 --- /dev/null +++ b/lib/fog/rackspace/requests/block_storage/delete_snapshot.rb @@ -0,0 +1,15 @@ +module Fog + module Rackspace + class BlockStorage + class Real + def delete_snapshot(snapshot_id) + request( + :expects => [202], + :method => 'DELETE', + :path => "snapshots/#{snapshot_id}" + ) + end + end + end + end +end diff --git a/lib/fog/rackspace/requests/block_storage/get_snapshot.rb b/lib/fog/rackspace/requests/block_storage/get_snapshot.rb new file mode 100644 index 000000000..4cc90c3b2 --- /dev/null +++ b/lib/fog/rackspace/requests/block_storage/get_snapshot.rb @@ -0,0 +1,15 @@ +module Fog + module Rackspace + class BlockStorage + class Real + def get_snapshot(snapshot_id) + request( + :expects => [200], + :method => 'GET', + :path => "snapshots/#{snapshot_id}" + ) + end + end + end + end +end diff --git a/lib/fog/rackspace/requests/block_storage/list_snapshots.rb b/lib/fog/rackspace/requests/block_storage/list_snapshots.rb new file mode 100644 index 000000000..e189d2814 --- /dev/null +++ b/lib/fog/rackspace/requests/block_storage/list_snapshots.rb @@ -0,0 +1,15 @@ +module Fog + module Rackspace + class BlockStorage + class Real + def list_snapshots + request( + :expects => [200], + :method => 'GET', + :path => 'snapshots' + ) + end + end + end + end +end