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/compute/models/linode/disks.rb

41 lines
1,019 B
Ruby
Raw Normal View History

2011-03-04 15:03:51 -05:00
require 'fog/core/collection'
require 'fog/compute/models/linode/disk'
module Fog
module Linode
class Compute
class Disks < Fog::Collection
model Fog::Linode::Compute::Disk
2011-03-07 16:05:20 -05:00
attribute :server
2011-03-04 15:03:51 -05:00
2011-03-07 16:05:20 -05:00
def all
requires :server
load disks(server.id)
2011-03-04 15:03:51 -05:00
end
2011-03-07 16:05:20 -05:00
def get(id)
requires :server
new disks(server.id, id).first
2011-03-04 15:03:51 -05:00
rescue Fog::Linode::Compute::NotFound
nil
end
2011-03-07 16:05:20 -05:00
def new(attributes = {})
requires :server
super({ :server => server }.merge!(attributes))
end
2011-03-04 15:03:51 -05:00
private
def disks(linode_id, id=nil)
connection.linode_disk_list(linode_id, id).body['DATA'].map { |disk| map_disk disk }
end
def map_disk(disk)
disk = disk.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
disk.merge! :id => disk[:diskid], :name => disk[:label], :server_id => disk[:linodeid]
end
end
end
end
end