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_link, #rvc_path, #rvc_path_str, #traverse_one

Constructor Details

#initialize(vm, ids) ⇒ SnapshotFolder

Returns a new instance of SnapshotFolder.



122
123
124
125
# File 'lib/rvc/extensions/VirtualMachine.rb', line 122

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

Class Method Details

.to_sObject



127
128
129
# File 'lib/rvc/extensions/VirtualMachine.rb', line 127

def self.to_s
  'Snapshot'
end

Instance Method Details

#childrenObject



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rvc/extensions/VirtualMachine.rb', line 144

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



158
159
160
161
162
163
164
165
# File 'lib/rvc/extensions/VirtualMachine.rb', line 158

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



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rvc/extensions/VirtualMachine.rb', line 131

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