vagrant-persistent-storage 0.0.44 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c0c150ceb7eaff53a28ae1acf561970b5a35ec75
4
- data.tar.gz: 111e5f2f5ef40a711a31f8d40d93d349d7eaa9c4
2
+ SHA256:
3
+ metadata.gz: 6c747645f753d9dcc3692e127df6c78c5b05cfc037853adcb39bf45d3c6d0376
4
+ data.tar.gz: df800f9b0f6c6a16fd8be1838a3c767e350af8c83f7744570b4177baa413836d
5
5
  SHA512:
6
- metadata.gz: 52fd811411ae2e8b0b23949c1f2b8ffe2c572ba7ab2575ffb3cb95d0f945250ac24eed14f3de5ea4d3c6c6b8806239f763eb99d2a1b109b1436aaa1e495a7ea1
7
- data.tar.gz: eea95b5979d7a0f8453c985400b6de4a06dc7cc544476b5deb6d1f465fd17f142b33bf7354abfb31bcc8cb52376a4bd587009b6dd296f4ef689d59a7f68ffcf6
6
+ metadata.gz: 2e1324f22d8ba5bbf67c30ae7b526fd7602db17bf2abed14443f82087739d2715802eb86593a9a07b0d267c794d4fa99cd764f4eede20340451a7f9165f525da
7
+ data.tar.gz: 1679290b6c4993d87df4064f41908032d5bf8da4a0d10a3545293cdd1231398b41e950015ba71d318831fa6838894b715d9d28d9c70339d75b088675fb16e65d
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Vagrant plugin that creates a persistent storage and attaches it to guest machine.
4
4
 
5
- Requires Virtualbox 5
5
+ Requires Virtualbox 5/6
6
6
 
7
7
  ## Installation
8
8
 
@@ -24,7 +24,7 @@ config.persistent_storage.mountpoint = '/var/lib/mysql'
24
24
  config.persistent_storage.volgroupname = 'myvolgroup'
25
25
  ```
26
26
 
27
- With `config.persistent_storage.mountoptions` you can change the mount options (default: defaults).
27
+ With `config.persistent_storage.mountoptions` you can change the mount options (default: defaults).
28
28
  An example which sets `prjquota` option with xfs.
29
29
  ```ruby
30
30
  config.persistent_storage.mountname = 'xfs'
@@ -48,17 +48,26 @@ When you expect a lot of writes in the disk (the case for `/home` mountpoints) i
48
48
  config.persistent_storage.variant = 'Fixed'
49
49
  ```
50
50
 
51
+ If you want to pass a list of options to the underlying `VboxManage
52
+ storageattach` call, you can use the `config.persistent_storage.attachoptions`
53
+ option. For instance, if you want to enable TRIM support:
54
+
55
+ ```ruby
56
+ config.persistent_storage.mountoptions = ['defaults', 'discard']
57
+ config.persistent_storage.attachoptions = ['--discard', 'on']
58
+ ```
59
+
51
60
  Every `vagrant up` will attach this file as hard disk to the guest machine.
52
61
  A `vagrant destroy` will detach the storage to avoid deletion of the storage by vagrant.
53
62
  A `vagrant destroy` generally destroys all attached drives. See [VBoxManage unregistervm --delete option][vboxmanage_delete].
54
63
 
55
- The disk is initialized and added to it's own volume group as specfied in the config;
64
+ The disk is initialized and added to it's own volume group as specfied in the config;
56
65
  this defaults to 'vagrant'. An ext4 filesystem is created and the disk mounted appropriately,
57
66
  with entries added to fstab ... subsequent runs will mount this disk with the options specified.
58
67
 
59
68
  ## Windows Guests
60
69
 
61
- Windows Guests must use the WinRM communicator by setting `vm.communicator = 'winrm'`. An additional option is provided to
70
+ Windows Guests must use the WinRM communicator by setting `vm.communicator = 'winrm'`. An additional option is provided to
62
71
  allow you to set the drive letter using:
63
72
 
64
73
  ```ruby
@@ -69,7 +78,7 @@ Options that are irrelevent to Windows are ignored, such as `mountname`, `filesy
69
78
 
70
79
  ## How Is The Storage Created?
71
80
 
72
- Based on the configuration provided, during a `vagrant up` a bash script is generated and uploaded to `/tmp/disk_operations_#{mnt_name}.sh` (Linux) or `disk_operations_#{mnt_name}.ps1` (Windows). If the box has not been previously provisioned the script is executed on a `vagrant up`. To force the script to be executed again you can run `vagrant provision` or if you have halted the box, `vagrant up --provision`.
81
+ Based on the configuration provided, during a `vagrant up` a bash script is generated and uploaded to `$tmpdir/disk_operations_#{mnt_name}.sh` (Linux) or `disk_operations_#{mnt_name}.ps1` (Windows). If the box has not been previously provisioned the script is executed on a `vagrant up`. To force the script to be executed again you can run `vagrant provision` or if you have halted the box, `vagrant up --provision`.
73
82
 
74
83
  The outcome of the script being run is placed in the home drive of the vagrant user in a file called `disk_operation_log.txt`.
75
84
 
@@ -113,6 +122,9 @@ If your box is not using LVM you must set `config.persistent_storage.use_lvm = f
113
122
  * [Adam Huffman](https://github.com/verdurin)
114
123
  * [caio2k](https://github.com/caio2k)
115
124
  * [Francesco](https://github.com/cisco87)
125
+ * [Dimitris Aragiorgis](https://github.com/dimara)
126
+ * [Symaxion](https://github.com/Symaxion)
127
+ * [Alex Pyrgiotis](https://github.com/apyrgio)
116
128
 
117
129
  ## TODO
118
130
 
@@ -24,7 +24,8 @@ module VagrantPlugins
24
24
 
25
25
  env[:ui].info I18n.t("vagrant_persistent_storage.action.attach_storage")
26
26
  location = env[:machine].config.persistent_storage.location
27
- env[:machine].provider.driver.attach_storage(location)
27
+ attachoptions = env[:machine].config.persistent_storage.attachoptions
28
+ env[:machine].provider.driver.attach_storage(location, attachoptions)
28
29
 
29
30
  @app.call(env)
30
31
 
@@ -1,3 +1,4 @@
1
+ require 'log4r'
1
2
  require 'pathname'
2
3
 
3
4
  module VagrantPlugins
@@ -16,6 +17,7 @@ module VagrantPlugins
16
17
  attr_accessor :mountname
17
18
  attr_accessor :mountpoint
18
19
  attr_accessor :mountoptions
20
+ attr_accessor :attachoptions
19
21
  attr_accessor :partition
20
22
  attr_accessor :diskdevice
21
23
  attr_accessor :filesystem
@@ -45,11 +47,13 @@ module VagrantPlugins
45
47
  @mountname = UNSET_VALUE
46
48
  @mountpoint = UNSET_VALUE
47
49
  @mountoptions = UNSET_VALUE
50
+ @attachoptions = UNSET_VALUE
48
51
  @diskdevice = UNSET_VALUE
49
52
  @filesystem = UNSET_VALUE
50
53
  @volgroupname = UNSET_VALUE
51
54
  @drive_letter = UNSET_VALUE
52
55
  @part_type_code = UNSET_VALUE
56
+ @logger = Log4r::Logger.new('vagrant::persistent_storage::config')
53
57
  end
54
58
 
55
59
  def finalize!
@@ -66,6 +70,7 @@ module VagrantPlugins
66
70
  @mountname = "" if @mountname == UNSET_VALUE
67
71
  @mountpoint = "" if @mountpoint == UNSET_VALUE
68
72
  @mountoptions = [] if @mountoptions == UNSET_VALUE
73
+ @attachoptions = [] if @attachoptions == UNSET_VALUE
69
74
  @diskdevice = "" if @diskdevice == UNSET_VALUE
70
75
  @filesystem = "" if @filesystem == UNSET_VALUE
71
76
  @volgroupname = "" if @volgroupname == UNSET_VALUE
@@ -150,6 +155,17 @@ module VagrantPlugins
150
155
  })
151
156
  end
152
157
 
158
+ if ! Pathname.new(machine.config.persistent_storage.location).absolute?
159
+ # Non-absolute paths are relative to machine's root directory (where
160
+ # Vagrantfile is placed). Paths under HOME, e.g., ~/disk.vdi), are
161
+ # expanded as expected.
162
+ new_location = File.expand_path(machine.config.persistent_storage.location, machine.env.root_path)
163
+ @logger.info "Found non-absolute location #{machine.config.persistent_storage.location}. Using location #{new_location} instead."
164
+ machine.config.persistent_storage.location = new_location
165
+ end
166
+
167
+ machine.ui.info "Using #{machine.config.persistent_storage.location} for persistent storage."
168
+
153
169
  if ! File.exists?@location.to_s and ! @create == "true"
154
170
  errors << I18n.t('vagrant_persistent_storage.config.no_create_and_missing', {
155
171
  :config_key => 'persistent_storage.create',
@@ -5,6 +5,12 @@ require 'erb'
5
5
  module VagrantPlugins
6
6
  module PersistentStorage
7
7
  module ManageStorage
8
+ def get_tmp_dir(m)
9
+ m.communicate.sudo('dirname $(mktemp -u)', :error_check => false) do |type, data|
10
+ tmpdir = data.to_s.strip
11
+ return tmpdir
12
+ end
13
+ end
8
14
  def populate_template(m)
9
15
  mnt_name = m.config.persistent_storage.mountname
10
16
  mnt_point = m.config.persistent_storage.mountpoint
@@ -60,7 +66,7 @@ module VagrantPlugins
60
66
  else
61
67
  ## shell script to format disk, create/manage LVM, mount disk
62
68
  disk_operations_template = ERB.new <<-EOF
63
- #!/bin/bash
69
+ #!/usr/bin/env bash
64
70
  DISK_DEV=#{disk_dev}
65
71
  <% if partition == true %>
66
72
  # fdisk the disk if it's not a block device already:
@@ -115,7 +121,8 @@ exit $?
115
121
  if os == 'windows'
116
122
  target_script = "disk_operations_#{mnt_name}.ps1"
117
123
  else
118
- target_script = "/tmp/disk_operations_#{mnt_name}.sh"
124
+ tmpdir = get_tmp_dir(m)
125
+ target_script = tmpdir + "/disk_operations_#{mnt_name}.sh"
119
126
  end
120
127
 
121
128
  File.open("#{tmp_script.path}", 'wb') do |f|
@@ -135,7 +142,8 @@ exit $?
135
142
  target_script = "disk_operations_#{mnt_name}.ps1"
136
143
  m.communicate.sudo("powershell -executionpolicy bypass -file #{target_script}")
137
144
  else
138
- target_script = "/tmp/disk_operations_#{mnt_name}.sh"
145
+ tmpdir = get_tmp_dir(m)
146
+ target_script = tmpdir + "/disk_operations_#{mnt_name}.sh"
139
147
  m.communicate.sudo("#{target_script}")
140
148
  end
141
149
 
@@ -147,7 +155,6 @@ exit $?
147
155
  run_disk_operations(m)
148
156
  end
149
157
  end
150
-
151
158
  end
152
159
  end
153
160
  end
@@ -15,7 +15,7 @@ module VagrantPlugins
15
15
  execute("storagectl", @uuid, "--name", controller_name, "--" + (self.remove_prefix(@version) ? "" : "sata") + "portcount", "2")
16
16
  end
17
17
  end
18
-
18
+
19
19
  def remove_prefix(vbox_version)
20
20
  return vbox_version.start_with?("4.3") || vbox_version.start_with?("5.") || vbox_version.start_with?("6.")
21
21
  end
@@ -24,7 +24,7 @@ module VagrantPlugins
24
24
  execute("createhd", "--filename", File.expand_path(location), "--size", "#{size}", "--variant", "#{variant}")
25
25
  end
26
26
 
27
- def attach_storage(location)
27
+ def attach_storage(location, attachoptions)
28
28
  controller_name = get_controller_name
29
29
  if controller_name.nil?
30
30
  controller_name = "SATA Controller"
@@ -32,15 +32,15 @@ module VagrantPlugins
32
32
 
33
33
  location_realpath = File.expand_path(location)
34
34
 
35
+ base_cmd = ["storageattach", @uuid, "--storagectl", get_controller_name, "--type", "hdd", "--medium", "#{location_realpath}"]
35
36
  if controller_name.start_with?("IDE")
36
- execute("storageattach", @uuid, "--storagectl", get_controller_name, "--port", "1", "--device", "0", "--type", "hdd", "--medium", "#{location_realpath}")
37
+ ctrl_args = ["--port", "1", "--device", "0"]
37
38
  elsif controller_name.start_with?("SCSI")
38
- execute("storageattach", @uuid, "--storagectl", get_controller_name, "--port", "15", "--device", "0", "--type", "hdd", "--medium", "#{location_realpath}")
39
+ ctrl_args = ["--port", "15", "--device", "0"]
39
40
  else
40
- execute("storageattach", @uuid, "--storagectl", get_controller_name, "--port", "4", "--device", "0", "--type", "hdd", "--medium", "#{location_realpath}", "--hotpluggable", "on")
41
+ ctrl_args = ["--port", "4", "--device", "0", "--hotpluggable", "on"]
41
42
  end
42
-
43
-
43
+ execute(*(base_cmd + ctrl_args + attachoptions))
44
44
  end
45
45
 
46
46
  def detach_storage(location)
@@ -48,6 +48,7 @@ module VagrantPlugins
48
48
  persistent_storage_data = read_persistent_storage(location_realpath)
49
49
  if location and persistent_storage_data and identical_files(persistent_storage_data.location, location_realpath)
50
50
  execute("storageattach", @uuid, "--storagectl", persistent_storage_data.controller, "--port", persistent_storage_data.port, "--device", "0", "--type", "hdd", "--medium", "none")
51
+ execute("closemedium", "disk", persistent_storage_data.image)
51
52
  end
52
53
  end
53
54
 
@@ -57,13 +58,27 @@ module VagrantPlugins
57
58
  storage_data = nil
58
59
  controller_name = get_controller_name
59
60
  info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
61
+ # Parse the following two lines matching the controller name:
62
+ # "SATA Controller-4-0"="/data/my-persistent-disk.vdi"
63
+ # "SATA Controller-ImageUUID-4-0"="1b5c4a17-3f84-49ba-b394-bfc609f30283"
64
+ # The first reports the underlying file, while the second reports the
65
+ # UUID of the VirtualBox medium.
60
66
  info.split("\n").each do |line|
61
67
  tmp_storage_data = nil
62
- tmp_storage_data = PersistentStorageData.new(controller_name, $1, $3) if line =~ /^"#{controller_name}-(\d+)-(\d+)"="(.*)"/
68
+ tmp_storage_data = PersistentStorageData.new(controller_name, $1, $3, nil) if line =~ /^"#{controller_name}-(\d+)-(\d+)"="(.*)"/
69
+
70
+ tmp_storage_data_image = nil
71
+ tmp_storage_data_image = $3 if line =~ /^"#{controller_name}-ImageUUID-(\d+)-(\d+)"="(.*)"/
63
72
 
64
73
  if !tmp_storage_data.nil? and tmp_storage_data.location != 'none' and identical_files(File.expand_path(location), tmp_storage_data.location)
65
74
  storage_data = tmp_storage_data
66
75
  end
76
+
77
+ # XXX: The ImageUUID line comes second and thus we have already
78
+ # storage_data initialized.
79
+ if !storage_data.nil? and !tmp_storage_data_image.nil?
80
+ storage_data.image = tmp_storage_data_image
81
+ end
67
82
  end
68
83
  return storage_data
69
84
  end
@@ -93,11 +108,13 @@ module VagrantPlugins
93
108
  attr_accessor :controller
94
109
  attr_accessor :port
95
110
  attr_accessor :location
111
+ attr_accessor :image
96
112
 
97
- def initialize(controller,port,location)
113
+ def initialize(controller,port,location,image)
98
114
  @controller = controller
99
115
  @port = port
100
116
  @location = location
117
+ @image = image
101
118
  end
102
119
  end
103
120
 
@@ -105,4 +122,3 @@ module VagrantPlugins
105
122
  end
106
123
  end
107
124
  end
108
-
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module PersistentStorage
3
- VERSION = "0.0.44"
3
+ VERSION = "0.0.49"
4
4
  end
5
5
  end
data/test.sh CHANGED
@@ -31,8 +31,8 @@ do
31
31
  else
32
32
  echo ...[FAILED]
33
33
  fi
34
- VAGRANT_VAGRANTFILE="$f" vagrant destroy -f --no-color >> $f.log && "$VBOXMANAGE" closemedium disk virtualdrive.vdi --delete >> $f.log 2>&1
34
+ VAGRANT_VAGRANTFILE="$f" vagrant destroy -f --no-color >> $f.log && rm -fv virtualdrive.vdi >> $f.log 2>&1
35
35
  done
36
36
 
37
37
 
38
- popd > /dev/null
38
+ popd > /dev/null
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-persistent-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Kusnier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.5.2.3
95
+ rubygems_version: 3.0.3
97
96
  signing_key:
98
97
  specification_version: 4
99
98
  summary: A Vagrant plugin that creates a persistent storage and attaches it to guest