mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|volume] Added volume model
This commit is contained in:
parent
99de5161c9
commit
e4cf9e3db9
3 changed files with 76 additions and 3 deletions
46
lib/fog/openstack/models/volume/volume.rb
Normal file
46
lib/fog/openstack/models/volume/volume.rb
Normal file
|
@ -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
|
||||
|
27
lib/fog/openstack/models/volume/volumes.rb
Normal file
27
lib/fog/openstack/models/volume/volumes.rb
Normal file
|
@ -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
|
||||
|
|
@ -11,10 +11,10 @@ module Fog
|
|||
: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'
|
||||
|
|
Loading…
Reference in a new issue