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

added images models

This commit is contained in:
nightshade427 2011-03-01 11:10:59 -05:00 committed by Nicholas Ricketts
parent 1d172b85b3
commit b26732a74e
15 changed files with 80 additions and 114 deletions

View file

@ -5,7 +5,6 @@ module Fog
class Compute
class Flavor < Fog::Model
identity :id
attribute :disk
attribute :name
attribute :ram

View file

@ -4,9 +4,7 @@ require 'fog/compute/models/linode/flavor'
module Fog
module Linode
class Compute
class Flavors < Fog::Collection
model Fog::Linode::Compute::Flavor
def all
@ -20,13 +18,13 @@ module Fog
end
private
def flavors(flavor_id=nil)
connection.avail_linodeplans(flavor_id).body['DATA'].tap { |data| map_flavors data }
def flavors(id=nil)
connection.avail_linodeplans(id).body['DATA'].tap { |data| map_flavors data }
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! :name => flavor[:label], :id => flavor[:planid] }
flavors.each { |flavor| flavor.merge! :id => flavor[:planid], :name => flavor[:label] }
end
end
end

View file

@ -0,0 +1,19 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class Image < Fog::Model
identity :id
attribute :name
attribute :bits
attribute :kernel_id
attribute :image_size
def kernel
Kernel.populate kernel_id
end
end
end
end
end

View file

@ -0,0 +1,35 @@
require 'fog/core/collection'
require 'fog/compute/models/linode/image'
module Fog
module Linode
class Compute
class Images < Fog::Collection
model Fog::Linode::Compute::Image
def all
load images
end
def get(id)
new images(id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def images(id=nil)
connection.avail_distributions(id).body['DATA'].tap { |data| map_images data }
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|
image.merge!(:id => image[:distributionid], :name => image[:label], :image_size => image[:minimagesize],
:kernel_id => image[:requirespvopskernel], :bits => ((image[:is64bit] == 1) ? 64 : 32 ))
end
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Linode
class Compute
class Real
def avail_configs(linode_id, config_id=nil, options={})
if config_id
options.merge!(:configid => config_id)
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'linode.config.list', :linodeId => linode_id }.merge!(options)
)
end
end
end
end
end

View file

@ -2,13 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Get available data centers
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_datacenters
request(
:expects => 200,
@ -16,7 +9,6 @@ module Fog
:query => { :api_action => 'avail.datacenters' }
)
end
end
end
end

View file

@ -2,16 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Get available distributions
#
# ==== Parameters
# * distributionId<~Integer>: id to limit results to
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_distributions(distribution_id=nil)
options = {}
if distribution_id
@ -23,7 +13,6 @@ module Fog
:query => { :api_action => 'avail.distributions' }.merge!(options)
)
end
end
end
end

View file

@ -2,18 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Get available kernels
#
# ==== Parameters
# * options<~Hash>:
# * kernelId<~Integer>: id to limit results to
# * isXen<~Integer>: if 1 limits results to only zen
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_kernels(options={})
request(
:expects => 200,
@ -21,7 +9,6 @@ module Fog
:query => { :api_action => 'avail.kernels' }.merge!(options)
)
end
end
end
end

View file

@ -2,25 +2,21 @@ module Fog
module Linode
class Compute
class Real
# Get available plans
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_linodeplans(linodeplan_id = nil)
options = {}
if linodeplan_id
options.merge!(:planId => linodeplan_id)
end
request(
result = request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'avail.linodeplans' }.merge!(options)
)
#hack for plans not filtering by id like they should above, remove when they fix it.
result.body["DATA"] = result.body["DATA"].select { |item| item['PLANID'] == linodeplan_id } if linodeplan_id
result
end
end
end
end

View file

@ -2,19 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Get available stack scripts
#
# ==== Parameters
# * options<~Hash>:
# * distributionId<~Integer>: Limit the results to Stackscripts that can be applied to this distribution id
# * distributionVendor<~String>: Debian, Ubuntu, Fedora, etc.
# * keywords<~String>: Search terms
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_stackscripts(options={})
request(
:expects => 200,
@ -22,7 +9,6 @@ module Fog
:query => { :api_action => 'avail.stackscripts' }.merge!(options)
)
end
end
end
end

View file

@ -2,18 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Creates a linode and assigns you full privileges
#
# ==== Parameters
# * datacenter_id<~Integer>: id of datacenter to place new linode in
# * payment_term<~Integer>: Subscription term in months, in [1, 12, 24]
# * plan_id<~Integer>: id of plan to boot new linode with
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def linode_create(datacenter_id, payment_term, plan_id)
request(
:expects => 200,
@ -26,7 +14,6 @@ module Fog
}
)
end
end
end
end

View file

@ -2,18 +2,6 @@ module Fog
module Linode
class Compute
class Real
# List all linodes user has access or delete to
#
# ==== Parameters
# * linode_id<~Integer>: id of linode to delete
# * options<~Hash>:
# * skipChecks<~Boolean>: skips safety checks and always deletes
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def linode_delete(linode_id, options={})
request(
:expects => 200,
@ -21,7 +9,6 @@ module Fog
:query => { :api_action => 'linode.delete', :linodeId => linode_id }.merge!(options)
)
end
end
end
end

View file

@ -2,16 +2,6 @@ module Fog
module Linode
class Compute
class Real
# List all linodes user has access or delete to
#
# ==== Parameters
# * linodeId<~Integer>: Limit the list to the specified LinodeID
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def linode_list(linode_id=nil)
options = {}
if linode_id
@ -23,7 +13,6 @@ module Fog
:query => { :api_action => 'linode.list' }.merge!(options)
)
end
end
end
end

View file

@ -2,18 +2,6 @@ module Fog
module Linode
class Compute
class Real
# Issues a shutdown, and then a boot job for a given linode
#
# ==== Parameters
# * linode_id<~Integer>: id of linode to reboot
# * options<~Hash>:
# * configId<~Boolean>: id of config to boot server with
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def linode_reboot(linode_id, options={})
request(
:expects => 200,
@ -21,7 +9,6 @@ module Fog
:query => { :api_action => 'linode.reboot', :linodeId => linode_id }.merge!(options)
)
end
end
end
end

View file

@ -2,12 +2,9 @@ require 'fog/core'
module Fog
module Linode
extend Fog::Provider
service(:compute, 'compute/linode')
service(:dns, 'dns/linode')
end
end