Add Blue Box location support.
This commit is contained in:
parent
a31f820db3
commit
87abce5b30
|
@ -15,12 +15,16 @@ module Fog
|
||||||
collection :images
|
collection :images
|
||||||
model :server
|
model :server
|
||||||
collection :servers
|
collection :servers
|
||||||
|
model :location
|
||||||
|
collection :locations
|
||||||
|
|
||||||
request_path 'fog/bluebox/requests/compute'
|
request_path 'fog/bluebox/requests/compute'
|
||||||
request :create_block
|
request :create_block
|
||||||
request :destroy_block
|
request :destroy_block
|
||||||
request :get_block
|
request :get_block
|
||||||
request :get_blocks
|
request :get_blocks
|
||||||
|
request :get_location
|
||||||
|
request :get_locations
|
||||||
request :get_product
|
request :get_product
|
||||||
request :get_products
|
request :get_products
|
||||||
request :get_template
|
request :get_template
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -15,6 +15,7 @@ module Fog
|
||||||
attribute :flavor_id, :aliases => :product, :squash => 'id'
|
attribute :flavor_id, :aliases => :product, :squash => 'id'
|
||||||
attribute :hostname
|
attribute :hostname
|
||||||
attribute :image_id
|
attribute :image_id
|
||||||
|
attribute :location_id
|
||||||
attribute :ips
|
attribute :ips
|
||||||
attribute :memory
|
attribute :memory
|
||||||
attribute :state, :aliases => "status"
|
attribute :state, :aliases => "status"
|
||||||
|
@ -26,7 +27,8 @@ module Fog
|
||||||
|
|
||||||
def initialize(attributes={})
|
def initialize(attributes={})
|
||||||
self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server
|
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
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,6 +48,11 @@ module Fog
|
||||||
connection.images.get(image_id)
|
connection.images.get(image_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def location
|
||||||
|
requires :location_id
|
||||||
|
connection.locations.get(location_id)
|
||||||
|
end
|
||||||
|
|
||||||
def private_ip_address
|
def private_ip_address
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -84,7 +91,7 @@ module Fog
|
||||||
|
|
||||||
def save
|
def save
|
||||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
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 = {}
|
options = {}
|
||||||
|
|
||||||
if identity.nil? # new record
|
if identity.nil? # new record
|
||||||
|
@ -103,7 +110,7 @@ module Fog
|
||||||
|
|
||||||
options['username'] = username
|
options['username'] = username
|
||||||
options['hostname'] = hostname if @hostname
|
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)
|
merge_attributes(data.body)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,12 +18,12 @@ module Fog
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * body<~Hash>:
|
# * body<~Hash>:
|
||||||
# TODO
|
# TODO
|
||||||
def create_block(product_id, template_id, options = {})
|
def create_block(product_id, template_id, location_id, options = {})
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:method => 'POST',
|
:method => 'POST',
|
||||||
:path => '/api/blocks.json',
|
: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
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue