mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add Blue Box location support.
This commit is contained in:
parent
a31f820db3
commit
87abce5b30
7 changed files with 113 additions and 7 deletions
|
@ -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
|
||||
|
|
17
lib/fog/bluebox/models/compute/location.rb
Normal file
17
lib/fog/bluebox/models/compute/location.rb
Normal 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
|
28
lib/fog/bluebox/models/compute/locations.rb
Normal file
28
lib/fog/bluebox/models/compute/locations.rb
Normal 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
|
|
@ -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"
|
||||
|
@ -25,8 +26,9 @@ module Fog
|
|||
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
|
||||
|
||||
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.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server
|
||||
self.image_id ||= 'a8f05200-7638-47d1-8282-2474ef57c4c3' # Scientific Linux 6
|
||||
self.location_id ||= '02b87c73-02de-445d-9cae-98e914c70d84' # Seattle, WA
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -45,6 +47,11 @@ module Fog
|
|||
requires :image_id
|
||||
connection.images.get(image_id)
|
||||
end
|
||||
|
||||
def location
|
||||
requires :location_id
|
||||
connection.locations.get(location_id)
|
||||
end
|
||||
|
||||
def private_ip_address
|
||||
nil
|
||||
|
@ -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
|
||||
|
@ -100,10 +107,10 @@ module Fog
|
|||
elsif @lb_applications
|
||||
options['lb_applications'] = lb_applications
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
26
lib/fog/bluebox/requests/compute/get_location.rb
Normal file
26
lib/fog/bluebox/requests/compute/get_location.rb
Normal 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
|
24
lib/fog/bluebox/requests/compute/get_locations.rb
Normal file
24
lib/fog/bluebox/requests/compute/get_locations.rb
Normal 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
|
Loading…
Add table
Reference in a new issue