Class: Lab::Drivers::VsphereDriver

Inherits:
VmDriver
  • Object
show all
Defined in:
lib/lab/driver/vsphere_driver.rb

Instance Attribute Summary

Attributes inherited from VmDriver

#credentials, #location, #os, #tools, #vmid

Instance Method Summary collapse

Methods inherited from VmDriver

#register, #unregister

Constructor Details

#initialize(config) ⇒ VsphereDriver

Returns a new instance of VsphereDriver.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lab/driver/vsphere_driver.rb', line 15

def initialize(config)
  unless config['user'] then raise ArgumentError, "Must provide a username" end
  unless config['host'] then raise ArgumentError, "Must provide a hostname" end
  unless config['pass'] then raise ArgumentError, "Must provide a password" end
  super(config)

  @user = filter_command(config['user'])
  @host = filter_command(config['host'])

  # Soft dependency
  begin
    require 'rbvmomi'
  rescue LoadError
    raise "WARNING: Library rbvmomi not found. Could not create driver!"
  end

  vim = RbVmomi::VIM.connect host: @host, user: @user, password: @pass, insecure: true
  dc = vim.serviceInstance.find_datacenter("datacenter1") or fail "datacenter not found"
  @vm = dc.find_vm("test") or fail "VM not found"
end

Instance Method Details

#check_file_exists(file) ⇒ Object



101
102
103
# File 'lib/lab/driver/vsphere_driver.rb', line 101

def check_file_exists(file)
  raise "Unimplemented"
end

#cleanupObject



109
110
111
# File 'lib/lab/driver/vsphere_driver.rb', line 109

def cleanup
  raise "Unimplemented"
end

#copy_from(from, to) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/lab/driver/vsphere_driver.rb', line 85

def copy_from(from, to)
  if @os == "linux"
    scp_from(from, to)
  else
    raise "Unimplemented"
  end
end

#copy_to(from, to) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/lab/driver/vsphere_driver.rb', line 93

def copy_to(from, to)
  if @os == "linux"
    scp_to(from, to)
  else
    raise "Unimplemented"
  end
end

#create_directory(directory) ⇒ Object



105
106
107
# File 'lib/lab/driver/vsphere_driver.rb', line 105

def create_directory(directory)
  raise "Unimplemented"
end

#create_snapshot(snapshot) ⇒ Object



60
61
62
63
# File 'lib/lab/driver/vsphere_driver.rb', line 60

def create_snapshot(snapshot)
  snapshot = filter_input(snapshot)
  raise "Unimplemented"
end

#delete_all_snapshotsObject



77
78
79
# File 'lib/lab/driver/vsphere_driver.rb', line 77

def delete_all_snapshots
  raise "Unimplemented"
end

#delete_snapshot(snapshot, remove_children = false) ⇒ Object



71
72
73
74
75
# File 'lib/lab/driver/vsphere_driver.rb', line 71

def delete_snapshot(snapshot, remove_children=false)
  raise "Unimplemented"
  # If we got here, the snapshot didn't exist
  raise "Invalid Snapshot Name"
end

#pauseObject



48
49
50
# File 'lib/lab/driver/vsphere_driver.rb', line 48

def pause
  raise "Unimplemented"
end

#resetObject



56
57
58
# File 'lib/lab/driver/vsphere_driver.rb', line 56

def reset
  @vm.ResetVM_Task.wait_for_completion
end

#resumeObject



52
53
54
# File 'lib/lab/driver/vsphere_driver.rb', line 52

def resume
  raise "Unimplemented"
end

#revert_snapshot(snapshot) ⇒ Object



65
66
67
68
69
# File 'lib/lab/driver/vsphere_driver.rb', line 65

def revert_snapshot(snapshot)
  raise "Unimplemented"
  # If we got here, the snapshot didn't exist
  raise "Invalid Snapshot Name"
end

#run_command(command) ⇒ Object



81
82
83
# File 'lib/lab/driver/vsphere_driver.rb', line 81

def run_command(command)
  raise "Unimplemented"
end

#running?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/lab/driver/vsphere_driver.rb', line 113

def running?
  raise "Unimplemented"
end

#startObject



36
37
38
# File 'lib/lab/driver/vsphere_driver.rb', line 36

def start
  @vm.PowerOnVM_Task.wait_for_completion
end

#stopObject



40
41
42
# File 'lib/lab/driver/vsphere_driver.rb', line 40

def stop
  @vm.PowerOffVM_Task.wait_for_completion
end

#suspendObject



44
45
46
# File 'lib/lab/driver/vsphere_driver.rb', line 44

def suspend
  @vm.SuspendVM_Task.wait_for_completion
end