vagrant-newdisk 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e6dc15fece47b2c2b659960109e4fc37fb31299
4
+ data.tar.gz: c201c5df7066de9a64065999ebff5174cf8d75d0
5
+ SHA512:
6
+ metadata.gz: 0a3c564a7bf83b3b775415fefedb04fb1e3eb70a50bc53848325dffc9759b2215770be54b936c3733d812a29cd26a70982a5a08c12861689605cc59dfb1ab1bd
7
+ data.tar.gz: 695058b2614bc0a42efebe6ebef9db3d4102522dd663188fe6fe013046ef99215a72c1bcc06de48d9475bfb70ad59825de702cf6cd2fae6c9b8691f78d5ace81
data/.gitignore ADDED
@@ -0,0 +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
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
5
+ end
6
+
7
+ group :plugins do
8
+ gem 'vagrant-newdisk', path: '.'
9
+ end
10
+
11
+ gem "rake", "~> 10.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # vagrant-newdisk
2
+
3
+ A Vagrant plugin to add a disks in VirtualBox
4
+
5
+
6
+ ## Installation
7
+
8
+
9
+ ```shell
10
+ vagrant plugin install vagrant-newdisk
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.newdisk.size = 10 * 1024 # size in megabytes
21
+ config.newdisk.path = "/tmp/your-file.vdi"
22
+ end
23
+ ```
24
+ ## Limitations
25
+
26
+ At present only one disk can be added to the first controller.
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
31
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ Bundler::GemHelper.install_tasks
data/Vagrantfile ADDED
@@ -0,0 +1,74 @@
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.newdisk.path = "test-disk.vdi"
58
+ config.newdisk.size = '20GB'
59
+
60
+ # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
61
+ # such as FTP and Heroku are also available. See the documentation at
62
+ # https://docs.vagrantup.com/v2/push/atlas.html for more information.
63
+ # config.push.define "atlas" do |push|
64
+ # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
65
+ # end
66
+
67
+ # Enable provisioning with a shell script. Additional provisioners such as
68
+ # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
69
+ # documentation for more information about their specific syntax and use.
70
+ # config.vm.provision "shell", inline: <<-SHELL
71
+ # apt-get update
72
+ # apt-get install -y apache2
73
+ # SHELL
74
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant/newdisk"
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 ADDED
@@ -0,0 +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
@@ -0,0 +1,101 @@
1
+ module Vagrant
2
+ module Newdisk
3
+ class Action
4
+
5
+ class NewDisk
6
+ def initialize(app, env)
7
+ @app = app
8
+ @machine = env[:machine]
9
+ @enabled = true
10
+ @ui = env[:ui]
11
+ if @machine.provider.to_s !~ /VirtualBox/
12
+ @enabled = false
13
+ env[:ui].error "The vagrant-newdisk plugin only supports VirtualBox at present."
14
+ end
15
+ end
16
+
17
+ def call(env)
18
+ # Create the disk before boot
19
+ if @enabled
20
+ size = @machine.config.newdisk.size
21
+ path = @machine.config.newdisk.path
22
+ env[:ui].error("size = #{size}")
23
+ env[:ui].error("path = #{path}")
24
+ new_disk(env, path, size)
25
+ end
26
+
27
+ # Allow middleware chain to continue so VM is booted
28
+ @app.call(env)
29
+ end
30
+
31
+ private
32
+
33
+ def new_disk(env, path, size)
34
+ driver = @machine.provider.driver
35
+ create_disk(driver, path, size)
36
+ attach_disk(driver, path)
37
+ end
38
+
39
+ def attach_disk(driver, path)
40
+ disk = find_place_for_new_disk(driver)
41
+ driver.execute('storageattach', @machine.id, '--storagectl', disk[:controller],
42
+ '--port', disk[:port].to_s, '--device', disk[:device].to_s, '--type', 'hdd',
43
+ '--medium', path)
44
+ end
45
+
46
+ def find_place_for_new_disk(driver)
47
+ disks = get_disks(driver)
48
+ @ui.error "disks = #{disks.to_s}"
49
+ controller = disks.first[:controller]
50
+ disks = disks.select { |disk| disk[:controller] == controller }
51
+ port = disks.map { |disk| disk[:port] }.max
52
+ disks = disks.select { |disk| disk[:port] == port }
53
+ max_device = disks.map { |disk| disk[:device] }.max
54
+
55
+ @ui.error "last disks: #{disks.to_s}"
56
+ new_disk = {:controller => controller, :port => port.to_i, :device => max_device.to_i + 1}
57
+ @ui.error "new disk: #{new_disk.to_s}"
58
+ new_disk
59
+ end
60
+
61
+ def get_disks(driver)
62
+ vminfo = get_vminfo(driver)
63
+ disks = []
64
+ disk_keys = vminfo.keys.select { |k| k =~ /-ImageUUID-/ }
65
+ disk_keys.each do |key|
66
+ uuid = vminfo[key]
67
+ disk_name = key.gsub(/-ImageUUID-/,'-')
68
+ parts = disk_name.split('-')
69
+ disks << {
70
+ controller: parts[0],
71
+ port: parts[1].to_i,
72
+ device: parts[2].to_i
73
+ }
74
+ end
75
+ disks
76
+ end
77
+
78
+ def get_vminfo(driver)
79
+ vminfo = {}
80
+ driver.execute('showvminfo', @machine.id, '--machinereadable', retryable: true).
81
+ split("\n").each do |line|
82
+ parts = line.partition('=')
83
+ key = unquoted(parts.first)
84
+ value = unquoted(parts.last)
85
+ vminfo[key] = value
86
+ end
87
+ vminfo
88
+ end
89
+
90
+ def create_disk(driver, path, size)
91
+ driver.execute('createhd', '--filename', path, '--size', size.to_s)
92
+ end
93
+
94
+ def unquoted(s)
95
+ s.gsub(/\A"(.*)"\Z/,'\1')
96
+ end
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,23 @@
1
+ module Vagrant
2
+ module Newdisk
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :size
5
+ attr_accessor :path
6
+
7
+ def initialize
8
+ @size = UNSET_VALUE
9
+ @path = UNSET_VALUE
10
+ end
11
+
12
+ def finalize!
13
+ return if @size == UNSET_VALUE
14
+ end
15
+
16
+ def validate(machine)
17
+ errors = []
18
+ return { 'Newdisk configuration' => errors }
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Newdisk
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The vagrant-newdisk plugin must be run within vagrant.'
5
+ end
6
+
7
+
8
+ module Vagrant
9
+ module Newdisk
10
+ class Plugin < Vagrant.plugin('2')
11
+
12
+ name 'vagrant-newdisk'
13
+
14
+ description <<-DESC
15
+ Provides the ability to add new VirtualBox disk at creation time.
16
+ DESC
17
+
18
+ config 'newdisk' do
19
+ require_relative 'newdisk/config'
20
+ Config
21
+ end
22
+
23
+ action_hook(:newdisk, :machine_action_up) do |hook|
24
+ require_relative 'newdisk/actions'
25
+ hook.before(VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::NewDisk)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/newdisk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-newdisk"
8
+ spec.version = Vagrant::Newdisk::VERSION
9
+ spec.authors = ["Yavor Nikolov"]
10
+ spec.email = ["nikolov.javor@gmail.com"]
11
+
12
+ spec.summary = %q{Vagrant plugin to add VirtualBox disk}
13
+ spec.description = %q{Vagrant plugin to add VirtualBox disk at creation time}
14
+ spec.homepage = "https://github.com/dbfit/vagrant-newdisk"
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
+
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.13"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-newdisk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yavor Nikolov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Vagrant plugin to add VirtualBox disk at creation time
42
+ email:
43
+ - nikolov.javor@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/vagrant/newdisk.rb
57
+ - lib/vagrant/newdisk/actions.rb
58
+ - lib/vagrant/newdisk/config.rb
59
+ - lib/vagrant/newdisk/version.rb
60
+ - vagrant-newdisk.gemspec
61
+ homepage: https://github.com/dbfit/vagrant-newdisk
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ allowed_push_host: https://rubygems.org
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.4
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Vagrant plugin to add VirtualBox disk
86
+ test_files: []