Add Blue Box location support.

This commit is contained in:
leehuffman 2012-02-12 00:02:52 -08:00
parent a31f820db3
commit 87abce5b30
7 changed files with 113 additions and 7 deletions

View File

@ -15,12 +15,16 @@ module Fog
collection :images
model :server
collection :servers
model :location
collection :locations
request_path 'fog/bluebox/requests/compute'
request :create_block
request :destroy_block
request :get_block
request :get_blocks
request :get_location
request :get_locations
request :get_product
request :get_products
request :get_template

View File

@ -0,0 +1,17 @@
require 'fog/core/model'
module Fog
module Compute
class Bluebox
class Location < Fog::Model
identity :id
attribute :description
end
end
end
end

View File

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/bluebox/models/compute/location'
module Fog
module Compute
class Bluebox
class Locations < Fog::Collection
model Fog::Compute::Bluebox::Location
def all
data = connection.get_locations.body
load(data)
end
def get(location_id)
response = connection.get_location(location_id)
new(response.body)
rescue Fog::Compute::Bluebox::NotFound
nil
end
end
end
end
end

View File

@ -15,6 +15,7 @@ module Fog
attribute :flavor_id, :aliases => :product, :squash => 'id'
attribute :hostname
attribute :image_id
attribute :location_id
attribute :ips
attribute :memory
attribute :state, :aliases => "status"
@ -26,7 +27,8 @@ module Fog
def initialize(attributes={})
self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server
self.image_id ||= '03807e08-a13d-44e4-b011-ebec7ef2c928' # Ubuntu LTS 10.04 64bit
self.image_id ||= 'a8f05200-7638-47d1-8282-2474ef57c4c3' # Scientific Linux 6
self.location_id ||= '02b87c73-02de-445d-9cae-98e914c70d84' # Seattle, WA
super
end
@ -46,6 +48,11 @@ module Fog
connection.images.get(image_id)
end
def location
requires :location_id
connection.locations.get(location_id)
end
def private_ip_address
nil
end
@ -84,7 +91,7 @@ module Fog
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id
requires :flavor_id, :image_id, :location_id
options = {}
if identity.nil? # new record
@ -103,7 +110,7 @@ module Fog
options['username'] = username
options['hostname'] = hostname if @hostname
data = connection.create_block(flavor_id, image_id, options)
data = connection.create_block(flavor_id, image_id, location_id, options)
merge_attributes(data.body)
true
end

View File

@ -18,12 +18,12 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>:
# TODO
def create_block(product_id, template_id, options = {})
def create_block(product_id, template_id, location_id, options = {})
request(
:expects => 200,
:method => 'POST',
:path => '/api/blocks.json',
:query => {'product' => product_id, 'template' => template_id}.merge!(options)
:query => {'product' => product_id, 'template' => template_id, 'location' => location_id}.merge!(options)
)
end

View File

@ -0,0 +1,26 @@
module Fog
module Compute
class Bluebox
class Real
# Get details of a location
#
# ==== Parameters
# * location_id<~Integer> - Id of location to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO
def get_location(location_id)
request(
:expects => 200,
:method => 'GET',
:path => "api/locations/#{location_id}.json"
)
end
end
end
end
end

View File

@ -0,0 +1,24 @@
module Fog
module Compute
class Bluebox
class Real
# Get list of locations
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'id'<~String> - UUID of the location
# * 'description'<~String> - Description of the location
def get_locations
request(
:expects => 200,
:method => 'GET',
:path => 'api/locations.json'
)
end
end
end
end
end