Class: RbVmomi::VIM::Datastore

Inherits:
Object
  • Object
show all
Defined in:
lib/vcenter_driver.rb

Overview

Monkey patch rbvmomi library with some extra functions

Instance Method Summary collapse

Instance Method Details

#download_to_stdout(remote_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.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vcenter_driver.rb', line 57

def download_to_stdout remote_path
    url = "http#{_connection.http.use_ssl? ? 's' : ''}://#{_connection.http.address}:#{_connection.http.port}#{mkuripath(remote_path)}"

    pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
                "-b", _connection.cookie,
                url


    Process.waitpid(pid, 0)
    fail "download failed" unless $?.success?
end

#get_text_file(remote_path) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vcenter_driver.rb', line 89

def get_text_file remote_path
    url = "http#{_connection.http.use_ssl? ? 's' : ''}://#{_connection.http.address}:#{_connection.http.port}#{mkuripath(remote_path)}"

    rout, wout = IO.pipe
    pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
                "-b", _connection.cookie,
                url,
                :out => wout,
                :err => '/dev/null'

    Process.waitpid(pid, 0)
    fail "get text file failed" unless $?.success?

    wout.close
    output = rout.readlines
    rout.close
    return output
end

#is_descriptor?(remote_path) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vcenter_driver.rb', line 69

def is_descriptor? remote_path
    url = "http#{_connection.http.use_ssl? ? 's' : ''}://#{_connection.http.address}:#{_connection.http.port}#{mkuripath(remote_path)}"

    rout, wout = IO.pipe

    pid = spawn CURLBIN, "-I", "-k", '--noproxy', '*', '-f',
                "-b", _connection.cookie,
                url,
                :out => wout,
                :err => '/dev/null'

    Process.waitpid(pid, 0)
    fail "read image header failed" unless $?.success?

    wout.close
    size = rout.readlines.select{|l| l.start_with?("Content-Length")}[0].sub("Content-Length: ","")
    rout.close
    size.chomp.to_i < 4096   # If <4k, then is a descriptor
end