Method: Lab::Drivers::RemoteEsxiDriver#get_snapshots

Defined in:
lib/lab/driver/remote_esxi_driver.rb

#get_snapshotsObject



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
173
174
175
176
# File 'lib/lab/driver/remote_esxi_driver.rb', line 143

def get_snapshots
  # Command take the format: 
  # vmware-vim-cmd vmsvc/snapshot.revert [vmid: int] [snapshotlevel: int] [snapshotindex: int]
  output = `ssh #{@user}@#{@host} \"vim-cmd vmsvc/snapshot.get #{@vmid}\"`

  # this keeps track of the snapshots, takes the form:
  #[ {:name => [0,0], :display_name => "String containing the snapshotname}, 
  #  {:name => [0,1], :display_name => "String containing the snapshotname}, ]
  #  ... 
  snapshots = []
  
  # Use these to keep track of the parsing...    
  current_tree = -1
  current_num = 0
  count = 0
  
  # Do the parsing & stick the snapshots in the snapshots array
  output_lines = output.split("\n")
  output_lines.each do |line|
    if line.include?("|") # this is a new snapshot
      if line.include?("ROOT") # it's a root
        current_num = 0
        current_tree = current_tree + 1 # new tree
        snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
      else
        current_num = current_num + 1 # new snapshot in current tree
        snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
      end
    end
    count = count+1
  end

snapshots
end