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

server creation and deletion working

This commit is contained in:
nightshade427 2011-03-04 15:03:51 -05:00 committed by Nicholas Ricketts
parent d87127d211
commit a810092449
7 changed files with 130 additions and 8 deletions

View file

@ -21,6 +21,8 @@ module Fog
collection :stack_scripts
model :ip
collection :ips
model :disk
collection :disks
request_path 'fog/compute/requests/linode'
request :avail_datacenters
@ -28,22 +30,24 @@ module Fog
request :avail_kernels
request :avail_linodeplans
request :avail_stackscripts
request :linode_boot
request :linode_disk_create
request :linode_disk_list
request :linode_disk_delete
request :linode_disk_createfromdistribution
request :linode_disk_createfromstackscript
request :linode_ip_list
request :linode_ip_addprivate
request :linode_config_list
request :linode_config_create
request :linode_create
request :linode_delete
request :linode_list
request :linode_boot
request :linode_reboot
request :linode_disk_create
request :linode_disk_createfromdistribution
request :linode_disk_createfromstackscript
request :linode_config_create
request :stackscript_list
# request :linode_resize
# request :linode_shutdown
request :linode_shutdown
request :linode_update
request :stackscript_list
# request :linode_resize
class Mock

View file

@ -0,0 +1,18 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class Disk < Fog::Model
identity :id
attribute :name
attribute :type
attribute :server_id
def delete
connection.linode_disk_delete server_id, id
end
end
end
end
end

View file

@ -0,0 +1,32 @@
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
def all(linode_id)
load disks(linode_id)
end
def get(linode_id, id)
new disks(linode_id, id).first
rescue Fog::Linode::Compute::NotFound
nil
end
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

View file

@ -12,6 +12,14 @@ module Fog
connection.ips.all(self.id)
end
def disks
connection.disks.all(self.id)
end
def disks?
not disks.empty?
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
data_center, flavor, image, name, password = attributes.values_at :data_center, :flavor, :image, :name, :password
@ -34,6 +42,13 @@ module Fog
# merge_attributes(new_server)
true
end
def delete
connection.linode_shutdown id
disks.each { |disk| disk.delete }
wait_for { not disks? }
connection.linode_delete id
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Linode
class Compute
class Real
def linode_disk_delete(linode_id, disk_id)
request(
:expects => 200,
:method => 'GET',
:query => {
:api_action => 'linode.disk.delete',
:linodeId => linode_id,
:diskId => disk_id
}
)
end
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Linode
class Compute
class Real
def linode_disk_list(linode_id, disk_id=nil)
options = {}
if disk_id
options.merge!(:diskId => disk_id)
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'linode.disk.list', :linodeId => linode_id }.merge!(options)
)
end
end
end
end
end

View file

@ -0,0 +1,15 @@
module Fog
module Linode
class Compute
class Real
def linode_shutdown(linode_id)
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'linode.shutdown', :linodeId => linode_id }
)
end
end
end
end
end