vagrant-persistent-storage 0.0.32 → 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/lib/vagrant-persistent-storage/config.rb +33 -20
- data/lib/vagrant-persistent-storage/manage_storage.rb +23 -16
- data/lib/vagrant-persistent-storage/version.rb +1 -1
- data/locales/en.yml +5 -1
- data/sample-vm/partition-false.vagrantfile +30 -0
- data/sample-vm/{Vagrantfile → partition-true.vagrantfile} +5 -1
- data/test.sh +38 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222ed37d94891036c944eb103454e251d8177ddf
|
4
|
+
data.tar.gz: 654612cbe9800c44d7f630df4892719c40e86063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d727bada13e754b4b6ace84eb03f67a5eff977543dc0e139df8e8c2d56e28a34f88e13810819e9e9a907ba95ccf2b351f6ce81d3bfb58c69e1973d11383b444d
|
7
|
+
data.tar.gz: 336ae22a9c30aca631baf233c02b6aee658d83ae8a11b725f3b7071d51cc29008e6a74f77d7967fa716679c109be32e0a927986c23fa567be11fcfb1b37f8612
|
data/README.md
CHANGED
@@ -34,29 +34,40 @@ config.persistent_storage.mountoptions = ['defaults', 'prjquota']
|
|
34
34
|
```
|
35
35
|
|
36
36
|
Device defaults to `/dev/sdb`. For boxes with multiple disks, make sure you increment the drive:
|
37
|
-
```
|
37
|
+
```ruby
|
38
38
|
config.persistent_storage.diskdevice = '/dev/sdc'
|
39
39
|
```
|
40
40
|
|
41
|
+
If you are using LVM and you would prefer to use the disk rather than a partition, you can set the following configuration:
|
42
|
+
```ruby
|
43
|
+
config.persistent_storage.partition = false
|
44
|
+
```
|
45
|
+
|
41
46
|
Every `vagrant up` will attach this file as hard disk to the guest machine.
|
42
|
-
|
47
|
+
A `vagrant destroy` will detach the storage to avoid deletion of the storage by vagrant.
|
43
48
|
A `vagrant destroy` generally destroys all attached drives. See [VBoxMange unregistervm --delete option][vboxmanage_delete].
|
44
49
|
|
45
50
|
The disk is initialized and added to it's own volume group as specfied in the config;
|
46
51
|
this defaults to 'vagrant'. An ext4 filesystem is created and the disk mounted appropriately,
|
47
|
-
with entries added to fstab ... subsequent runs will mount this disk with the options specified
|
52
|
+
with entries added to fstab ... subsequent runs will mount this disk with the options specified.
|
48
53
|
|
49
54
|
## Windows Guests
|
50
55
|
|
51
56
|
Windows Guests must use the WinRM communicator by setting `vm.communicator = 'winrm'`. An additional option is provided to
|
52
57
|
allow you to set the drive letter using:
|
53
58
|
|
54
|
-
```
|
59
|
+
```ruby
|
55
60
|
config.persistent_storage.drive_letter = 'Z'
|
56
61
|
```
|
57
62
|
|
58
63
|
Options that are irrelevent to Windows are ignored, such as `mountname`, `filesystem`, `mountpoint` and `volgroupname`.
|
59
64
|
|
65
|
+
## How Is The Storage Created?
|
66
|
+
|
67
|
+
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 scrip to be executed again you can run `vagrant provision` or if you have halted the box, `vagrant up --provision`.
|
68
|
+
|
69
|
+
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`.
|
70
|
+
|
60
71
|
## Optional settings
|
61
72
|
|
62
73
|
```ruby
|
@@ -90,6 +101,7 @@ If your box are not using LVM you must set `config.persistent_storage.use_lvm =
|
|
90
101
|
* [Henry N.](https://github.com/HenryNe)
|
91
102
|
* [fredleger](https://github.com/fredleger)
|
92
103
|
* [Sebastian Wendel](https://github.com/sourceindex)
|
104
|
+
* [Ben Phegan](https://github.com/BenPhegan)
|
93
105
|
|
94
106
|
## TODO
|
95
107
|
|
@@ -15,6 +15,7 @@ module VagrantPlugins
|
|
15
15
|
attr_accessor :mountname
|
16
16
|
attr_accessor :mountpoint
|
17
17
|
attr_accessor :mountoptions
|
18
|
+
attr_accessor :partition
|
18
19
|
attr_accessor :diskdevice
|
19
20
|
attr_accessor :filesystem
|
20
21
|
attr_accessor :volgroupname
|
@@ -26,6 +27,7 @@ module VagrantPlugins
|
|
26
27
|
alias_method :manage?, :manage
|
27
28
|
alias_method :format?, :format
|
28
29
|
alias_method :use_lvm?, :use_lvm
|
30
|
+
alias_method :partition?, :partition
|
29
31
|
alias_method :enabled?, :enabled
|
30
32
|
|
31
33
|
def initialize
|
@@ -36,6 +38,7 @@ module VagrantPlugins
|
|
36
38
|
@format = true
|
37
39
|
@use_lvm = true
|
38
40
|
@enabled = false
|
41
|
+
@partition = true
|
39
42
|
@location = UNSET_VALUE
|
40
43
|
@mountname = UNSET_VALUE
|
41
44
|
@mountpoint = UNSET_VALUE
|
@@ -54,31 +57,33 @@ module VagrantPlugins
|
|
54
57
|
@manage = true if @manage == UNSET_VALUE
|
55
58
|
@format = true if @format == UNSET_VALUE
|
56
59
|
@use_lvm = true if @use_lvm == UNSET_VALUE
|
60
|
+
@partition = true if @partition == UNSET_VALUE
|
57
61
|
@enabled = false if @enabled == UNSET_VALUE
|
58
|
-
@location =
|
59
|
-
@mountname =
|
60
|
-
@mountpoint =
|
61
|
-
@mountoptions =
|
62
|
-
@diskdevice =
|
63
|
-
@filesystem =
|
64
|
-
@volgroupname =
|
65
|
-
|
62
|
+
@location = "" if @location == UNSET_VALUE
|
63
|
+
@mountname = "" if @mountname == UNSET_VALUE
|
64
|
+
@mountpoint = "" if @mountpoint == UNSET_VALUE
|
65
|
+
@mountoptions = [] if @mountoptions == UNSET_VALUE
|
66
|
+
@diskdevice = "" if @diskdevice == UNSET_VALUE
|
67
|
+
@filesystem = "" if @filesystem == UNSET_VALUE
|
68
|
+
@volgroupname = "" if @volgroupname == UNSET_VALUE
|
69
|
+
@drive_letter = 0 if @drive_letter == UNSET_VALUE
|
66
70
|
@part_type_code = "8e" if @part_type_code == UNSET_VALUE
|
67
71
|
end
|
68
72
|
|
69
73
|
def validate(machine)
|
70
|
-
errors =
|
74
|
+
errors = _detected_errors
|
71
75
|
|
72
76
|
errors << validate_bool('persistent_storage.create', @create)
|
73
77
|
errors << validate_bool('persistent_storage.mount', @mount)
|
74
|
-
errors << validate_bool('persistent_storage.
|
75
|
-
errors << validate_bool('persistent_storage.
|
76
|
-
errors << validate_bool('persistent_storage.
|
77
|
-
errors << validate_bool('persistent_storage.
|
78
|
+
errors << validate_bool('persistent_storage.manage', @manage)
|
79
|
+
errors << validate_bool('persistent_storage.format', @format)
|
80
|
+
errors << validate_bool('persistent_storage.use_lvm', @use_lvm)
|
81
|
+
errors << validate_bool('persistent_storage.enabled', @enabled)
|
82
|
+
errors << validate_bool('persistent_storage.partition', @partition)
|
78
83
|
errors.compact!
|
79
84
|
|
80
|
-
if !machine.config.persistent_storage.size.kind_of?(
|
81
|
-
errors << I18n.t('vagrant_persistent_storage.config.
|
85
|
+
if !machine.config.persistent_storage.size.kind_of?(Fixnum)
|
86
|
+
errors << I18n.t('vagrant_persistent_storage.config.not_a_number', {
|
82
87
|
:config_key => 'persistent_storage.size',
|
83
88
|
:is_class => size.class.to_s,
|
84
89
|
})
|
@@ -113,6 +118,12 @@ module VagrantPlugins
|
|
113
118
|
:is_class => filesystem.class.to_s,
|
114
119
|
})
|
115
120
|
end
|
121
|
+
if !machine.config.persistent_storage.part_type_code.kind_of?(String)
|
122
|
+
errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
|
123
|
+
:config_key => 'persistent_storage.part_type_code',
|
124
|
+
:is_class => volgroupname.class.to_s,
|
125
|
+
})
|
126
|
+
end
|
116
127
|
if !machine.config.persistent_storage.volgroupname.kind_of?(String)
|
117
128
|
errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
|
118
129
|
:config_key => 'persistent_storage.volgroupname',
|
@@ -121,19 +132,21 @@ module VagrantPlugins
|
|
121
132
|
end
|
122
133
|
|
123
134
|
mount_point_path = Pathname.new("#{machine.config.persistent_storage.location}")
|
124
|
-
if ! mount_point_path.absolute?
|
135
|
+
if ! (mount_point_path.absolute? || mount_point_path.relative?)
|
125
136
|
errors << I18n.t('vagrant_persistent_storage.config.not_a_path', {
|
126
137
|
:config_key => 'persistent_storage.location',
|
127
138
|
:is_path => location.class.to_s,
|
128
139
|
})
|
129
140
|
end
|
130
141
|
|
131
|
-
{ 'Persistent Storage configuration' => errors }
|
132
|
-
|
133
142
|
if ! File.exists?@location.to_s and ! @create == "true"
|
134
|
-
|
143
|
+
errors << I18n.t('vagrant_persistent_storage.config.no_create_and_missing', {
|
144
|
+
:config_key => 'persistent_storage.create',
|
145
|
+
:is_path => location.class.to_s,
|
146
|
+
})
|
135
147
|
end
|
136
|
-
|
148
|
+
|
149
|
+
{ 'Persistent Storage configuration' => errors }
|
137
150
|
end
|
138
151
|
|
139
152
|
private
|
@@ -14,9 +14,10 @@ module VagrantPlugins
|
|
14
14
|
fs_type = m.config.persistent_storage.filesystem
|
15
15
|
manage = m.config.persistent_storage.manage
|
16
16
|
use_lvm = m.config.persistent_storage.use_lvm
|
17
|
+
partition = m.config.persistent_storage.partition
|
17
18
|
mount = m.config.persistent_storage.mount
|
18
19
|
format = m.config.persistent_storage.format
|
19
|
-
|
20
|
+
part_type_code = m.config.persistent_storage.part_type_code
|
20
21
|
|
21
22
|
## windows filesystem options
|
22
23
|
drive_letter = m.config.persistent_storage.drive_letter
|
@@ -27,16 +28,16 @@ module VagrantPlugins
|
|
27
28
|
os = "linux"
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
vg_name = 'vps' unless vg_name != ""
|
32
|
+
disk_dev = '/dev/sdb' unless disk_dev != ""
|
33
|
+
mnt_name = 'vps' unless mnt_name != ""
|
34
|
+
mnt_options = ['defaults'] unless mnt_options.any?
|
35
|
+
fs_type = 'ext3' unless fs_type != ""
|
36
|
+
if use_lvm
|
37
|
+
device = "/dev/#{vg_name}/#{mnt_name}"
|
38
|
+
else
|
39
|
+
device = "#{disk_dev}1"
|
40
|
+
end
|
40
41
|
if drive_letter == 0
|
41
42
|
drive_letter = ""
|
42
43
|
else
|
@@ -46,6 +47,7 @@ module VagrantPlugins
|
|
46
47
|
if os == "windows"
|
47
48
|
## shell script for windows to create NTFS partition and assign drive letter
|
48
49
|
disk_operations_template = ERB.new <<-EOF
|
50
|
+
<% if partition == true %>
|
49
51
|
<% if format == true %>
|
50
52
|
foreach ($disk in get-wmiobject Win32_DiskDrive -Filter "Partitions = 0"){
|
51
53
|
$disk.DeviceID
|
@@ -53,26 +55,31 @@ module VagrantPlugins
|
|
53
55
|
"select disk "+$disk.Index+"`r clean`r create partition primary`r format fs=ntfs unit=65536 quick`r active`r assign #{drive_letter}" | diskpart >> disk_operation_log.txt
|
54
56
|
}
|
55
57
|
<% end %>
|
58
|
+
<% end %>
|
56
59
|
EOF
|
57
60
|
else
|
58
61
|
## shell script to format disk, create/manage LVM, mount disk
|
59
62
|
disk_operations_template = ERB.new <<-EOF
|
60
63
|
#!/bin/bash
|
64
|
+
DISK_DEV=#{disk_dev}
|
65
|
+
<% if partition == true %>
|
61
66
|
# fdisk the disk if it's not a block device already:
|
62
67
|
re='[0-9][.][0-9.]*[0-9.]*'; [[ $(sfdisk --version) =~ $re ]] && version="${BASH_REMATCH}"
|
63
68
|
if ! awk -v ver="$version" 'BEGIN { if (ver < 2.26 ) exit 1; }'; then
|
64
|
-
[ -b
|
69
|
+
[ -b ${DISK_DEV}1 ] || echo 0,,#{part_type_code} | sfdisk $DISK_DEV
|
65
70
|
else
|
66
|
-
[ -b
|
71
|
+
[ -b ${DISK_DEV}1 ] || echo ,,#{part_type_code} | sfdisk $DISK_DEV
|
67
72
|
fi
|
68
73
|
echo "fdisk returned: $?" >> disk_operation_log.txt
|
74
|
+
DISK_DEV=${DISK_DEV}1
|
75
|
+
<% end %>
|
69
76
|
|
70
77
|
<% if use_lvm == true %>
|
71
78
|
# Create the physical volume if it doesn't already exist:
|
72
|
-
[[ `pvs
|
79
|
+
[[ `pvs $DISK_DEV` ]] || pvcreate $DISK_DEV
|
73
80
|
echo "pvcreate returned: $?" >> disk_operation_log.txt
|
74
81
|
# Create the volume group if it doesn't already exist:
|
75
|
-
[[ `vgs #{vg_name}` ]] || vgcreate #{vg_name}
|
82
|
+
[[ `vgs #{vg_name}` ]] || vgcreate #{vg_name} $DISK_DEV
|
76
83
|
echo "vgcreate returned: $?" >> disk_operation_log.txt
|
77
84
|
# Create the logical volume if it doesn't already exist:
|
78
85
|
[[ `lvs #{vg_name} | grep #{mnt_name}` ]] || lvcreate -l 100%FREE -n #{mnt_name} #{vg_name}
|
@@ -84,7 +91,7 @@ echo "vg activation returned: $?" >> disk_operation_log.txt
|
|
84
91
|
|
85
92
|
<% if format == true %>
|
86
93
|
# Create the filesytem if it doesn't already exist
|
87
|
-
MNT_NAME=#{mnt_name}
|
94
|
+
MNT_NAME=#{vg_name}-#{mnt_name}
|
88
95
|
[[ `blkid | grep ${MNT_NAME:0:16} | grep #{fs_type}` ]] || mkfs.#{fs_type} -L #{mnt_name} #{device}
|
89
96
|
echo "#{fs_type} creation return: $?" >> disk_operation_log.txt
|
90
97
|
<% if mount == true %>
|
data/locales/en.yml
CHANGED
@@ -9,4 +9,8 @@ en:
|
|
9
9
|
manage_storage: "** Managing persistent storage **"
|
10
10
|
config:
|
11
11
|
not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
|
12
|
-
not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{
|
12
|
+
not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{value}'"
|
13
|
+
not_a_string: "A value for %{config_key} must be a String, not type '%{value}'"
|
14
|
+
not_a_path: "A value for %{config_key} must be resolveable as a path"
|
15
|
+
not_a_number: "A value for %{config_key} must be a number, not type '%{value}'"
|
16
|
+
no_create_and_missing: "File doesn't exist, and create set to false"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
|
9
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
10
|
+
config.vm.box = "precise32"
|
11
|
+
|
12
|
+
# The url from where the 'config.vm.box' box will be fetched if it
|
13
|
+
# doesn't already exist on the user's system.
|
14
|
+
#config.vm.box_url = "http://files.vagrantup.com/precise32.box"
|
15
|
+
|
16
|
+
# configure a persistent storage for mysql data
|
17
|
+
config.persistent_storage.enabled = true
|
18
|
+
config.persistent_storage.location = "virtualdrive.vdi"
|
19
|
+
config.persistent_storage.size = 5000
|
20
|
+
config.persistent_storage.mountname = 'mysql'
|
21
|
+
config.persistent_storage.filesystem = 'ext4'
|
22
|
+
config.persistent_storage.mountpoint = '/var/lib/mysql'
|
23
|
+
config.persistent_storage.volgroupname = 'myvolgroup'
|
24
|
+
config.persistent_storage.partition = false
|
25
|
+
|
26
|
+
config.vm.provision "fix-no-tty", type: "shell" do |s|
|
27
|
+
s.privileged = false
|
28
|
+
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
|
29
|
+
end
|
30
|
+
end
|
@@ -22,4 +22,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
22
22
|
config.persistent_storage.mountpoint = '/var/lib/mysql'
|
23
23
|
config.persistent_storage.volgroupname = 'myvolgroup'
|
24
24
|
|
25
|
-
|
25
|
+
config.vm.provision "fix-no-tty", type: "shell" do |s|
|
26
|
+
s.privileged = false
|
27
|
+
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
|
28
|
+
end
|
29
|
+
end
|
data/test.sh
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
pushd sample-vm > /dev/null
|
4
|
+
|
5
|
+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
6
|
+
VBOXMANAGE=`which vboxmanage`
|
7
|
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
8
|
+
VBOXMANAGE=`which vboxmanage`
|
9
|
+
elif [[ "$OSTYPE" == "cygwin" ]]; then
|
10
|
+
VBOXMANAGE="/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"
|
11
|
+
elif [[ "$OSTYPE" == "msys" ]]; then
|
12
|
+
VBOXMANAGE="/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"
|
13
|
+
elif [[ "$OSTYPE" == "win32" ]]; then
|
14
|
+
VBOXMANAGE="/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"
|
15
|
+
elif [[ "$OSTYPE" == "freebsd"* ]]; then
|
16
|
+
VBOXMANAGE=`which vboxmanage`
|
17
|
+
else
|
18
|
+
echo Seriously, what the hell are you running me on????
|
19
|
+
exit 1
|
20
|
+
fi
|
21
|
+
|
22
|
+
FILES=*.vagrantfile
|
23
|
+
for f in $FILES
|
24
|
+
do
|
25
|
+
echo Testing $f
|
26
|
+
VAGRANT_VAGRANTFILE="$f" vagrant up --no-color > $f.log
|
27
|
+
VAGRANT_VAGRANTFILE="$f" vagrant ssh -- "mount | grep -q mysql"
|
28
|
+
RESULT=$?
|
29
|
+
if [ $RESULT -eq 0 ]; then
|
30
|
+
echo ...[PASSED]
|
31
|
+
else
|
32
|
+
echo ...[FAILED]
|
33
|
+
fi
|
34
|
+
VAGRANT_VAGRANTFILE="$f" vagrant destroy -f --no-color >> $f.log && "$VBOXMANAGE" closemedium disk virtualdrive.vdi --delete >> $f.log 2>&1
|
35
|
+
done
|
36
|
+
|
37
|
+
|
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.
|
4
|
+
version: 0.0.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Kusnier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,8 +66,10 @@ files:
|
|
66
66
|
- lib/vagrant-persistent-storage/version.rb
|
67
67
|
- locales/en.yml
|
68
68
|
- sample-vm/.gitignore
|
69
|
-
- sample-vm/
|
69
|
+
- sample-vm/partition-false.vagrantfile
|
70
|
+
- sample-vm/partition-true.vagrantfile
|
70
71
|
- sample-win-vm/Vagrantfile
|
72
|
+
- test.sh
|
71
73
|
- vagrant-persistent-storage.gemspec
|
72
74
|
homepage: https://github.com/kusnier/vagrant-persistent-storage
|
73
75
|
licenses:
|