Skip to content
Browse files

[openstack|volume] Added volume model

  • Loading branch information...
1 parent 99de516 commit e4cf9e3db905f65f506c7ff1cb9c943cce69eeec @pmdeazeta pmdeazeta committed with Keoven May 14, 2012
View
46 lib/fog/openstack/models/volume/volume.rb
@@ -0,0 +1,46 @@
+require 'fog/core/model'
+
+module Fog
+ module Volume
+ class OpenStack
+
+ class Volume < Fog::Model
+
+ identity :id
+
+ attribute :display_name, :aliases => 'displayName'
+ attribute :display_description, :aliases => 'displayDescription'
+ attribute :status
+ attribute :size
+ attribute :type, :aliases => 'volumeType'
+ attribute :snapshot_id, :aliases => 'snapshotId'
+ attribute :availability_zone, :aliases => 'availabilityZone'
+ attribute :created_at, :aliases => 'createdAt'
+ attribute :attachments
+
+
+ def initialize(attributes)
+ @connection = attributes[:connection]
+ super
+ end
+
+ def save
+ requires :display_name, :size
+ data = connection.create_volume(display_name, display_description, size, attributes)
+ merge_attributes(data.body['volume'])
+ true
+ end
+
+ def destroy
+ requires :id
+ connection.delete_volume(id)
+ true
+ end
+
+ end
+
+ end
+ end
+
+end
+
View
27 lib/fog/openstack/models/volume/volumes.rb
@@ -0,0 +1,27 @@
+require 'fog/core/collection'
+require 'fog/openstack/models/volume/volume'
+
+module Fog
+ module Volume
+ class OpenStack
+
+ class Volumes < Fog::Collection
+ model Fog::Volume::OpenStack::Volume
+
+ def all(detailed=true)
+ load(connection.list_volumes(detailed).body['volumes'])
+ end
+
+ def find_by_id(volume_id)
+ if volume = connection.get_volume_details(volume_id).body['volume']
+ new(volume)
+ end
+ rescue Fog::Volume::OpenStack::NotFound
+ nil
+ end
+ end
+
+ end
+ end
+end
+
View
6 lib/fog/openstack/volume.rb
@@ -11,10 +11,10 @@ class OpenStack < Fog::Service
:openstack_api_key, :openstack_username,
:current_user, :current_tenant
- #model_path 'fog/openstack/models/volume'
+ model_path 'fog/openstack/models/volume'
- #model :volume
- #collection :volumes
+ model :volume
+ collection :volumes
request_path 'fog/openstack/requests/volume'

0 comments on commit e4cf9e3

Please sign in to comment.
Something went wrong with that request. Please try again.