Skip to content

Commit

Permalink
changes brought up during testing
Browse files Browse the repository at this point in the history
don't create disk if disk file exists, and adjust mkfs to identify disks on ubuntu correctly
  • Loading branch information
madAndroid committed Sep 4, 2013
1 parent 53da4d4 commit e88325e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
24 changes: 15 additions & 9 deletions lib/vagrant-persistent-storage/action/create_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ def call(env)
return @app.call(env) unless env[:machine].config.persistent_storage.enabled?

# check config to see if the disk should be created
return @app.call(env) unless @machine.config.persistent_storage.create?
@logger.info '** Creating Persistent Storage **'

env[:ui].info I18n.t("vagrant_persistent_storage.action.create_storage")
location = env[:machine].config.persistent_storage.location
size = env[:machine].config.persistent_storage.size
env[:machine].provider.driver.create_storage(location, size)

@app.call(env)
return @app.call(env) unless env[:machine].config.persistent_storage.create?

if File.exists?(env[:machine].config.persistent_storage.location)
@logger.info '** Persistent Storage Volume exists, not creating **'
env[:ui].info I18n.t("vagrant_persistent_storage.action.not_creating")
@app.call(env)

else
@logger.info '** Creating Persistent Storage **'
env[:ui].info I18n.t("vagrant_persistent_storage.action.create_storage")
location = env[:machine].config.persistent_storage.location
size = env[:machine].config.persistent_storage.size
env[:machine].provider.driver.create_storage(location, size)
@app.call(env)
end

end

Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-persistent-storage/action/detach_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(app, env)
end

def call(env)
# skip if machine is not running and the action is destroy, halt or suspend
return @app.call(env) if @machine.state.id != :running && [:destroy, :halt, :suspend].include?(env[:machine_action])
# skip if machine is not running and the action is halt or suspend
return @app.call(env) if @machine.state.id != :running && [:halt, :suspend].include?(env[:machine_action])
# skip if machine is not saved and the action is resume
return @app.call(env) if @machine.state.id != :saved && env[:machine_action] == :resume
# skip if machine is not running and the action is suspend
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-persistent-storage/manage_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def populate_template(m)
<% if format == true %>
# Create the filesytem if it doesn't already exist
[[ `blkid | grep #{device}` ]] || mkfs.#{fs_type} #{device}
[[ `blkid | grep #{mnt_name} | grep #{fs_type}` ]] || mkfs.#{fs_type} #{device}
echo "#{fs_type} creation return: $?" >> disk_operation_log.txt
<% if mount == true %>
# Create mountpoint #{mnt_point}
Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant-persistent-storage/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class Plugin < Vagrant.plugin('2')
end

action_hook(:persistent_storage, :machine_action_destroy) do |hook|
hook.prepend(VagrantPlugins::PersistentStorage::Action.detach_storage)
hook.after VagrantPlugins::ProviderVirtualBox::Action::action_halt,
VagrantPlugins::PersistentStorage::Action.detach_storage
hook.before VagrantPlugins::ProviderVirtualBox::Action::Destroy,
VagrantPlugins::PersistentStorage::Action.detach_storage
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ def create_adapter
end

def create_storage(location, size)
if ! File.exists?(location)
execute("createhd", "--filename", location, "--size", size)
end
execute("createhd", "--filename", location, "--size", size)
end

def attach_storage(location)
# if location != 0 and read_persistent_storage(location) == location
execute("storageattach", @uuid, "--storagectl", "SATA Controller", "--port", "1", "--device", "0", "--type", "hdd", "--medium", "#{location}")
# end
end

def detach_storage(location)
Expand Down
1 change: 1 addition & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ en:
action:
create_adapter: "** Creating adapter for persistent storage **"
create_storage: "** Creating persistent storage **"
not_creating: "** Persistent Storage Volume exists, not creating **"
attach_storage: "** Attaching persistent storage **"
detach_storage: "** Detaching persistent storage **"
manage_storage: "** Managing persistent storage **"
Expand Down

0 comments on commit e88325e

Please sign in to comment.