1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/ibm/models/storage/volume.rb

99 lines
2.7 KiB
Ruby
Raw Normal View History

2012-01-10 17:20:56 -05:00
require 'fog/core/model'
module Fog
module Storage
class IBM
class Volume < Fog::Model
2011-12-10 01:50:45 -05:00
STATES = {
0 => 'New',
1 => 'Creating',
2 => 'Deleting',
3 => 'Deleted',
4 => 'Detached',
5 => 'Attached',
6 => 'Failed',
7 => 'Deletion pending',
8 => 'Being cloned',
9 => 'Cloning',
10 => 'Attaching',
11 => 'Detaching',
12 => 'Copying',
13 => 'Importing',
14 => 'Transfer retrying',
}
2011-12-10 01:50:45 -05:00
2012-01-10 17:20:56 -05:00
identity :id
2011-12-10 01:50:45 -05:00
attribute :instance_id, :aliases => "instanceId"
attribute :io_price, :aliases => "ioPrice"
2012-01-10 17:20:56 -05:00
attribute :name
attribute :state
2011-12-10 01:50:45 -05:00
attribute :size
attribute :offering_id, :aliases => "offeringId"
attribute :owner
attribute :created_at, :aliases => "createdTime"
attribute :location_id, :aliases => "location"
attribute :product_codes, :aliases => "productCodes"
attribute :format
attribute :storage_area, :aliases => 'storageArea'
attribute :platform_version, :aliases => 'platformVersion'
attribute :clone_status, :aliases => 'cloneStatus'
2012-01-10 17:20:56 -05:00
2011-12-10 01:50:45 -05:00
def attached?
state == "Attached"
2011-12-10 01:50:45 -05:00
end
2012-01-10 17:20:56 -05:00
2011-12-10 01:50:45 -05:00
def attach(instance_id)
requires :id
connection.attach_volume(instance_id, id).body['success']
end
def detach(instance_id)
requires :id
connection.detach_volume(instance_id, id).body['success']
end
def created_at
Time.at(attributes[:created_at].to_f / 1000)
2012-01-10 17:20:56 -05:00
end
def destroy
requires :id
connection.delete_volume(id)
2011-12-10 01:50:45 -05:00
true
end
def instance
2012-02-29 00:13:34 -05:00
return nil if instance_id.nil? || instance_id == "0" || instance_id == ""
2011-12-10 01:50:45 -05:00
Fog::Compute[:ibm].servers.get(instance_id)
end
def location
requires :location_id
Fog::Compute[:ibm].locations.get(location_id)
end
# Are we ready to be attached to an instance?
def ready?
# TODO: Not sure if this is the only state we should be matching.
state == "Detached"
2011-12-10 01:50:45 -05:00
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
2011-12-10 01:50:45 -05:00
requires :name, :offering_id, :format, :location_id, :size
data = connection.create_volume(name, offering_id, format, location_id, size)
merge_attributes(data.body)
true
end
def state
STATES[attributes[:state]]
2012-01-10 17:20:56 -05:00
end
end
end
end
end