From 87abce5b30662c764ce01b59af85059a345c8246 Mon Sep 17 00:00:00 2001 From: leehuffman Date: Sun, 12 Feb 2012 00:02:52 -0800 Subject: [PATCH] Add Blue Box location support. --- lib/fog/bluebox/compute.rb | 4 +++ lib/fog/bluebox/models/compute/location.rb | 17 +++++++++++ lib/fog/bluebox/models/compute/locations.rb | 28 +++++++++++++++++++ lib/fog/bluebox/models/compute/server.rb | 17 +++++++---- .../bluebox/requests/compute/create_block.rb | 4 +-- .../bluebox/requests/compute/get_location.rb | 26 +++++++++++++++++ .../bluebox/requests/compute/get_locations.rb | 24 ++++++++++++++++ 7 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 lib/fog/bluebox/models/compute/location.rb create mode 100644 lib/fog/bluebox/models/compute/locations.rb create mode 100644 lib/fog/bluebox/requests/compute/get_location.rb create mode 100644 lib/fog/bluebox/requests/compute/get_locations.rb diff --git a/lib/fog/bluebox/compute.rb b/lib/fog/bluebox/compute.rb index 02b6efe1b..5166bc123 100644 --- a/lib/fog/bluebox/compute.rb +++ b/lib/fog/bluebox/compute.rb @@ -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 diff --git a/lib/fog/bluebox/models/compute/location.rb b/lib/fog/bluebox/models/compute/location.rb new file mode 100644 index 000000000..3a15a6a8e --- /dev/null +++ b/lib/fog/bluebox/models/compute/location.rb @@ -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 diff --git a/lib/fog/bluebox/models/compute/locations.rb b/lib/fog/bluebox/models/compute/locations.rb new file mode 100644 index 000000000..d03118802 --- /dev/null +++ b/lib/fog/bluebox/models/compute/locations.rb @@ -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 diff --git a/lib/fog/bluebox/models/compute/server.rb b/lib/fog/bluebox/models/compute/server.rb index 39e98ab81..d9be122f0 100644 --- a/lib/fog/bluebox/models/compute/server.rb +++ b/lib/fog/bluebox/models/compute/server.rb @@ -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 diff --git a/lib/fog/bluebox/requests/compute/create_block.rb b/lib/fog/bluebox/requests/compute/create_block.rb index 22618584e..48525a22e 100644 --- a/lib/fog/bluebox/requests/compute/create_block.rb +++ b/lib/fog/bluebox/requests/compute/create_block.rb @@ -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 diff --git a/lib/fog/bluebox/requests/compute/get_location.rb b/lib/fog/bluebox/requests/compute/get_location.rb new file mode 100644 index 000000000..f08c40a75 --- /dev/null +++ b/lib/fog/bluebox/requests/compute/get_location.rb @@ -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 diff --git a/lib/fog/bluebox/requests/compute/get_locations.rb b/lib/fog/bluebox/requests/compute/get_locations.rb new file mode 100644 index 000000000..e49cac4cb --- /dev/null +++ b/lib/fog/bluebox/requests/compute/get_locations.rb @@ -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