1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/libvirt/models/compute/uri.rb

147 lines
2.5 KiB
Ruby
Raw Normal View History

require 'uri'
2011-08-08 17:22:55 -04:00
require 'cgi'
module Fog
module Compute
module LibvirtUtil
2011-08-08 17:22:55 -04:00
class URI
attr_reader :uri
2011-08-08 17:22:55 -04:00
def initialize(uri)
@parsed_uri=::URI.parse(uri)
@uri=uri
return self
end
2011-08-08 17:22:55 -04:00
# 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?
2011-08-08 17:22:55 -04:00
return scheme.split(/\+/)[1]
end
2011-08-08 17:22:55 -04:00
def scheme
return @parsed_uri.scheme
end
2011-08-08 17:22:55 -04:00
def driver
scheme=@parsed_uri.scheme
return nil if scheme.nil?
2011-08-08 17:22:55 -04:00
return scheme.split(/\+/).first
end
2011-08-08 17:22:55 -04:00
def ssh_enabled?
if remote?
return transport.include?("ssh")
else
return false
end
end
2011-08-08 17:22:55 -04:00
def remote?
return !transport.nil?
end
2011-08-08 17:22:55 -04:00
def user
@parsed_uri.user
end
def host
@parsed_uri.host
end
def port
@parsed_uri.port
end
2011-08-08 17:22:55 -04:00
def password
@parsed_uri.password
end
def name
value("name")
end
2011-08-08 17:22:55 -04:00
def command
value("command")
end
2011-08-08 17:22:55 -04:00
def socket
value("socket")
end
2011-08-08 17:22:55 -04:00
def keyfile
value("command")
end
2011-08-08 17:22:55 -04:00
def netcat
value("netcat")
end
def no_verify?
2011-08-08 17:30:09 -04:00
no_verify=value("no_verify")
return false if no_verify.nil?
if no_verify.to_s=="0"
return false
else
return true
end
end
2011-08-08 17:22:55 -04:00
def verify?
return !no_verify?
end
def no_tty?
no_tty=value("no_tty")
2011-08-08 17:22:55 -04:00
return false if no_tty.nil?
2011-08-08 17:22:55 -04:00
if no_tty=="0"
return false
else
return true
end
end
2011-08-08 17:22:55 -04:00
def tty?
return !no_tty?
end
2011-08-08 17:22:55 -04:00
def pkipath
value("pkipath")
end
2011-08-08 17:22:55 -04:00
# A libvirt URI allows you to specify extra params
# http://libvirt.org/remote.html
private
def value(name)
unless @parsed_uri.query.nil?
params=CGI.parse(@parsed_uri.query)
if params.has_key?(name)
return params[name].first
else
return nil
end
else
return nil
end
end
2011-08-08 17:22:55 -04:00
end
end
end
end