vagrant-disksize 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +14 -14
- data/Gemfile +15 -15
- data/LICENSE.txt +21 -21
- data/README.md +69 -56
- data/Rakefile +2 -2
- data/Vagrantfile +73 -73
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/vagrant/disksize.rb +34 -34
- data/lib/vagrant/disksize/actions.rb +142 -140
- data/lib/vagrant/disksize/config.rb +48 -45
- data/lib/vagrant/disksize/version.rb +5 -5
- data/vagrant-disksize.gemspec +35 -35
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed50257fa9beb3cf82e819f7c9cda72de170a1a
|
4
|
+
data.tar.gz: 2ea55ad19b783a25fbb442fd3947b7e13284f027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abee2553e9b3c3c981b76c3f39f652af94e94f5d859c74fd4c5b59fd8d50ef7d8fd076d11a2c9a7590af7ef4882ea75670f5a999ba86b9034f5116462ff852de
|
7
|
+
data.tar.gz: 22a95dd79e18d89e3115795d801168ac5b0367ce730901e6ceaf427c08779cbdfcdb828949c14497d845ffd6f1e2bae82053d6de927b2e02334c6db0dbf3b520
|
data/.gitignore
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
|
11
|
-
.ruby-version
|
12
|
-
.ruby-gemset
|
13
|
-
|
14
|
-
.*.swp
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
.ruby-version
|
12
|
+
.ruby-gemset
|
13
|
+
|
14
|
+
.*.swp
|
data/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
group :development do
|
4
|
-
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.5'
|
5
|
-
end
|
6
|
-
|
7
|
-
group :plugins do
|
8
|
-
gem 'vagrant-disksize', path: '.'
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
# Specify your gem's dependencies in vagrant-disksize.gemspec
|
13
|
-
# Actually, we can't do this as we need to be in the plugins group
|
14
|
-
# for vagrant to load us during development
|
15
|
-
#gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.5'
|
5
|
+
end
|
6
|
+
|
7
|
+
group :plugins do
|
8
|
+
gem 'vagrant-disksize', path: '.'
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
# Specify your gem's dependencies in vagrant-disksize.gemspec
|
13
|
+
# Actually, we can't do this as we need to be in the plugins group
|
14
|
+
# for vagrant to load us during development
|
15
|
+
#gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 Simon Protheroe
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Simon Protheroe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,56 +1,69 @@
|
|
1
|
-
# vagrant-disksize
|
2
|
-
|
3
|
-
A Vagrant plugin to resize disks in VirtualBox
|
4
|
-
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
|
9
|
-
```shell
|
10
|
-
vagrant plugin install vagrant-disksize
|
11
|
-
```
|
12
|
-
|
13
|
-
## Usage
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
1
|
+
# vagrant-disksize
|
2
|
+
|
3
|
+
A Vagrant plugin to resize disks in VirtualBox
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
|
9
|
+
```shell
|
10
|
+
vagrant plugin install vagrant-disksize
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Set the size you want for your disk in your Vagrantfile. For example
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Vagrant.configure('2') do |config|
|
19
|
+
config.vm.box = 'ubuntu/xenial64'
|
20
|
+
config.disksize.size = '50GB'
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
You can specify the size as a raw number (in bytes) or using KB, MB, GB
|
25
|
+
or TB (though I'd be interested to learn more if you are using Vagrant
|
26
|
+
to create multi-terabyte disks). Internally the size will be converted
|
27
|
+
to megabytes, for ease of interaction with VirtualBox. If the value you
|
28
|
+
specify isn't a whole number of megabytes, it will be rounded up, to
|
29
|
+
ensure you have at least the capacity you requested. Note that the
|
30
|
+
plugin uses the original definitions so, for example, 1 GB = 1024 MB;
|
31
|
+
we don't have to use hardware manufacturer marketing maths here and
|
32
|
+
it makes the internal maths easier.
|
33
|
+
|
34
|
+
## Limitations
|
35
|
+
|
36
|
+
At present only the first disk will be resized. That seems to be OK for
|
37
|
+
typical boxes such as the official Ubuntu images for Xenial, but there may
|
38
|
+
well be other configurations where the first disk found isn't the main HDD.
|
39
|
+
|
40
|
+
The plugin only works with VirtualBox but it will issue an error message
|
41
|
+
and then disable itself if you try to use it with another provider.
|
42
|
+
|
43
|
+
Disks can only be increased in size. There is no facility to shrink a disk.
|
44
|
+
|
45
|
+
Depending on the guest, you may need to resize the partition and the filesystem
|
46
|
+
from within the guest. At present the plugin only resizes the underlying disk.
|
47
|
+
|
48
|
+
This hasn't been tested on a wide variety of versions of Vagrant or VirtualBox.
|
49
|
+
It works for, at least, Vagrant 1.8.5 and VirtualBox 5.1.x, but any
|
50
|
+
feedback about other versions, particularly older ones, would be much appreciated.
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
55
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
58
|
+
To release a new version, update the version number in `version.rb`, and then
|
59
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
60
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sprotheroe/vagrant-disksize.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
69
|
+
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :spec
|
data/Vagrantfile
CHANGED
@@ -1,73 +1,73 @@
|
|
1
|
-
# -*- mode: ruby -*-
|
2
|
-
# vi: set ft=ruby :
|
3
|
-
|
4
|
-
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
5
|
-
# configures the configuration version (we support older styles for
|
6
|
-
# backwards compatibility). Please don't change it unless you know what
|
7
|
-
# you're doing.
|
8
|
-
Vagrant.configure("2") do |config|
|
9
|
-
# The most common configuration options are documented and commented below.
|
10
|
-
# For a complete reference, please see the online documentation at
|
11
|
-
# https://docs.vagrantup.com.
|
12
|
-
|
13
|
-
# Every Vagrant development environment requires a box. You can search for
|
14
|
-
# boxes at https://atlas.hashicorp.com/search.
|
15
|
-
config.vm.box = "ubuntu/xenial64"
|
16
|
-
|
17
|
-
# Disable automatic box update checking. If you disable this, then
|
18
|
-
# boxes will only be checked for updates when the user runs
|
19
|
-
# `vagrant box outdated`. This is not recommended.
|
20
|
-
# config.vm.box_check_update = false
|
21
|
-
|
22
|
-
# Create a forwarded port mapping which allows access to a specific port
|
23
|
-
# within the machine from a port on the host machine. In the example below,
|
24
|
-
# accessing "localhost:8080" will access port 80 on the guest machine.
|
25
|
-
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
26
|
-
|
27
|
-
# Create a private network, which allows host-only access to the machine
|
28
|
-
# using a specific IP.
|
29
|
-
# config.vm.network "private_network", ip: "192.168.33.10"
|
30
|
-
|
31
|
-
# Create a public network, which generally matched to bridged network.
|
32
|
-
# Bridged networks make the machine appear as another physical device on
|
33
|
-
# your network.
|
34
|
-
# config.vm.network "public_network"
|
35
|
-
|
36
|
-
# Share an additional folder to the guest VM. The first argument is
|
37
|
-
# the path on the host to the actual folder. The second argument is
|
38
|
-
# the path on the guest to mount the folder. And the optional third
|
39
|
-
# argument is a set of non-required options.
|
40
|
-
# config.vm.synced_folder "../data", "/vagrant_data"
|
41
|
-
|
42
|
-
# Provider-specific configuration so you can fine-tune various
|
43
|
-
# backing providers for Vagrant. These expose provider-specific options.
|
44
|
-
# Example for VirtualBox:
|
45
|
-
#
|
46
|
-
# config.vm.provider "virtualbox" do |vb|
|
47
|
-
# # Display the VirtualBox GUI when booting the machine
|
48
|
-
# vb.gui = true
|
49
|
-
#
|
50
|
-
# # Customize the amount of memory on the VM:
|
51
|
-
# vb.memory = "1024"
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# View the documentation for the provider you are using for more
|
55
|
-
# information on available options.
|
56
|
-
|
57
|
-
config.disksize.size = '20GB'
|
58
|
-
|
59
|
-
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
|
60
|
-
# such as FTP and Heroku are also available. See the documentation at
|
61
|
-
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
|
62
|
-
# config.push.define "atlas" do |push|
|
63
|
-
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
|
64
|
-
# end
|
65
|
-
|
66
|
-
# Enable provisioning with a shell script. Additional provisioners such as
|
67
|
-
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
68
|
-
# documentation for more information about their specific syntax and use.
|
69
|
-
# config.vm.provision "shell", inline: <<-SHELL
|
70
|
-
# apt-get update
|
71
|
-
# apt-get install -y apache2
|
72
|
-
# SHELL
|
73
|
-
end
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
5
|
+
# configures the configuration version (we support older styles for
|
6
|
+
# backwards compatibility). Please don't change it unless you know what
|
7
|
+
# you're doing.
|
8
|
+
Vagrant.configure("2") do |config|
|
9
|
+
# The most common configuration options are documented and commented below.
|
10
|
+
# For a complete reference, please see the online documentation at
|
11
|
+
# https://docs.vagrantup.com.
|
12
|
+
|
13
|
+
# Every Vagrant development environment requires a box. You can search for
|
14
|
+
# boxes at https://atlas.hashicorp.com/search.
|
15
|
+
config.vm.box = "ubuntu/xenial64"
|
16
|
+
|
17
|
+
# Disable automatic box update checking. If you disable this, then
|
18
|
+
# boxes will only be checked for updates when the user runs
|
19
|
+
# `vagrant box outdated`. This is not recommended.
|
20
|
+
# config.vm.box_check_update = false
|
21
|
+
|
22
|
+
# Create a forwarded port mapping which allows access to a specific port
|
23
|
+
# within the machine from a port on the host machine. In the example below,
|
24
|
+
# accessing "localhost:8080" will access port 80 on the guest machine.
|
25
|
+
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
26
|
+
|
27
|
+
# Create a private network, which allows host-only access to the machine
|
28
|
+
# using a specific IP.
|
29
|
+
# config.vm.network "private_network", ip: "192.168.33.10"
|
30
|
+
|
31
|
+
# Create a public network, which generally matched to bridged network.
|
32
|
+
# Bridged networks make the machine appear as another physical device on
|
33
|
+
# your network.
|
34
|
+
# config.vm.network "public_network"
|
35
|
+
|
36
|
+
# Share an additional folder to the guest VM. The first argument is
|
37
|
+
# the path on the host to the actual folder. The second argument is
|
38
|
+
# the path on the guest to mount the folder. And the optional third
|
39
|
+
# argument is a set of non-required options.
|
40
|
+
# config.vm.synced_folder "../data", "/vagrant_data"
|
41
|
+
|
42
|
+
# Provider-specific configuration so you can fine-tune various
|
43
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
44
|
+
# Example for VirtualBox:
|
45
|
+
#
|
46
|
+
# config.vm.provider "virtualbox" do |vb|
|
47
|
+
# # Display the VirtualBox GUI when booting the machine
|
48
|
+
# vb.gui = true
|
49
|
+
#
|
50
|
+
# # Customize the amount of memory on the VM:
|
51
|
+
# vb.memory = "1024"
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# View the documentation for the provider you are using for more
|
55
|
+
# information on available options.
|
56
|
+
|
57
|
+
config.disksize.size = '20GB'
|
58
|
+
|
59
|
+
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
|
60
|
+
# such as FTP and Heroku are also available. See the documentation at
|
61
|
+
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
|
62
|
+
# config.push.define "atlas" do |push|
|
63
|
+
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
|
64
|
+
# end
|
65
|
+
|
66
|
+
# Enable provisioning with a shell script. Additional provisioners such as
|
67
|
+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
68
|
+
# documentation for more information about their specific syntax and use.
|
69
|
+
# config.vm.provision "shell", inline: <<-SHELL
|
70
|
+
# apt-get update
|
71
|
+
# apt-get install -y apache2
|
72
|
+
# SHELL
|
73
|
+
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "vagrant/disksize"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vagrant/disksize"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/lib/vagrant/disksize.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
#require "vagrant/disksize/version"
|
2
|
-
begin
|
3
|
-
require 'vagrant'
|
4
|
-
rescue LoadError
|
5
|
-
raise 'The vagrant-disksize plugin must be run within vagrant.'
|
6
|
-
end
|
7
|
-
|
8
|
-
|
9
|
-
module Vagrant
|
10
|
-
module Disksize
|
11
|
-
class Plugin < Vagrant.plugin('2')
|
12
|
-
|
13
|
-
name 'vagrant-disksize'
|
14
|
-
|
15
|
-
description <<-DESC
|
16
|
-
Provides the ability to resize VirtualBox disks at creation time,
|
17
|
-
so they don't need to be the same size as the default for the box.
|
18
|
-
Filesystems are not resized by this code.
|
19
|
-
DESC
|
20
|
-
|
21
|
-
config 'disksize' do
|
22
|
-
require_relative 'disksize/config'
|
23
|
-
Config
|
24
|
-
end
|
25
|
-
|
26
|
-
action_hook(:disksize, :machine_action_up) do |hook|
|
27
|
-
require_relative 'disksize/actions'
|
28
|
-
|
29
|
-
# TODO Ensure we are using the VirtualBox provider
|
30
|
-
hook.before(VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::ResizeDisk)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
#require "vagrant/disksize/version"
|
2
|
+
begin
|
3
|
+
require 'vagrant'
|
4
|
+
rescue LoadError
|
5
|
+
raise 'The vagrant-disksize plugin must be run within vagrant.'
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
module Vagrant
|
10
|
+
module Disksize
|
11
|
+
class Plugin < Vagrant.plugin('2')
|
12
|
+
|
13
|
+
name 'vagrant-disksize'
|
14
|
+
|
15
|
+
description <<-DESC
|
16
|
+
Provides the ability to resize VirtualBox disks at creation time,
|
17
|
+
so they don't need to be the same size as the default for the box.
|
18
|
+
Filesystems are not resized by this code.
|
19
|
+
DESC
|
20
|
+
|
21
|
+
config 'disksize' do
|
22
|
+
require_relative 'disksize/config'
|
23
|
+
Config
|
24
|
+
end
|
25
|
+
|
26
|
+
action_hook(:disksize, :machine_action_up) do |hook|
|
27
|
+
require_relative 'disksize/actions'
|
28
|
+
|
29
|
+
# TODO Ensure we are using the VirtualBox provider
|
30
|
+
hook.before(VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::ResizeDisk)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,140 +1,142 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Disksize
|
3
|
-
class Action
|
4
|
-
|
5
|
-
class ResizeDisk
|
6
|
-
|
7
|
-
# NOTE - size is represented in MB throughout this class, for ease of using with VirtualBox
|
8
|
-
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
@machine = env[:machine]
|
12
|
-
@enabled = true
|
13
|
-
if @machine.provider.to_s !~ /VirtualBox/
|
14
|
-
@enabled = false
|
15
|
-
env[:ui].error "The vagrant-disksize plugin only supports VirtualBox at present. Disk size will not be changed."
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(env)
|
20
|
-
# Resize disk itself before boot
|
21
|
-
if @enabled
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
env[:ui].
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
1
|
+
module Vagrant
|
2
|
+
module Disksize
|
3
|
+
class Action
|
4
|
+
|
5
|
+
class ResizeDisk
|
6
|
+
|
7
|
+
# NOTE - size is represented in MB throughout this class, for ease of using with VirtualBox
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@enabled = true
|
13
|
+
if @machine.provider.to_s !~ /VirtualBox/
|
14
|
+
@enabled = false
|
15
|
+
env[:ui].error "The vagrant-disksize plugin only supports VirtualBox at present. Disk size will not be changed."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
# Resize disk itself before boot
|
21
|
+
if @enabled
|
22
|
+
requested_size = @machine.config.disksize.size
|
23
|
+
if requested_size
|
24
|
+
ensure_disk_resizable(env)
|
25
|
+
resize_disk(env, requested_size)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Allow middleware chain to continue so VM is booted
|
30
|
+
@app.call(env)
|
31
|
+
|
32
|
+
# TODO Possibly resize partition and filesystem here if needed
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def ensure_disk_resizable(env)
|
38
|
+
driver = @machine.provider.driver
|
39
|
+
disks = identify_disks(driver)
|
40
|
+
# TODO Shouldn't assume that the first disk is the one we want to resize
|
41
|
+
unless disk_resizeable? disks.first
|
42
|
+
old_disk = disks.first
|
43
|
+
new_disk = generate_resizable_disk(old_disk)
|
44
|
+
unless File.exist? new_disk[:file]
|
45
|
+
clone_as_vdi(driver, old_disk, new_disk)
|
46
|
+
attach_disk(driver, new_disk)
|
47
|
+
File.delete(old_disk[:file])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def resize_disk(env, req_size)
|
53
|
+
driver = @machine.provider.driver
|
54
|
+
disks = identify_disks(driver)
|
55
|
+
target = disks.first # TODO Shouldn't assume that the first disk is the one we want to resize
|
56
|
+
|
57
|
+
old_size = get_disk_size(driver, target)
|
58
|
+
if old_size < req_size
|
59
|
+
grow_vdi(driver, target, req_size)
|
60
|
+
new_size = get_disk_size(driver, target)
|
61
|
+
env[:ui].success "Resized disk: old #{old_size} MB, req #{req_size} MB, new #{new_size} MB"
|
62
|
+
env[:ui].success "You may need to resize the filesystem from within the guest."
|
63
|
+
elsif old_size > req_size
|
64
|
+
env[:ui].error "Disk cannot be decreased in size. #{req_size} MB requested but disk is already #{old_size} MB."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def clone_as_vdi(driver, src, dst)
|
69
|
+
driver.execute('clonemedium', src[:file], dst[:file], '--format', 'VDI')
|
70
|
+
end
|
71
|
+
|
72
|
+
def grow_vdi(driver, disk, size)
|
73
|
+
driver.execute('modifymedium', disk[:file], '--resize', size.to_s)
|
74
|
+
end
|
75
|
+
|
76
|
+
def attach_disk(driver, disk)
|
77
|
+
parts = disk[:name].split('-')
|
78
|
+
controller = parts[0]
|
79
|
+
port = parts[1]
|
80
|
+
device = parts[2]
|
81
|
+
driver.execute('storageattach', @machine.id, '--storagectl', controller, '--port', port, '--device', device, '--type', 'hdd', '--medium', disk[:file])
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_disk_size(driver, disk)
|
85
|
+
size = nil
|
86
|
+
driver.execute('showmediuminfo', disk[:file]).each_line do |line|
|
87
|
+
if line =~ /Capacity:\s+([0-9]+)\s+MB/
|
88
|
+
size = $1.to_i
|
89
|
+
end
|
90
|
+
end
|
91
|
+
size
|
92
|
+
end
|
93
|
+
|
94
|
+
def identify_disks(driver)
|
95
|
+
vminfo = get_vminfo(driver)
|
96
|
+
disks = []
|
97
|
+
disk_keys = vminfo.keys.select { |k| k =~ /-ImageUUID-/ }
|
98
|
+
disk_keys.each do |key|
|
99
|
+
uuid = vminfo[key]
|
100
|
+
disk_name = key.gsub(/-ImageUUID-/,'-')
|
101
|
+
disk_file = vminfo[disk_name]
|
102
|
+
disks << {
|
103
|
+
uuid: uuid,
|
104
|
+
name: disk_name,
|
105
|
+
file: disk_file
|
106
|
+
}
|
107
|
+
end
|
108
|
+
disks
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_vminfo(driver)
|
112
|
+
vminfo = {}
|
113
|
+
driver.execute('showvminfo', @machine.id, '--machinereadable', retryable: true).split("\n").each do |line|
|
114
|
+
parts = line.partition('=')
|
115
|
+
key = unquoted(parts.first)
|
116
|
+
value = unquoted(parts.last)
|
117
|
+
vminfo[key] = value
|
118
|
+
end
|
119
|
+
vminfo
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_resizable_disk(disk)
|
123
|
+
src = disk[:file]
|
124
|
+
src_extn = File.extname(src)
|
125
|
+
src_path = File.dirname(src)
|
126
|
+
src_base = File.basename(src, src_extn)
|
127
|
+
dst = File.join(src_path, src_base) + '.vdi'
|
128
|
+
disk.merge({ uuid: "(undefined)", file: dst })
|
129
|
+
end
|
130
|
+
|
131
|
+
def disk_resizeable?(disk)
|
132
|
+
disk[:file].end_with? '.vdi'
|
133
|
+
end
|
134
|
+
|
135
|
+
def unquoted(s)
|
136
|
+
s.gsub(/\A"(.*)"\Z/,'\1')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -1,45 +1,48 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Disksize
|
3
|
-
class Config < Vagrant.plugin('2', :config)
|
4
|
-
attr_accessor :size
|
5
|
-
|
6
|
-
SIZE_REGEX = /^(?<number>[0-9]+)\s?(?<scale>KB|MB|GB|TB)?$/
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@size = UNSET_VALUE
|
10
|
-
end
|
11
|
-
|
12
|
-
def finalize!
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
1
|
+
module Vagrant
|
2
|
+
module Disksize
|
3
|
+
class Config < Vagrant.plugin('2', :config)
|
4
|
+
attr_accessor :size
|
5
|
+
|
6
|
+
SIZE_REGEX = /^(?<number>[0-9]+)\s?(?<scale>KB|MB|GB|TB)?$/
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@size = UNSET_VALUE
|
10
|
+
end
|
11
|
+
|
12
|
+
def finalize!
|
13
|
+
if @size == UNSET_VALUE
|
14
|
+
@size = nil
|
15
|
+
else
|
16
|
+
# Convert from human to machine readable
|
17
|
+
size_str = @size.to_s.strip
|
18
|
+
matches = SIZE_REGEX.match(size_str)
|
19
|
+
if matches
|
20
|
+
number = matches[:number]
|
21
|
+
scale = matches[:scale]
|
22
|
+
@size = number.to_i
|
23
|
+
if scale
|
24
|
+
pos = %w(KB MB GB TB).index(scale)
|
25
|
+
mult = 1 << 10*(pos+1)
|
26
|
+
@size *= mult
|
27
|
+
end
|
28
|
+
end
|
29
|
+
# Convert size from bytes to MB
|
30
|
+
size_in_mb = (@size.to_i + (1<<20)-1) / (1<<20)
|
31
|
+
@size = size_in_mb
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate(machine)
|
36
|
+
errors = _detected_errors
|
37
|
+
|
38
|
+
unless @size.nil? || @size.is_a?(Integer)
|
39
|
+
errors << "'#{@size}' is not a valid specification of disk size"
|
40
|
+
end
|
41
|
+
|
42
|
+
return { 'Disksize configuration' => errors }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Disksize
|
3
|
-
VERSION = "0.1.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Vagrant
|
2
|
+
module Disksize
|
3
|
+
VERSION = "0.1.2"
|
4
|
+
end
|
5
|
+
end
|
data/vagrant-disksize.gemspec
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'vagrant/disksize/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "vagrant-disksize"
|
8
|
-
spec.version = Vagrant::Disksize::VERSION
|
9
|
-
spec.authors = ["Simon Protheroe"]
|
10
|
-
spec.email = ["protheroe@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Vagrant plugin to resize VirtualBox disks}
|
13
|
-
spec.description = %q{Vagrant plugin to resize VirtualBox disks at creation time}
|
14
|
-
spec.homepage = "https://github.com/sprotheroe/vagrant-disksize"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
"public gem pushes."
|
24
|
-
end
|
25
|
-
|
26
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
f.match(%r{^(test|spec|features)/})
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant/disksize/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-disksize"
|
8
|
+
spec.version = Vagrant::Disksize::VERSION
|
9
|
+
spec.authors = ["Simon Protheroe"]
|
10
|
+
spec.email = ["protheroe@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Vagrant plugin to resize VirtualBox disks}
|
13
|
+
spec.description = %q{Vagrant plugin to resize VirtualBox disks at creation time}
|
14
|
+
spec.homepage = "https://github.com/sprotheroe/vagrant-disksize"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-disksize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Protheroe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.7
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Vagrant plugin to resize VirtualBox disks
|