Class: Lab::Drivers::RemoteEsxiDriver
- Inherits:
-
VmDriver
- Object
- VmDriver
- Lab::Drivers::RemoteEsxiDriver
show all
- Defined in:
- lib/lab/driver/remote_esxi_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
Returns a new instance of RemoteEsxiDriver.
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/lab/driver/remote_esxi_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
super(config)
@user = filter_command(config['user'])
@host = filter_command(config['host'])
@port = config['port']
end
|
Instance Method Details
#check_file_exists(file) ⇒ Object
121
122
123
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 121
def check_file_exists(file)
raise "Not Implemented"
end
|
#cleanup ⇒ Object
129
130
131
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 129
def cleanup
end
|
#copy_from(from, to) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 105
def copy_from(from, to)
if @os == "linux"
scp_from(from, to)
else
raise "Unimplemented"
end
end
|
#copy_to(from, to) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 113
def copy_to(from, to)
if @os == "linux"
scp_to(from, to)
else
raise "Unimplemented"
end
end
|
#create_directory(directory) ⇒ Object
125
126
127
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 125
def create_directory(directory)
raise "Not Implemented"
end
|
#create_snapshot(snapshot) ⇒ Object
50
51
52
53
54
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 50
def create_snapshot(snapshot)
snapshot = filter_input(snapshot)
remote_system_command("vim-cmd vmsvc/snapshot.create #{@vmid} #{snapshot} \'lab created snapshot\' 1 true")
end
|
#delete_all_snapshots ⇒ Object
97
98
99
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 97
def delete_all_snapshots
remote_system_command("vim-cmd vmsvc/snapshot.removeall #{@vmid}")
end
|
#delete_snapshot(snapshot, remove_children = false) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 78
def delete_snapshot(snapshot, remove_children=false)
snapshots = get_snapshots
snapshots.each do |snapshot_obj|
if snapshot_obj[:display_name].downcase == snapshot.downcase
snapshot_identifier = snapshot_obj[:name].join(" ")
remote_system_command("vim-cmd vmsvc/snapshot.remove #{@vmid} #{remove_children} #{snapshot_identifier}")
return true
end
end
raise "Invalid Snapshot Name"
end
|
#get_snapshots ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 139
def get_snapshots
output = `ssh #{@user}@#{@host} \"vim-cmd vmsvc/snapshot.get #{@vmid}\"`
snapshots = []
current_tree = -1
current_num = 0
count = 0
output_lines = output.split("\n")
output_lines.each do |line|
if line.include?("|") if line.include?("ROOT") current_num = 0
current_tree = current_tree + 1 snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
else
current_num = current_num + 1 snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
end
end
count = count+1
end
snapshots
end
|
#pause ⇒ Object
38
39
40
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 38
def pause
remote_system_command("vim-cmd vmsvc/power.suspend #{@vmid}")
end
|
#reset ⇒ Object
46
47
48
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 46
def reset
remote_system_command("vim-cmd vmsvc/power.reset #{@vmid}")
end
|
#resume ⇒ Object
42
43
44
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 42
def resume
remote_system_command("vim-cmd vmsvc/power.suspendResume #{@vmid}")
end
|
#revert_snapshot(snapshot) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 56
def revert_snapshot(snapshot)
snapshots = get_snapshots
snapshots.each do |snapshot_obj|
if snapshot_obj[:display_name].downcase == snapshot.downcase
snapshot_identifier = snapshot_obj[:name].join(" ")
remote_system_command("vim-cmd vmsvc/snapshot.revert #{@vmid} 0 #{snapshot_identifier}")
return true
end
end
raise "Invalid Snapshot Name"
end
|
#run_command(command) ⇒ Object
101
102
103
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 101
def run_command(command)
raise "Not Implemented"
end
|
#running? ⇒ Boolean
133
134
135
136
137
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 133
def running?
power_status_string = `ssh #{@user}@#{@host} \"vim-cmd vmsvc/power.getstate #{@vmid}\"`
return true if power_status_string =~ /Powered on/
false
end
|
#start ⇒ Object
26
27
28
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 26
def start
remote_system_command("vim-cmd vmsvc/power.on #{@vmid}")
end
|
#stop ⇒ Object
30
31
32
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 30
def stop
remote_system_command("vim-cmd vmsvc/power.off #{@vmid}")
end
|
#suspend ⇒ Object
34
35
36
|
# File 'lib/lab/driver/remote_esxi_driver.rb', line 34
def suspend
remote_system_command("vim-cmd vmsvc/power.suspend #{@vmid}")
end
|