2012-01-22 10:38:02 -05:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Ovirt < Fog::Service
|
|
|
|
|
|
|
|
requires :ovirt_username, :ovirt_password
|
|
|
|
recognizes :ovirt_url, :ovirt_server, :ovirt_port, :ovirt_api_path, :ovirt_datacenter
|
|
|
|
|
|
|
|
model_path 'fog/ovirt/models/compute'
|
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
model :template
|
|
|
|
collection :templates
|
|
|
|
model :cluster
|
|
|
|
collection :clusters
|
2012-03-12 06:25:03 -04:00
|
|
|
model :interface
|
|
|
|
collection :interfaces
|
2012-04-09 09:42:58 -04:00
|
|
|
model :volume
|
|
|
|
collection :volumes
|
2012-01-22 10:38:02 -05:00
|
|
|
|
|
|
|
request_path 'fog/ovirt/requests/compute'
|
|
|
|
|
|
|
|
request :vm_action
|
|
|
|
request :destroy_vm
|
2012-02-08 06:58:10 -05:00
|
|
|
request :create_vm
|
2012-02-20 07:18:54 -05:00
|
|
|
request :update_vm
|
2012-01-22 10:38:02 -05:00
|
|
|
request :datacenters
|
|
|
|
request :storage_domains
|
2012-02-08 06:58:10 -05:00
|
|
|
request :list_virtual_machines
|
|
|
|
request :get_virtual_machine
|
|
|
|
request :list_templates
|
|
|
|
request :get_template
|
|
|
|
request :list_clusters
|
|
|
|
request :get_cluster
|
2012-03-12 06:25:03 -04:00
|
|
|
request :add_interface
|
|
|
|
request :destroy_interface
|
|
|
|
request :update_interface
|
|
|
|
request :list_vm_interfaces
|
|
|
|
request :list_template_interfaces
|
|
|
|
request :list_networks
|
2012-03-21 10:00:57 -04:00
|
|
|
request :vm_ticket
|
2012-04-09 09:42:58 -04:00
|
|
|
request :list_vm_volumes
|
|
|
|
request :list_template_volumes
|
|
|
|
request :add_volume
|
|
|
|
request :destroy_volume
|
2012-02-08 06:58:10 -05:00
|
|
|
|
|
|
|
module Shared
|
|
|
|
# converts an OVIRT object into an hash for fog to consume.
|
|
|
|
def ovirt_attrs obj
|
|
|
|
opts = {:raw => obj}
|
|
|
|
obj.instance_variables.each do |v|
|
2012-02-08 17:45:12 -05:00
|
|
|
key = v.to_s.gsub("@","").to_sym
|
2012-02-08 06:58:10 -05:00
|
|
|
value = obj.instance_variable_get(v)
|
|
|
|
#ignore nil values
|
|
|
|
next if value.nil?
|
|
|
|
|
2012-02-19 05:44:11 -05:00
|
|
|
opts[key] = case value
|
2012-02-08 06:58:10 -05:00
|
|
|
when OVIRT::Link
|
|
|
|
value.id
|
2012-03-12 06:25:03 -04:00
|
|
|
when Array
|
|
|
|
value
|
2012-02-08 06:58:10 -05:00
|
|
|
when Hash
|
|
|
|
value
|
|
|
|
else
|
|
|
|
value.to_s.strip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
opts
|
|
|
|
end
|
|
|
|
end
|
2012-01-22 10:38:02 -05:00
|
|
|
|
|
|
|
class Mock
|
2012-02-08 06:58:10 -05:00
|
|
|
include Shared
|
|
|
|
|
2012-01-22 10:38:02 -05:00
|
|
|
def initialize(options={})
|
2012-02-08 06:58:10 -05:00
|
|
|
require 'rbovirt'
|
2012-01-22 10:38:02 -05:00
|
|
|
username = options[:ovirt_username]
|
2012-02-02 07:58:46 -05:00
|
|
|
password = options[:ovirt_password]
|
2012-01-22 10:38:02 -05:00
|
|
|
url = options[:ovirt_url]
|
|
|
|
end
|
|
|
|
|
2012-02-08 06:58:10 -05:00
|
|
|
private
|
2012-03-12 06:25:03 -04:00
|
|
|
attr_reader :client
|
2012-02-08 06:58:10 -05:00
|
|
|
#read mocks xml
|
|
|
|
def read_xml(file_name)
|
|
|
|
file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
|
|
|
|
File.read(file_path)
|
|
|
|
end
|
2012-01-22 10:38:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
2012-02-08 06:58:10 -05:00
|
|
|
include Shared
|
2012-03-12 06:25:03 -04:00
|
|
|
|
2012-01-22 10:38:02 -05:00
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
require 'rbovirt'
|
|
|
|
username = options[:ovirt_username]
|
|
|
|
password = options[:ovirt_password]
|
|
|
|
server = options[:ovirt_server]
|
|
|
|
port = options[:ovirt_port] || 8080
|
|
|
|
api_path = options[:ovirt_api_path] || '/api'
|
2012-02-02 07:58:46 -05:00
|
|
|
url = options[:ovirt_url] || "#{@scheme}://#{server}:#{port}#{api_path}"
|
2012-01-22 10:38:02 -05:00
|
|
|
datacenter = options[:ovirt_datacenter]
|
|
|
|
|
|
|
|
@client = OVIRT::Client.new(username, password, url, datacenter)
|
|
|
|
end
|
2012-03-12 06:25:03 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
attr_reader :client
|
2012-01-22 10:38:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|