Class: Snap::Command

Inherits:
Vagrant::Command::GroupBase
  • Object
show all
Defined in:
lib/vagrant_snap.rb

Instance Method Summary collapse

Instance Method Details

#back(target = nil) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/vagrant_snap.rb', line 146

def back(target=nil)
   with_target(target) do |vmname, vagvmname|
     puts "[#{vagvmname}]"
     system "VBoxManage controlvm #{vmname} poweroff"
     system "VBoxManage snapshot  #{vmname} restorecurrent"
     system "VBoxManage startvm   #{vmname} --type headless"
   end
end

#delete(snapshot_name, target = nil) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/vagrant_snap.rb', line 186

def delete(snapshot_name, target=nil)
   with_target(target) do |vmname, vagvmname|
     puts "[#{vagvmname}]"
     VBox::SnapShot.parse_tree( vmname )
     if VBox::SnapShot.include?( snapshot_name )
       system "VBoxManage snapshot #{vmname} delete #{snapshot_name}"
     else
       warn "#{snapshot_name} is not exist".red
     end
   end
end

#go(snapshot_name, target = nil) ⇒ Object



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

def go(snapshot_name, target=nil)
   with_target(target) do |vmname, vagvmname|
     puts "[#{vagvmname}]"
     VBox::SnapShot.parse_tree( vmname )
     if VBox::SnapShot.include?( snapshot_name )
       system "VBoxManage controlvm #{vmname} poweroff"
       system "VBoxManage snapshot  #{vmname} restore #{snapshot_name}"
       system "VBoxManage startvm   #{vmname} --type headless"
     else
       warn "#{snapshot_name} is not exist".red
     end
   end
end

#list(target = nil) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vagrant_snap.rb', line 117

def list(target=nil)
   with_target(target) do |vmname, vagvmname|
     puts "[#{vagvmname}]"
     VBox::SnapShot.parse_tree( vmname )
     if VBox::SnapShot.tree
       result = VBox::SnapShot.show
     else
       result = "no snapshot"
     end
     puts result
   end
end

#take(target = nil) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/vagrant_snap.rb', line 158

def take(target=nil)
   with_target(target) do |vmname, vagvmname|
     puts "[#{vagvmname}]"
     VBox::SnapShot.parse_tree( vmname )
     if options.name
       if VBox::SnapShot.include? options.name
         warn "#{options.name} is already exist".red
         next
       else
         new_name = options.name
       end
     end
     unless new_name
       lastname = VBox::SnapShot.lastname
       new_name = if lastname.nil?
                    "001"
                  else
                    n = lastname.succ
                    n = n.succ while VBox::SnapShot.include? n
                    n
                  end
     end
     desc = options.desc ? " --description '#{options.desc}'" : ""
     system "VBoxManage snapshot #{vmname} take #{new_name} #{desc} --pause"
   end
end