Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into hyperv_support
Browse files Browse the repository at this point in the history
  • Loading branch information
jtopper committed Sep 28, 2014
2 parents e82b1fd + 510bca9 commit aaf6b40
Show file tree
Hide file tree
Showing 28 changed files with 456 additions and 30 deletions.
52 changes: 52 additions & 0 deletions lib/vagrant-multiprovider-snap/command/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'optparse'
require 'vagrant'

module VagrantSnap

module Command

class Delete < Vagrant.plugin("2", :command)

def execute

options = {}
options[:snap_name] = nil

opts = OptionParser.new do |o|

o.banner = "Usage: vagrant snap delete [vm-name] --name=<snapname>"
o.separator ""

o.on("--name SNAPNAME", "Snapshot to delete - mandatory option") do |n|
options[:snap_name] = n
end

end

begin

argv = parse_options(opts)
return if !argv
raise OptionParser::MissingArgument if options[:snap_name].nil?

rescue OptionParser::InvalidOption, OptionParser::MissingArgument
puts $!.to_s
puts opts
return false
end

with_target_vms(argv) do |vm|

vm.action(:snapshot_delete, :snap_name => options[:snap_name])

end

0

end

end

end

end
5 changes: 5 additions & 0 deletions lib/vagrant-multiprovider-snap/command/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def initialize(argv, env)
Take
end

@subcommands.register(:delete) do
require_relative "delete"
Delete
end

@subcommands.register(:rollback) do
require_relative "rollback"
Rollback
Expand Down
26 changes: 26 additions & 0 deletions lib/vagrant-multiprovider-snap/providers/virtualbox/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module Action

autoload :SnapshotTake, File.expand_path("../action/snapshot_take.rb", __FILE__)
autoload :SnapshotRollback, File.expand_path("../action/snapshot_rollback.rb", __FILE__)
autoload :SnapshotDelete, File.expand_path("../action/snapshot_delete.rb", __FILE__)
autoload :HasSnapshot, File.expand_path("../action/has_snapshot.rb", __FILE__)
autoload :MessageSnapshotNotCreated, File.expand_path("../action/message_snapshot_not_created.rb", __FILE__)
autoload :MessageSnapshotNotDeleted, File.expand_path("../action/message_snapshot_not_deleted.rb", __FILE__)

def self.action_snapshot_take
Vagrant::Action::Builder.new.tap do |b|
Expand All @@ -25,6 +27,30 @@ def self.action_snapshot_take
end
end

def self.action_snapshot_delete
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVirtualbox
b.use Call, Created do |env, b2|
if env[:result]
b2.use Call, HasSnapshot do |env2, b3|
if env2[:result]
b3.use CheckAccessible
b3.use Call, SnapshotDelete do |env3,b4|
unless env3[:result]
b4.use MessageSnapshotNotDeleted
end
end
else
b3.use MessageSnapshotNotCreated
end
end
else
b2.use MessageNotCreated
end
end
end
end

def self.action_snapshot_rollback
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVirtualbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def initialize(app, env)

def call(env)

env[:result] = env[:machine].provider.driver.has_snapshot?
if env[:snap_name].nil?
env[:snap_name] = env[:machine].provider.driver.snapshot_list.last
end

env[:result] = env[:machine].provider.driver.has_snapshot?(env[:snap_name])

@app.call(env)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def initialize(app, env)

def call(env)

env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_not_created")
if env[:snap_name].nil?
env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_not_created.not_created")
else
env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_not_created.named_not_exist",
:snapshot => env[:snap_name]),
)
end

@app.call(env)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module VagrantPlugins

module ProviderVirtualBox

module Action

class MessageSnapshotNotDeleted

def initialize(app, env)
@app = app
end

def call(env)

env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_not_deleted.not_deleted",
:snapshot => env[:snap_name]),
)

@app.call(env)

end

end

end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module VagrantPlugins

module ProviderVirtualBox

module Action

class SnapshotDelete

def initialize(app, env)
@app = app
end

def call(env)

env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_delete.deleting",
:snapshot => env[:snap_name]),
)

env[:result] = env[:machine].provider.driver.snapshot_delete(env[:snap_name])

@app.call(env)

end

end

end

end

end
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ def initialize(app, env)

def call(env)

env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_rollback.rolling_back")

# Snapshot rollback involves powering off and on the VM
# so we need to find the gui state

boot_mode = env[:machine].provider_config.gui ? "gui" : "headless"

if env[:snap_name].nil?
env[:snap_name] = env[:machine].provider.driver.snapshot_list.last
env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_rollback.rolling_back")
else
env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_rollback.rolling_back_named",
:snapshot => env[:snap_name]),
)
end

env[:machine].provider.driver.snapshot_rollback(boot_mode,env[:snap_name])

@app.call(env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ def initialize(app, env)

def call(env)

env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_take.taking")
if env[:snap_name].nil?
env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_take.taking")
else
env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_take.taking_named",
:snapshot => env[:snap_name]),
)
end

env[:machine].provider.driver.snapshot_take(env[:snap_name])

@app.call(env)
Expand Down
12 changes: 10 additions & 2 deletions lib/vagrant-multiprovider-snap/providers/virtualbox/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def snapshot_take(name)
execute("snapshot", @uuid, "take", name || "vagrant-snap-#{Time.now.to_i}", "--pause")
end

def snapshot_delete(name)
execute("snapshot", @uuid, "delete", name)
end

def snapshot_rollback(bootmode, name)
# don't try to power off if we're already off
unless [:poweroff, :aborted].include?(read_state)
Expand All @@ -31,8 +35,12 @@ def snapshot_list
snapshots
end

def has_snapshot?
snapshot_list.length > 0
def has_snapshot?(name)
if name.nil?
return true unless snapshot_list.empty?
else
return true if snapshot_list.include? "#{name}"
end
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Driver
class Meta

def_delegators :@driver, :snapshot_take,
:snapshot_delete,
:snapshot_rollback,
:snapshot_list,
:has_snapshot?
Expand Down
26 changes: 26 additions & 0 deletions lib/vagrant-multiprovider-snap/providers/vmware_fusion/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module Action

autoload :SnapshotTake, File.expand_path("../action/snapshot_take.rb", __FILE__)
autoload :SnapshotRollback, File.expand_path("../action/snapshot_rollback.rb", __FILE__)
autoload :SnapshotDelete, File.expand_path("../action/snapshot_delete.rb", __FILE__)
autoload :HasSnapshot, File.expand_path("../action/has_snapshot.rb", __FILE__)
autoload :MessageSnapshotNotCreated, File.expand_path("../action/message_snapshot_not_created.rb", __FILE__)
autoload :MessageSnapshotNotDeleted, File.expand_path("../action/message_snapshot_not_deleted.rb", __FILE__)

def self.action_snapshot_take
Vagrant::Action::Builder.new.tap do |b|
Expand All @@ -24,6 +26,29 @@ def self.action_snapshot_take
end
end

def self.action_snapshot_delete
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVMware
b.use Call, Created do |env, b2|
if env[:result]
b2.use Call, HasSnapshot do |env2, b3|
if env2[:result]
b3.use Call, SnapshotDelete do |env3,b4|
unless env3[:result]
b4.use MessageSnapshotNotDeleted
end
end
else
b3.use MessageSnapshotNotCreated
end
end
else
b2.use MessageNotCreated
end
end
end
end

def self.action_snapshot_rollback
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVMware
Expand All @@ -43,6 +68,7 @@ def self.action_snapshot_rollback
end
end
end

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def initialize(app, env)

def call(env)

env[:result] = env[:machine].provider.driver.has_snapshot?
if env[:snap_name].nil?
snap_name = env[:machine].provider.driver.snapshot_list.last
else
snap_name = env[:snap_name]
end

env[:result] = env[:machine].provider.driver.has_snapshot?(snap_name)

@app.call(env)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def initialize(app, env)

def call(env)

env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_not_created")
if env[:snap_name].nil?
env[:ui].info I18n.t("vagrant_snap.actions.vm.snapshot_not_created.not_created")
else
env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_not_created.named_not_exist",
:snapshot => env[:snap_name]),
)
end

@app.call(env)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module HashiCorp

module VagrantVMwarefusion

module Action

class MessageSnapshotNotDeleted

def initialize(app, env)
@app = app
end

def call(env)

env[:ui].info(I18n.t("vagrant_snap.actions.vm.snapshot_not_deleted.not_deleted",
:snapshot => env[:snap_name]),
)

@app.call(env)

end

end

end

end

end
Loading

0 comments on commit aaf6b40

Please sign in to comment.