Permalink
Browse files

Merge pull request #29 from frapposelli/fix-file-urls

Fixed file:// URIs handling in OvfManager and CachedOvfDeployer.
  • Loading branch information...
2 parents f6b8972 + 69a888f commit 9a43ed75f92e6163ae39f47e47ad40797c58b542 @cdickmann cdickmann committed Dec 18, 2013
Showing with 13 additions and 2 deletions.
  1. +8 −1 lib/rbvmomi/utils/deploy.rb
  2. +5 −1 lib/rbvmomi/vim/OvfManager.rb
@@ -102,6 +102,13 @@ def upload_ovf_as_template ovf_url, template_name, opts = {}
# simplicity this function assumes we need to read the OVF file
# ourselves to know the names, and we map all of them to the same
# VIM::Network.
+
+ # If we're handling a file:// URI we need to strip the scheme as open-uri
+ # can't handle them.
+ if URI(ovf_url).scheme == "file" && URI(ovf_url).host.nil?
+ ovf_url = URI(ovf_url).path
+ end
+
ovf = open(ovf_url, 'r'){|io| Nokogiri::XML(io.read)}
ovf.remove_namespaces!
networks = ovf.xpath('//NetworkSection/Network').map{|x| x['name']}
@@ -206,7 +213,7 @@ def upload_ovf_as_template ovf_url, template_name, opts = {}
# or nil
def lookup_template template_name
template_path = "#{template_name}-#{@computer.name}"
- template = @template_folder.traverse(template_path, VIM::VirtualMachine)
+ template = @template_folder.traverse(template_path, RbVmomi::VIM::VirtualMachine)
if template
config = template.config
is_template = config && config.template
@@ -95,13 +95,17 @@ def deployOVF opts
raise "Couldn't find deviceURL for device '#{fileItem.deviceId}'"
end
- # XXX handle file:// URIs
ovfFilename = opts[:uri].to_s
tmp = ovfFilename.split(/\//)
tmp.pop
tmp << fileItem.path
filename = tmp.join("/")
+ # If filename doesn't have a URI scheme, we're considering it a local file
+ if URI(filename).scheme.nil?
+ filename = "file://" + filename
+ end
+
method = fileItem.create ? "PUT" : "POST"
keepAliveThread = Thread.new do

0 comments on commit 9a43ed7

Please sign in to comment.