mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[train] add images models for rackspace
This commit is contained in:
parent
66ee22f6c3
commit
34c68f00ae
5 changed files with 98 additions and 0 deletions
8
bin/fog
8
bin/fog
|
@ -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
|
||||
|
|
34
lib/fog/rackspace/models/servers/image.rb
Normal file
34
lib/fog/rackspace/models/servers/image.rb
Normal 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
|
50
lib/fog/rackspace/models/servers/images.rb
Normal file
50
lib/fog/rackspace/models/servers/images.rb
Normal 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
|
|
@ -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?}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue