Class: RbVmomi::VIM::Datastore

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvmomi/vim/Datastore.rb

Overview

TODO:

Use an HTTP library instead of executing curl.

Note:

download and upload require curl. If curl is not in your PATH then set the CURL environment variable to point to it.

Instance Method Summary collapse

Instance Method Details

#download(remote_path, local_path) ⇒ void

This method returns an undefined value.

Download a file from this datastore.

Parameters:

  • remote_path (String)

    Source path on the datastore.

  • local_path (String)

    Destination path on the local machine.



27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Boolean

Check whether a file exists on this datastore.

Parameters:

  • path (String)

    Path on the datastore.

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ void

This method returns an undefined value.

Upload a file to this datastore.

Parameters:

  • remote_path (String)

    Destination path on the datastore.

  • local_path (String)

    Source path on the local machine.



42
43
44
45
46
47
48
49
50
51
# 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