Class: RVC::SnapshotFolder

Inherits:
Object
  • Object
show all
Includes:
InventoryObject
Defined in:
lib/rvc/extensions/VirtualMachine.rb

Instance Attribute Summary

Attributes included from InventoryObject

#rvc_arc, #rvc_parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InventoryObject

included, #ls_text, #rvc_children, #rvc_link, #rvc_path, #rvc_path_str, #rvc_relative_path, #rvc_relative_path_str, #traverse_one

Methods included from ObjectWithFields::ClassMethods

#field, #fields

Methods included from ObjectWithFields

#field, #field_properties, #perfmetrics

Constructor Details

#initialize(vm, ids) ⇒ SnapshotFolder

Returns a new instance of SnapshotFolder.



268
269
270
271
# File 'lib/rvc/extensions/VirtualMachine.rb', line 268

def initialize vm, ids
  @vm = vm
  @ids = ids
end

Class Method Details

.to_sObject



273
274
275
# File 'lib/rvc/extensions/VirtualMachine.rb', line 273

def self.to_s
  'Snapshot'
end

Instance Method Details

#childrenObject



290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/rvc/extensions/VirtualMachine.rb', line 290

def children
  tree = find_tree
  {}.tap do |h|
    tree.childSnapshotList.each do |x|
      name = x.name
      name = x.name + '.1' if h.member? x.name
      while h.member? name
        name = name.succ
      end
      h[name] = RVC::SnapshotFolder.new(@vm, @ids+[x.id])
    end
  end
end

#display_infoObject



304
305
306
307
308
309
310
311
# File 'lib/rvc/extensions/VirtualMachine.rb', line 304

def display_info
  tree = find_tree
  puts "id: #{tree.id}"
  puts "name: #{tree.name}"
  puts "description: #{tree.description}"
  puts "state: #{tree.state}"
  puts "creation time: #{tree.createTime}"
end

#find_treeObject



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/rvc/extensions/VirtualMachine.rb', line 277

def find_tree
  cur = nil
  info = @vm.snapshot
  fail "snapshot not found" unless info
  children = info.rootSnapshotList
  @ids.each do |id|
    cur = children.find { |x| x.id == id }
    fail "snapshot not found" unless cur
    children = cur.childSnapshotList
  end
  cur
end