class RbVmomi::VIM::Datastore

@note download and upload require curl. If curl is not in your PATH

then set the +CURL+ environment variable to point to it.

@todo Use an HTTP library instead of executing curl.

Constants

CURLBIN

Public Instance Methods

download(remote_path, local_path) click to toggle source

Download a file from this datastore. @param remote_path [String] Source path on the datastore. @param local_path [String] Destination path on the local machine. @return [void]

# File lib/rbvmomi/vim/Datastore.rb, line 27
def download remote_path, local_path
  url = "http#{@soap.http.use_ssl? ? 's' : ''}://#{@soap.http.address}:#{@soap.http.port}#{mkuripath(remote_path)}"
  pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
              "-o", local_path,
              "-b", @soap.cookie,
              url,
              :out => '/dev/null'
  Process.waitpid(pid, 0)
  fail "download failed" unless $?.success?
end
exists?(path) click to toggle source

Check whether a file exists on this datastore. @param path [String] Path on the datastore.

# File lib/rbvmomi/vim/Datastore.rb, line 9
def exists? path
  req = Net::HTTP::Head.new mkuripath(path)
  req.initialize_http_header 'cookie' => @soap.cookie
  resp = @soap.http.request req
  case resp
  when Net::HTTPSuccess
    true
  when Net::HTTPNotFound
    false
  else
    fail resp.inspect
  end
end
upload(remote_path, local_path) click to toggle source

Upload a file to this datastore. @param remote_path [String] Destination path on the datastore. @param local_path [String] Source path on the local machine. @return [void]

# File lib/rbvmomi/vim/Datastore.rb, line 42
def upload remote_path, local_path
  url = "http#{@soap.http.use_ssl? ? 's' : ''}://#{@soap.http.address}:#{@soap.http.port}#{mkuripath(remote_path)}"
  pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
              "-T", local_path,
              "-b", @soap.cookie,
              url,
              :out => '/dev/null'
  Process.waitpid(pid, 0)
  fail "upload failed" unless $?.success?
end

Private Instance Methods

datacenter() click to toggle source
# File lib/rbvmomi/vim/Datastore.rb, line 55
def datacenter
  return @datacenter if @datacenter
  x = parent
  while not x.is_a? RbVmomi::VIM::Datacenter
    x = x.parent
  end
  fail unless x.is_a? RbVmomi::VIM::Datacenter
  @datacenter = x
end
mkuripath(path) click to toggle source
# File lib/rbvmomi/vim/Datastore.rb, line 65
def mkuripath path
  "/folder/#{URI.escape path}?dcPath=#{URI.escape datacenter.name}&dsName=#{URI.escape name}"
end