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

server provisioning completed

This commit is contained in:
nightshade427 2011-03-01 16:37:27 -05:00 committed by Nicholas Ricketts
parent 57188adf91
commit d87127d211
22 changed files with 365 additions and 23 deletions

View file

@ -17,6 +17,10 @@ module Fog
collection :kernels
model :data_center
collection :data_centers
model :stack_script
collection :stack_scripts
model :ip
collection :ips
request_path 'fog/compute/requests/linode'
request :avail_datacenters
@ -24,14 +28,22 @@ module Fog
request :avail_kernels
request :avail_linodeplans
request :avail_stackscripts
# request :linode_boot
request :linode_boot
request :linode_ip_list
request :linode_ip_addprivate
request :linode_config_list
request :linode_create
request :linode_delete
request :linode_list
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_update
request :linode_update
class Mock

View file

@ -13,12 +13,12 @@ module Fog
private
def datacenters(id=nil)
connection.avail_datacenters.body['DATA'].tap { |data| map_datacenters data }
connection.avail_datacenters.body['DATA'].map { |datacenter| map_datacenter datacenter }
end
def map_datacenters(datacenters)
datacenters.map! { |datacenter| datacenter.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
datacenters.each { |datacenter| datacenter.merge! :id => datacenter[:datacenterid], :name => datacenter[:location] }
def map_datacenter(datacenter)
datacenter = datacenter.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
datacenter.merge! :id => datacenter[:datacenterid], :name => datacenter[:location]
end
end
end

View file

@ -19,12 +19,12 @@ module Fog
private
def flavors(id=nil)
connection.avail_linodeplans(id).body['DATA'].tap { |data| map_flavors data }
connection.avail_linodeplans(id).body['DATA'].map { |flavor| map_flavor flavor }
end
def map_flavors(flavors)
flavors.map! { |flavor| flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
flavors.each { |flavor| flavor.merge! :id => flavor[:planid], :name => flavor[:label] }
def map_flavor(flavor)
flavor = flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
flavor.merge! :id => flavor[:planid], :name => flavor[:label]
end
end
end

View file

@ -19,12 +19,11 @@ module Fog
private
def images(id=nil)
connection.avail_distributions(id).body['DATA'].tap { |data| map_images data }
connection.avail_distributions(id).body['DATA'].map { |image| map_image image }
end
def map_images(images)
images.map! { |image| image.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
images.each do |image|
def map_image(image)
image = image.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
image.merge!(:id => image[:distributionid], :name => image[:label], :image_size => image[:minimagesize],
:kernel_id => image[:requirespvopskernel], :bits => ((image[:is64bit] == 1) ? 64 : 32 ))
end
@ -32,4 +31,3 @@ module Fog
end
end
end
end

View file

@ -0,0 +1,13 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class Ip < Fog::Model
identity :id
attribute :ip
attribute :public
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
require 'fog/compute/models/linode/ip'
module Fog
module Linode
class Compute
class Ips < Fog::Collection
model Fog::Linode::Compute::Ip
def all(linode_id)
load ips(linode_id)
end
def get(linode_id, id)
new ips(linode_id, id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def ips(linode_id, id=nil)
connection.linode_ip_list(linode_id, id).body['DATA'].map { |ip| map_ip ip }
end
def map_ip(ip)
ip = ip.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
ip.merge! :id => ip[:ipaddressid], :ip => ip[:ipaddress], :public => ip[:ispublic]==1
end
end
end
end
end

View file

@ -19,12 +19,12 @@ module Fog
private
def kernels(id=nil)
connection.avail_kernels(id).body['DATA'].tap { |data| map_kernels data }
connection.avail_kernels(id).body['DATA'].map { |kernel| map_kernel kernel }
end
def map_kernels(kernels)
kernels.map! { |kernel| kernel.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
kernels.each { |kernel| kernel.merge! :id => kernel[:kernelid], :name => kernel[:label] }
def map_kernel(kernel)
kernel = kernel.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
kernel.merge! :id => kernel[:kernelid], :name => kernel[:label]
end
end
end

View file

@ -0,0 +1,40 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class Server < Fog::Model
identity :id
attribute :name
attribute :status
def ips
connection.ips.all(self.id)
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
id = connection.linode_create(data_center.id, flavor.id, 1).body['DATA']['LinodeID']
connection.linode_ip_addprivate id
ip = connection.ips.all(id).find { |ip| !ip.public }
script = connection.stack_scripts.get 2161
script_options = { :hostname => name, :privip => ip.ip }
swap = connection.linode_disk_create(id, "#{name}_swap", 'swap', flavor.ram).body['DATA']['DiskID']
disk = connection.linode_disk_createfromstackscript(id, script.id, image.id, "#{name}_main",
(flavor.disk*1024)-flavor.ram, password, script_options).body['DATA']['DiskID']
config = connection.linode_config_create(id, 110, name, "#{disk},#{swap},,,,,,,").body['DATA']['ConfigID']
connection.linode_update id, :label => name
connection.linode_boot id, config
new_server = connection.servers.get id
# merge_attributes(new_server)
true
end
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
require 'fog/compute/models/linode/server'
module Fog
module Linode
class Compute
class Servers < Fog::Collection
model Fog::Linode::Compute::Server
def all
load servers
end
def get(id)
new servers(id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def servers(id=nil)
connection.linode_list(id).body['DATA'].map { |server| map_server server }
end
def map_server(server)
server = server.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
server.merge! :id => server[:linodeid], :name => server[:label]
end
end
end
end
end

View file

@ -0,0 +1,12 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class StackScript < Fog::Model
identity :id
attribute :name
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/core/collection'
require 'fog/compute/models/linode/stack_script'
module Fog
module Linode
class Compute
class StackScripts < Fog::Collection
model Fog::Linode::Compute::StackScript
def all
load stackscripts
end
def get(id)
new stackscripts(id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def stackscripts(id=nil)
connection.stackscript_list(id).body['DATA'].map { |script| map_stackscript script }
end
def map_stackscript(script)
script = script.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
script.merge! :id => script[:stackscriptid], :name => script[:label]
end
end
end
end
end

View file

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

View file

@ -0,0 +1,21 @@
module Fog
module Linode
class Compute
class Real
def linode_config_create(linode_id, kernel_id, name, disk_list)
request(
:expects => 200,
:method => 'GET',
:query => {
:api_action => 'linode.config.create',
:linodeId => linode_id,
:kernelId => kernel_id,
:label => name,
:diskList => disk_list
}
)
end
end
end
end
end

View file

@ -2,7 +2,7 @@ module Fog
module Linode
class Compute
class Real
def avail_configs(linode_id, config_id=nil, options={})
def linode_config_list(linode_id, config_id=nil, options={})
if config_id
options.merge!(:configid => config_id)
end

View file

@ -2,7 +2,7 @@ module Fog
module Linode
class Compute
class Real
def linode_create(datacenter_id, payment_term, plan_id)
def linode_create(datacenter_id, plan_id, payment_term)
request(
:expects => 200,
:method => 'GET',

View file

@ -0,0 +1,21 @@
module Fog
module Linode
class Compute
class Real
def linode_disk_create(linode_id, name, type, size)
request(
:expects => 200,
:method => 'GET',
:query => {
:api_action => 'linode.disk.create',
:linodeId => linode_id,
:label => name,
:type => type,
:size => size
}
)
end
end
end
end
end

View file

@ -0,0 +1,22 @@
module Fog
module Linode
class Compute
class Real
def linode_disk_createfromdistribution(linode_id, distro_id, name, size, password)
request(
:expects => 200,
:method => 'GET',
:query => {
:api_action => 'linode.disk.createfromdistribution',
:linodeId => linode_id,
:distributionId => distro_id,
:label => name,
:size => size,
:rootPass => password
}
)
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Linode
class Compute
class Real
def linode_disk_createfromstackscript(linode_id, script_id, distro_id, name, size, password, options={})
request(
:expects => 200,
:method => 'GET',
:query => {
:api_action => 'linode.disk.createfromstackscript',
:linodeId => linode_id,
:stackScriptID => script_id,
:distributionId => distro_id,
:label => name,
:size => size,
:rootPass => password,
:stackScriptUDFResponses => options.to_json
}
)
end
end
end
end
end

View file

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

View file

@ -0,0 +1,19 @@
module Fog
module Linode
class Compute
class Real
def linode_ip_list(linode_id, ip_id=nil)
options = {}
if ip_id
options.merge!(:ipaddressId => ip_id)
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'linode.ip.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_update(linode_id, options={})
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'linode.update', :linodeId => linode_id }.merge!(options)
)
end
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Linode
class Compute
class Real
def stackscript_list(script_id=nil)
options = {}
if script_id
options.merge!(:stackScriptID => script_id)
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'stackscript.list' }.merge!(options)
)
end
end
end
end
end