-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from Sharpie/add-snapshot-support
Add snapshot support
- Loading branch information
Showing
12 changed files
with
364 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
source/lib/vagrant-openstack-provider/action/snapshot_cleanup.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotCleanup < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
machine_snapshots = nova.list_snapshots(env, env[:machine].id) | ||
|
||
snapshots_to_clean = machine_snapshots.select do |s| | ||
s.metadata.key?('vagrant_snapshot') | ||
end | ||
|
||
@app.call env | ||
|
||
unless snapshots_to_clean.empty? | ||
env[:ui].info("Deleting Vagrant snapshots: #{snapshots_to_clean.map(&:name)}") | ||
end | ||
|
||
snapshots_to_clean.each do |s| | ||
nova.delete_snapshot(env, s.id) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
source/lib/vagrant-openstack-provider/action/snapshot_delete.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotDelete < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
machine_snapshots = nova.list_snapshots(env, env[:machine].id) | ||
|
||
snapshot = machine_snapshots.find { |s| s.name == env[:snapshot_name] } | ||
|
||
unless snapshot.nil? | ||
env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.deleting', | ||
name: snapshot.name)) | ||
|
||
nova.delete_snapshot(env, snapshot.id) | ||
|
||
env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.deleted', | ||
name: snapshot.name)) | ||
end | ||
|
||
@app.call env | ||
end | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
source/lib/vagrant-openstack-provider/action/snapshot_list.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotList < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
machine_snapshots = nova.list_snapshots(env, env[:machine].id) | ||
|
||
env[:machine_snapshot_list] = machine_snapshots.map(&:name) | ||
|
||
@app.call env | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
source/lib/vagrant-openstack-provider/action/snapshot_restore.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotRestore < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
machine_snapshots = nova.list_snapshots(env, env[:machine].id) | ||
|
||
snapshot = machine_snapshots.find { |s| s.name == env[:snapshot_name] } | ||
|
||
unless snapshot.nil? | ||
env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.restoring', | ||
name: snapshot.name)) | ||
|
||
nova.restore_snapshot(env, env[:machine].id, snapshot.id) | ||
end | ||
|
||
@app.call env | ||
end | ||
end | ||
end | ||
end | ||
end |
51 changes: 51 additions & 0 deletions
51
source/lib/vagrant-openstack-provider/action/snapshot_save.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotSave < AbstractAction | ||
def initialize(app, _env, retry_interval = 3) | ||
@app = app | ||
@retry_interval = retry_interval | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
config = env[:machine].provider_config | ||
|
||
env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.saving', | ||
name: env[:snapshot_name])) | ||
|
||
nova.create_snapshot( | ||
env, | ||
env[:machine].id, env[:snapshot_name]) | ||
|
||
image = nova.list_snapshots(env, env[:machine].id).find { |i| i.name == env[:snapshot_name] } | ||
|
||
timeout(config.server_create_timeout, Errors::Timeout) do | ||
loop do | ||
image_status = nova.get_image_details(env, image.id) | ||
|
||
break if image_status['status'] == 'ACTIVE' | ||
|
||
unless image_status['progress'].nil? | ||
env[:ui].clear_line | ||
env[:ui].report_progress(image_status['progress'], 100, false) | ||
end | ||
|
||
sleep @retry_interval | ||
end | ||
end | ||
|
||
# Clear progress output. | ||
env[:ui].clear_line | ||
|
||
env[:ui].success(I18n.t('vagrant.actions.vm.snapshot.saved', | ||
name: env[:snapshot_name])) | ||
|
||
@app.call env | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
source/lib/vagrant-openstack-provider/cap/snapshot_list.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module VagrantPlugins | ||
module Openstack | ||
module Cap | ||
module SnapshotList | ||
# Returns a list of the snapshots that are taken on this machine. | ||
# | ||
# @return [Array<String>] | ||
def self.snapshot_list(machine) | ||
env = machine.action(:snapshot_list, lock: false) | ||
env[:machine_snapshot_list] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.