1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

(#9241) Add skeleton VMware vSphere platform support

This patch adds a compute service to fog setting the stage to model
VMware virtual machines using Fog.  The patch adds support for:

    rdebug -- fog vsphere
    >>> connection = Fog::Compute.new(:provider => :vsphere)

The connection to the VMware API is implemented along with
authentication using an username and password.  The connection is not
fully secured with this patch because no validation of the SSL
certificate is implemented.

Raw API requests are working with this patch, but none of the API
requests have associated Fog models or collections.
This commit is contained in:
Jeff McCune 2011-08-29 20:04:04 -07:00
parent c4c0f1537e
commit 98637d39da
7 changed files with 127 additions and 1 deletions

View file

@ -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'

30
lib/fog/bin/vsphere.rb Normal file
View file

@ -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

View file

@ -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

View file

@ -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
end

View file

@ -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'

15
lib/fog/vsphere.rb Normal file
View file

@ -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

View file

@ -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