diff --git a/.gitignore b/.gitignore index 3ebcd70b3..57908580e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ doc/* rdoc pkg spec/credentials.yml +*~ diff --git a/lib/fog/bin.rb b/lib/fog/bin.rb index e71f8afaa..ccbd00947 100644 --- a/lib/fog/bin.rb +++ b/lib/fog/bin.rb @@ -65,4 +65,5 @@ require 'fog/bin/new_servers' require 'fog/bin/rackspace' require 'fog/bin/slicehost' require 'fog/bin/terremark' +require 'fog/bin/voxel' require 'fog/bin/zerigo' diff --git a/lib/fog/bin/voxel.rb b/lib/fog/bin/voxel.rb new file mode 100644 index 000000000..fae613236 --- /dev/null +++ b/lib/fog/bin/voxel.rb @@ -0,0 +1,30 @@ +class Voxel < Fog::Bin + class << self + + def class_for(key) + case key + when :compute + Fog::Voxel::Compute + else + raise ArgumentError, "Unrecognized service: #{key}" + end + end + + def [](service) + @@connections ||= Hash.new do |hash, key| + hash[key] = case key + when :compute + Fog::Compute.new(:provider => 'Voxel') + else + raise ArgumentError, "Unrecognized service: #{service}" + end + end + @@connections[service] + end + + def services + [:compute] + end + + end +end diff --git a/lib/fog/compute.rb b/lib/fog/compute.rb index 8ec5e5556..cce7a7258 100644 --- a/lib/fog/compute.rb +++ b/lib/fog/compute.rb @@ -28,6 +28,9 @@ module Fog when 'Rackspace' require 'fog/compute/rackspace' Fog::Rackspace::Compute.new(attributes) + when 'Voxel' + require 'fog/compute/voxel' + Fog::Voxel::Compute.new(attributes) when 'Slicehost' require 'fog/compute/slicehost' Fog::Slicehost::Compute.new(attributes) diff --git a/lib/fog/compute/models/voxel/image.rb b/lib/fog/compute/models/voxel/image.rb new file mode 100644 index 000000000..7ebbdbc2e --- /dev/null +++ b/lib/fog/compute/models/voxel/image.rb @@ -0,0 +1,13 @@ +require 'fog/core/model' + +module Fog + module Voxel + class Compute + class Image < Fog::Model + + identity :id + attribute :name + end + end + end +end diff --git a/lib/fog/compute/models/voxel/images.rb b/lib/fog/compute/models/voxel/images.rb new file mode 100644 index 000000000..956241d68 --- /dev/null +++ b/lib/fog/compute/models/voxel/images.rb @@ -0,0 +1,28 @@ +require 'fog/core/collection' +require 'fog/compute/models/voxel/image' + +module Fog + module Voxel + class Compute + + class Images < Fog::Collection + + model Fog::Voxel::Compute::Image + + def all + data = connection.images_list + load(data) + end + + def get(image_id) + data = connection.images_list(image_id).body['image'] + new(data) + rescue Fog::Voxel::Compute::NotFound + nil + end + + end + + end + end +end diff --git a/lib/fog/compute/requests/voxel/images_list.rb b/lib/fog/compute/requests/voxel/images_list.rb new file mode 100644 index 000000000..127c76a46 --- /dev/null +++ b/lib/fog/compute/requests/voxel/images_list.rb @@ -0,0 +1,25 @@ +module Fog + module Voxel + class Compute + class Real + def images_list( image_id = nil ) + options = { :verbosity => 'compact' } + + unless image_id.nil? + options[:verbosity] = 'extended' + options[:image_id] = image_id + end + + data = request("voxel.images.list", options) + data['images']['image'].map { |i| { :id => i['id'], :name => i['summary'] } } + end + end + + class Mock + def images_list + Fog::Mock.not_implemented + end + end + end + end +end diff --git a/lib/fog/compute/voxel.rb b/lib/fog/compute/voxel.rb new file mode 100644 index 000000000..efbef1d86 --- /dev/null +++ b/lib/fog/compute/voxel.rb @@ -0,0 +1,33 @@ +module Fog + module Voxel + class Compute < Fog::Service + + requires :voxel_api_key, :voxel_api_secret + + model_path 'fog/compute/models/voxel' + model :image + collection :images + + request_path 'fog/compute/requests/voxel' + request :images_list + + class Mock + include Collections + end + + class Real + include Collections + + def initialize(options = {}) + require 'hapi' + @connection = HAPI.new( :authkey => { :key => options[:voxel_api_key], :secret => options[:voxel_api_secret] }, :default_format => :ruby ) + end + + def request(voxel_method_name, options = {}) + STDERR.puts "Got called" + @connection.send(voxel_method_name, options) + end + end + end + end +end diff --git a/lib/fog/core/credentials.rb b/lib/fog/core/credentials.rb index 323fc2ed1..60fc60b03 100644 --- a/lib/fog/core/credentials.rb +++ b/lib/fog/core/credentials.rb @@ -75,6 +75,8 @@ An alternate file may be used by placing its path in the FOG_RC environment vari :slicehost_password: :terremark_username: :terremark_password: + :voxel_api_key: + :voxel_api_secret: :zerigo_email: :zerigo_token: # diff --git a/lib/fog/providers/voxel.rb b/lib/fog/providers/voxel.rb new file mode 100644 index 000000000..6f616b137 --- /dev/null +++ b/lib/fog/providers/voxel.rb @@ -0,0 +1,10 @@ +require 'fog/core' + +module Fog + module Voxel + + extend Fog::Provider + + service(:compute, 'compute/rackspace') + end +end