vagrant-ssd 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: daca43c93266c483d8a7b8d06e06e3defc5cc9ea90e84d8b0d9ec80e62c5b7ce
4
+ data.tar.gz: bc9f2a0846046f4242df5491e2ce71cb123b2d3488c54ee44f3af335a13786f6
5
+ SHA512:
6
+ metadata.gz: 6e3834907bc4ac27941f3e8c3eaa694fb34d728a44e2d53ded24e49995e2e1e9112d845e1eb4a481ba69e07c01047edb705f618e09a452809c9cd3633f490c4f
7
+ data.tar.gz: c48d4ab07296e794657f5839caf4607647ff431484d4d57ca28821ceecb74dd52d16f8c03406e5049a94c78601d53916c3731f36595159d4b3be936c75fb610a
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-ssd", path: "."
9
+ end
10
+
11
+ # Specify your gem's dependencies in vagrant-ssd.gemspec
12
+ #gemspec
13
+
14
+ #gem "rake", "~> 12.0"
@@ -0,0 +1,25 @@
1
+ # vagrant-ssd
2
+
3
+ A Vagrant plugin to set all virtual disks to nonrotational. Inspired by [vagrant-disksize](https://github.com/sprotheroe/vagrant-disksize).
4
+
5
+ ## Installation / usage
6
+
7
+ Use the following command:
8
+ ```
9
+ vagrant plugin install vagrant-ssd
10
+ ```
11
+ ...or set it in Vagrantfile plugins section:
12
+ ```
13
+ Vagrant.configure("2") do |config|
14
+ config.vagrant.plugins =["vagrant-ssd", ...]
15
+ ...
16
+ end
17
+ ```
18
+
19
+ ## Limitations
20
+ It works with Virtualbox provider only.
21
+
22
+ ## License
23
+
24
+ The gem is available as open source under the terms of the MIT License.
25
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant/ssd"
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(__FILE__)
@@ -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,26 @@
1
+ require "vagrant/ssd/version"
2
+
3
+ begin
4
+ require 'vagrant'
5
+ rescue LoadError
6
+ raise 'The vagrant-disksize plugin must be run within vagrant.'
7
+ end
8
+
9
+ module Vagrant
10
+ module Ssd
11
+ class Plugin < Vagrant.plugin('2')
12
+
13
+ name 'vagrant-ssd'
14
+
15
+ description <<-DESC
16
+ Adds 'solid state drive' attribute to virtual disks provided by Virtualbox.
17
+ DESC
18
+
19
+ action_hook(:ssd, :machine_action_up) do |hook|
20
+ require_relative 'ssd/actions'
21
+
22
+ hook.before(VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::SsdDisk)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,101 @@
1
+ module Vagrant
2
+ module Ssd
3
+ class Action
4
+
5
+ class SsdDisk
6
+
7
+ # inspired by https://github.com/sprotheroe/vagrant-disksize
8
+
9
+ # Creates infix for VBoxManage commands (driver.execute)
10
+ # according to VirtualBox version
11
+ VB_Meta = VagrantPlugins::ProviderVirtualBox::Driver::Meta.new()
12
+ if VB_Meta.version >= '5.0'
13
+ MEDIUM = 'medium'
14
+ else
15
+ MEDIUM = 'hd'
16
+ end
17
+
18
+ def initialize(app, env)
19
+ @app = app
20
+ @machine = env[:machine]
21
+ @enabled = true
22
+ if @machine.provider.to_s !~ /VirtualBox/
23
+ @enabled = false
24
+ env[:ui].error "Vagrant-ssd plugin supports VirtualBox only."
25
+ end
26
+ end
27
+
28
+ def call(env)
29
+
30
+ if @enabled
31
+
32
+ driver = @machine.provider.driver
33
+ disks = identify_disks(driver)
34
+
35
+ disks.each do | disk |
36
+ attach_disk(driver, disk)
37
+ end
38
+ end
39
+
40
+ # Allow middleware chain to continue so VM is booted
41
+ @app.call(env)
42
+
43
+ end
44
+
45
+ private
46
+
47
+ def attach_disk(driver, disk)
48
+ parts = disk[:name].split('-')
49
+ controller = parts[0]
50
+ port = parts[1]
51
+ device = parts[2]
52
+ driver.execute('storageattach', @machine.id, '--storagectl', controller, '--port', port, '--device', device, '--type', 'hdd', '--nonrotational', 'on', '--medium', disk[:file])
53
+ end
54
+
55
+ def identify_disks(driver)
56
+ vminfo = get_vminfo(driver)
57
+ disks = []
58
+ disk_keys = vminfo.keys.select { |k| k =~ /-ImageUUID-/ }
59
+ disk_keys.each do |key|
60
+ uuid = vminfo[key]
61
+ if is_disk(driver, uuid)
62
+ disk_name = key.gsub(/-ImageUUID-/,'-')
63
+ disk_file = vminfo[disk_name]
64
+ disks << {
65
+ uuid: uuid,
66
+ name: disk_name,
67
+ file: disk_file
68
+ }
69
+ end
70
+ end
71
+ disks
72
+ end
73
+
74
+
75
+ def is_disk(driver, uuid)
76
+ begin
77
+ driver.execute("showmediuminfo", 'disk', uuid)
78
+ true
79
+ rescue
80
+ false
81
+ end
82
+ end
83
+
84
+ def get_vminfo(driver)
85
+ vminfo = {}
86
+ driver.execute('showvminfo', @machine.id, '--machinereadable', retryable: true).split("\n").each do |line|
87
+ parts = line.partition('=')
88
+ key = unquoted(parts.first)
89
+ value = unquoted(parts.last)
90
+ vminfo[key] = value
91
+ end
92
+ vminfo
93
+ end
94
+
95
+ def unquoted(s)
96
+ s.gsub(/\A"(.*)"\Z/,'\1')
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Ssd
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/vagrant/ssd/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "vagrant-ssd"
5
+ spec.version = Vagrant::Ssd::VERSION
6
+ spec.authors = ["Gabor Toth"]
7
+ spec.email = ["gabor.toth@live.com"]
8
+
9
+ spec.summary = %q{Adds 'solid state drive' attribute to virtual disks provided by Virtualbox. }
10
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = "https://github.com/gabortoth-hu/vagrant-ssd"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/gabortoth-hu/vagrant-ssd"
18
+ spec.metadata["changelog_uri"] = "https://github.com/gabortoth-hu/vagrant-ssd"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # spec.add_development_dependency "bundler", "~> 1.13"
30
+ spec.add_development_dependency "rake", "~> 12.0"
31
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ssd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabor Toth
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ description:
28
+ email:
29
+ - gabor.toth@live.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - bin/console
39
+ - bin/setup
40
+ - lib/vagrant/ssd.rb
41
+ - lib/vagrant/ssd/actions.rb
42
+ - lib/vagrant/ssd/version.rb
43
+ - vagrant-ssd.gemspec
44
+ homepage: https://github.com/gabortoth-hu/vagrant-ssd
45
+ licenses: []
46
+ metadata:
47
+ allowed_push_host: https://rubygems.org
48
+ homepage_uri: https://github.com/gabortoth-hu/vagrant-ssd
49
+ source_code_uri: https://github.com/gabortoth-hu/vagrant-ssd
50
+ changelog_uri: https://github.com/gabortoth-hu/vagrant-ssd
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.3.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.6
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Adds 'solid state drive' attribute to virtual disks provided by Virtualbox.
71
+ test_files: []