diff --git a/lib/fog/bin.rb b/lib/fog/bin.rb index 5e68015a3..b34575100 100644 --- a/lib/fog/bin.rb +++ b/lib/fog/bin.rb @@ -73,5 +73,6 @@ require 'fog/bin/stormondemand' require 'fog/bin/terremark' require 'fog/bin/vcloud' require 'fog/bin/virtual_box' +require 'fog/bin/vsphere' require 'fog/bin/voxel' require 'fog/bin/zerigo' diff --git a/lib/fog/bin/vsphere.rb b/lib/fog/bin/vsphere.rb new file mode 100644 index 000000000..9d06b916d --- /dev/null +++ b/lib/fog/bin/vsphere.rb @@ -0,0 +1,30 @@ +class Vsphere < Fog::Bin + class << self + + def class_for(key) + case key + when :compute + Fog::Compute::Vsphere + 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 => 'Vsphere') + else + raise ArgumentError, "Unrecognized service: #{key.inspect}" + end + end + @@connections[service] + end + + def services + Fog::Vsphere.services + end + + end +end diff --git a/lib/fog/compute.rb b/lib/fog/compute.rb index 342b3af5e..5f950b9ce 100644 --- a/lib/fog/compute.rb +++ b/lib/fog/compute.rb @@ -56,6 +56,9 @@ module Fog when :voxel require 'fog/voxel/compute' Fog::Compute::Voxel.new(attributes) + when :vsphere + require 'fog/vsphere/compute' + Fog::Compute::Vsphere.new(attributes) else raise ArgumentError.new("#{provider} is not a recognized compute provider") end diff --git a/lib/fog/core/errors.rb b/lib/fog/core/errors.rb index 747291a9a..ce44ff3c3 100644 --- a/lib/fog/core/errors.rb +++ b/lib/fog/core/errors.rb @@ -65,6 +65,9 @@ An alternate file may be used by placing its path in the FOG_RC environment vari :dnsimple_password: :dnsmadeeasy_api_key: :dnsmadeeasy_secret_key: + :vsphere_server: + :vsphere_username: + :vsphere_password: # # End of Fog Credentials File ####################################################### @@ -74,4 +77,4 @@ An alternate file may be used by placing its path in the FOG_RC environment vari end end -end \ No newline at end of file +end diff --git a/lib/fog/providers.rb b/lib/fog/providers.rb index cdf5b6ad6..2bdfe236f 100644 --- a/lib/fog/providers.rb +++ b/lib/fog/providers.rb @@ -18,5 +18,6 @@ require 'fog/slicehost' require 'fog/storm_on_demand' require 'fog/vcloud' require 'fog/virtual_box' +require 'fog/vsphere' require 'fog/voxel' require 'fog/zerigo' diff --git a/lib/fog/vsphere.rb b/lib/fog/vsphere.rb new file mode 100644 index 000000000..aa6ae3314 --- /dev/null +++ b/lib/fog/vsphere.rb @@ -0,0 +1,15 @@ +require 'fog/core' + +module Fog + module Vsphere + + extend Fog::Provider + + module Errors + class ServiceError < Fog::Errors::Error; end + end + + service(:compute, 'vsphere/compute') + + end +end diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb new file mode 100644 index 000000000..25681bf75 --- /dev/null +++ b/lib/fog/vsphere/compute.rb @@ -0,0 +1,73 @@ +module Fog + module Compute + class Vsphere < Fog::Service + + requires :vsphere_username, :vsphere_password, :vsphere_server + recognizes :vsphere_port, :vsphere_path, :vsphere_ns + recognizes :vsphere_rev, :vsphere_ssl + + class Mock + + def initialize(options={}) + Fog::Mock.not_implemented + end + + end + + class Real + + def initialize(options={}) + require 'rbvmomi' + @vsphere_username = options[:vsphere_username] + @vsphere_password = options[:vsphere_password] + @vsphere_server = options[:vsphere_server] + @vsphere_port = options[:vsphere_port] || 443 + @vsphere_path = options[:vsphere_path] || '/sdk' + @vsphere_ns = options[:vsphere_ns] || 'urn:vim25' + @vsphere_rev = options[:vsphere_rev] || '4.0' + @vsphere_ssl = options[:vsphere_ssl] || true + @vsphere_must_reauthenticate = false + + @connection = RbVmomi::VIM.new :host => @vsphere_server, + :port => @vsphere_port, + :path => @vsphere_path, + :ns => @vsphere_ns, + :rev => @vsphere_rev, + :ssl => @vsphere_ssl, + :insecure => true + + # Negotiate the API revision + if not options[:vsphere_rev] + rev = @connection.serviceContent.about.apiVersion + @connection.rev = [ rev, ENV['FOG_VSPHERE_REV'] || '4.1' ].min + end + + @vsphere_is_vcenter = @connection.serviceContent.about.apiType == "VirtualCenter" + + authenticate + end + + def reload + raise NotImplementedError + end + + def request + raise NotImplementedError + end + + private + + def authenticate + begin + @connection.serviceContent.sessionManager.Login :userName => @vsphere_username, + :password => @vsphere_password + rescue RbVmomi::VIM::InvalidLogin => e + raise Fog::Vsphere::Errors::ServiceError, e.message + end + end + + end + + end + end +end