mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
- Added URI helper to parse libvirt URL's
- exposed Libvirt original connection in Compute object - exposed URI in Compute object - added libvirt-ruby gem to the developer Gemspec
This commit is contained in:
parent
1e31e1e41d
commit
ef02c51d7e
3 changed files with 148 additions and 4 deletions
|
@ -54,6 +54,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency('rspec', '~>1.3.1')
|
||||
s.add_development_dependency('shindo', '~>0.3.4')
|
||||
s.add_development_dependency('virtualbox', '~>0.8.3')
|
||||
s.add_development_dependency('ruby-libvirt','~>0.4.0')
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'fog/compute/models/libvirt/uri'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Libvirt < Fog::Service
|
||||
|
@ -26,12 +28,15 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
attr_reader :connection
|
||||
attr_reader :uri
|
||||
|
||||
def initialize(options={})
|
||||
@uri = options[:libvirt_uri]
|
||||
@uri = ::Fog::Compute::LibvirtUtil::URI.new(options[:libvirt_uri])
|
||||
|
||||
#libvirt is part of the gem => ruby-libvirt
|
||||
# libvirt is part of the gem => ruby-libvirt
|
||||
require 'libvirt'
|
||||
@connection = ::Libvirt::open(@uri)
|
||||
@connection = ::Libvirt::open(@uri.uri)
|
||||
end
|
||||
|
||||
# hack to provide 'requests'
|
||||
|
@ -42,7 +47,7 @@ module Fog
|
|||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
138
lib/fog/compute/models/libvirt/uri.rb
Normal file
138
lib/fog/compute/models/libvirt/uri.rb
Normal file
|
@ -0,0 +1,138 @@
|
|||
require 'uri'
|
||||
require 'cgi'
|
||||
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
module LibvirtUtil
|
||||
|
||||
class URI
|
||||
|
||||
attr_reader :uri
|
||||
|
||||
def initialize(uri)
|
||||
@parsed_uri=::URI.parse(uri)
|
||||
@uri=uri
|
||||
return self
|
||||
end
|
||||
|
||||
# Transport will be part of the scheme
|
||||
# The part after the plus sign
|
||||
# f.i. qemu+ssh
|
||||
def transport
|
||||
scheme=@parsed_uri.scheme
|
||||
return nil if scheme.nil?
|
||||
|
||||
return scheme.split(/\+/)[1]
|
||||
end
|
||||
|
||||
def scheme
|
||||
return @parsed_uri.scheme
|
||||
end
|
||||
|
||||
def driver
|
||||
scheme=@parsed_uri.scheme
|
||||
return nil if scheme.nil?
|
||||
|
||||
return scheme.split(/\+/).first
|
||||
end
|
||||
|
||||
def ssh_enabled?
|
||||
transport.include?("ssh")
|
||||
end
|
||||
|
||||
def remote?
|
||||
return !transport.nil?
|
||||
end
|
||||
|
||||
def user
|
||||
@parsed_uri.user
|
||||
end
|
||||
|
||||
def host
|
||||
@parsed_uri.host
|
||||
end
|
||||
|
||||
def port
|
||||
@parsed_uri.port
|
||||
end
|
||||
|
||||
def password
|
||||
@parsed_uri.password
|
||||
end
|
||||
|
||||
def name
|
||||
value("name")
|
||||
end
|
||||
|
||||
def command
|
||||
value("command")
|
||||
end
|
||||
|
||||
def socket
|
||||
value("socket")
|
||||
end
|
||||
|
||||
def keyfile
|
||||
value("command")
|
||||
end
|
||||
|
||||
def netcat
|
||||
value("netcat")
|
||||
end
|
||||
|
||||
def no_verify?
|
||||
no_verify=value("no_verify")
|
||||
return false if no_verify.nil?
|
||||
|
||||
if no_verify.to_s=="0"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
def verify?
|
||||
return !no_verify?
|
||||
end
|
||||
|
||||
def no_tty?
|
||||
no_tty=value("no_tty")
|
||||
|
||||
return false if no_tty.nil?
|
||||
|
||||
if no_tty=="0"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def tty?
|
||||
return !no_tty?
|
||||
end
|
||||
|
||||
def pkipath
|
||||
value("pkipath")
|
||||
end
|
||||
|
||||
|
||||
# A libvirt URI allows you to specify extra params
|
||||
# http://libvirt.org/remote.html
|
||||
private
|
||||
def value(name)
|
||||
params=CGI.parse(@parsed_uri.query)
|
||||
if params.has_key?(name)
|
||||
return params[name].first
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue