Class: RbVmomi::VIM::Datastore

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

Instance Method Summary collapse

Instance Method Details

#datacenterObject



216
217
218
219
220
221
222
223
224
# File 'lib/rbvmomi/extensions.rb', line 216

def datacenter
  return @datacenter if @datacenter
  x = parent
  while not x.is_a? Datacenter
    x = x.parent
  end
  fail unless x.is_a? Datacenter
  @datacenter = x
end

#download(remote_path, local_path) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/rbvmomi/extensions.rb', line 244

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

Returns:



230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/rbvmomi/extensions.rb', line 230

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

#mkuripath(path) ⇒ Object



226
227
228
# File 'lib/rbvmomi/extensions.rb', line 226

def mkuripath path
  "/folder/#{URI.escape path}?dcPath=#{URI.escape datacenter.name}&dsName=#{URI.escape name}"
end

#upload(remote_path, local_path) ⇒ Object



255
256
257
258
259
260
261
262
263
264
# File 'lib/rbvmomi/extensions.rb', line 255

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