[train] add images models for rackspace

This commit is contained in:
Wesley Beary 2009-11-19 08:19:46 -08:00
parent 66ee22f6c3
commit 34c68f00ae
5 changed files with 98 additions and 0 deletions

View File

@ -68,6 +68,14 @@ module Rackspace
:rackspace_username => credentials[:rackspace_username]
)
def flavors
@@servers.flavors
end
def images
@@servers.images
end
def servers
@@servers.servers
end

View File

@ -0,0 +1,34 @@
module Fog
module Rackspace
class Servers
class Image < Fog::Model
identity :id
attribute :name
attribute :created
attribute :updated
attribute :status
attribute :server_id, 'serverId'
def server=(new_server)
@server_id = new_server.id
end
def destroy
connection.delete_image(@id)
true
end
def save
data = connection.create_server(@server_id)
merge_attributes(data.body['image'])
true
end
end
end
end
end

View File

@ -0,0 +1,50 @@
module Fog
module Rackspace
class Servers
def addresses(attributes = {})
Fog::AWS::EC2::Addresses.new({
:connection => self
}.merge!(attributes))
end
def images(attributes = {})
Fog::Rackspace::Servers::Images.new({
:connection => self
}.merge!(attributes))
end
class Images < Fog::Collection
model Fog::Rackspace::Servers::Image
attribute :server
def all
data = connection.list_images_detail.body
servers = Fog::Rackspace::Servers::Images.new({
:connection => connection
})
for image in data['images']
servers << Fog::Rackspace::Servers::Image.new({
:collection => images,
:connection => connection
}.merge!(image))
end
if server
images = images.select {|image| image.server_id == server.id}
end
images
end
def get(image_id)
connection.get_image_details(image_id)
rescue Excon::Errors::NotFound
nil
end
end
end
end
end

View File

@ -22,6 +22,10 @@ module Fog
true
end
def images
connection.images(:server => self)
end
def save
options = { 'metadata' => @metadata, 'personality' => @personality }
options = options.reject {|key, value| value.nil?}

View File

@ -17,6 +17,8 @@ module Fog
def self.reload
load "fog/rackspace/models/servers/flavor.rb"
load "fog/rackspace/models/servers/flavors.rb"
load "fog/rackspace/models/servers/image.rb"
load "fog/rackspace/models/servers/images.rb"
load "fog/rackspace/models/servers/server.rb"
load "fog/rackspace/models/servers/servers.rb"