1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

initial commit of Rackspace::Servers server models

This commit is contained in:
Wesley Beary 2009-10-14 22:03:16 -07:00
parent 22fe3b41db
commit 5830adeccb
3 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,49 @@
module Fog
module Rackspace
class Server
class Server < Fog::Model
attribute :admin_pass, 'adminPass'
attribute :id
attribute :name
attribute :image_id, 'imageId'
attribute :flavor_id, 'flavorId'
attribute :host_id, 'hostId'
attribute :status
attribute :personality
attribute :progress
attribute :addresses
attribute :metadata
def destroy
connection.delete_server(@id)
true
end
def reload
new_attributes = servers.get(@id).attributes
merge_attributes(new_attributes)
end
def save
data = connection.create_server(@flavor_id, @image_id)
merge_attributes(data.body['server'])
true
end
def servers
@servers
end
private
def servers=(new_servers)
@servers = new_servers
end
end
end
end
end

View file

@ -0,0 +1,52 @@
module Fog
module Rackspace
class Servers
def servers
Fog::Rackspace::Servers::Servers.new(:connection => self)
end
class Servers < Fog::Collection
def all
data = connection.get_servers_details.body
servers = Fog::Rackspace::Servers::Servers.new({
:connection => connection
})
for server in data['servers']
servers << Fog::Rackspace::Servers::Server.new({
:connection => connection,
:servers => servers
}.merge!(server))
end
servers
end
def create(attributes = {})
server = new(attributes)
server.save
server
end
def get(id)
connection.get_server_details(id)
rescue Fog::Errors::NotFound
nil
end
def new
Fog::Rackspace::Servers::Server.new(
:connection => connection,
:servers => self
)
end
def reload
get(id)
end
end
end
end
end

View file

@ -3,6 +3,9 @@ module Fog
class Servers
def self.reload
load "fog/rackspace/models/servers/server.rb"
load "fog/rackspace/models/servers/servers.rb"
load "fog/rackspace/requests/servers/create_server.rb"
load "fog/rackspace/requests/servers/delete_server.rb"
load "fog/rackspace/requests/servers/get_flavors.rb"