vagrant-vmpooler 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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -0
  3. data/Gemfile +15 -0
  4. data/LICENSE +15 -0
  5. data/README.md +143 -0
  6. data/Rakefile +22 -0
  7. data/example_box/Vagrantfile +22 -0
  8. data/example_box/dummy.box +0 -0
  9. data/example_box/metadata.json +3 -0
  10. data/example_box/readme.md +8 -0
  11. data/lib/vagrant-vmpooler.rb +53 -0
  12. data/lib/vagrant-vmpooler/action.rb +212 -0
  13. data/lib/vagrant-vmpooler/action/create_server.rb +103 -0
  14. data/lib/vagrant-vmpooler/action/delete_server.rb +50 -0
  15. data/lib/vagrant-vmpooler/action/hard_reboot_server.rb +24 -0
  16. data/lib/vagrant-vmpooler/action/is_created.rb +16 -0
  17. data/lib/vagrant-vmpooler/action/is_paused.rb +16 -0
  18. data/lib/vagrant-vmpooler/action/is_suspended.rb +16 -0
  19. data/lib/vagrant-vmpooler/action/message_already_created.rb +16 -0
  20. data/lib/vagrant-vmpooler/action/message_not_created.rb +16 -0
  21. data/lib/vagrant-vmpooler/action/message_server_running.rb +16 -0
  22. data/lib/vagrant-vmpooler/action/message_will_not_destroy.rb +16 -0
  23. data/lib/vagrant-vmpooler/action/pause_server.rb +24 -0
  24. data/lib/vagrant-vmpooler/action/read_ssh_info.rb +56 -0
  25. data/lib/vagrant-vmpooler/action/read_state.rb +41 -0
  26. data/lib/vagrant-vmpooler/action/reboot_server.rb +24 -0
  27. data/lib/vagrant-vmpooler/action/resume_server.rb +25 -0
  28. data/lib/vagrant-vmpooler/action/setup_rsync.rb +40 -0
  29. data/lib/vagrant-vmpooler/action/suspend_server.rb +24 -0
  30. data/lib/vagrant-vmpooler/action/sync_folders.rb +104 -0
  31. data/lib/vagrant-vmpooler/action/take_snapshot.rb +35 -0
  32. data/lib/vagrant-vmpooler/action/wait_for_state.rb +38 -0
  33. data/lib/vagrant-vmpooler/config.rb +100 -0
  34. data/lib/vagrant-vmpooler/errors.rb +31 -0
  35. data/lib/vagrant-vmpooler/plugin.rb +30 -0
  36. data/lib/vagrant-vmpooler/provider.rb +55 -0
  37. data/lib/vagrant-vmpooler/version.rb +5 -0
  38. data/locales/en.yml +151 -0
  39. data/spec/spec_helper.rb +0 -0
  40. data/spec/vagrant-vmpooler/config_spec.rb +44 -0
  41. data/vagrant-vmpooler.gemspec +23 -0
  42. metadata +45 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cc6fb009c3b0a198615d4fcd1adcdc5e7fd394d
4
- data.tar.gz: b8759e327f2d75a66ce22afb7e918b5dcb26c280
3
+ metadata.gz: e486440ea637821124539808198cc50957bb029b
4
+ data.tar.gz: e554e152df419b00c8000868820e948eb5aa2347
5
5
  SHA512:
6
- metadata.gz: b8c60d6655b641bb197c492755a6cb4049b813ce17464b2be5f15f8a0cd0c7f49ccefaedef1c245c564ca14cc2d938a12d16b4ae419daad50193507b00542013
7
- data.tar.gz: df132df2989f210c4ecaad64ac6a1d8ec5ee4dc681df1213df33500c295d1c17972f82c43ef9faa62854fbd9edf8e8cbcdd576f7914d45ef426f7b441ab93dcf
6
+ metadata.gz: 882376fe4efc5110bd38861b3e90f0369de12f2dc36f2040bf0b914e9f1cc04d9f059a981d4bc6fb8a06f199bcaead92fa4dd77f41b76e6252806238b1de4404
7
+ data.tar.gz: ab6784bc7c9201ca52e411ed3b31eaa3ab60786f4094e29b3b119f8974aee1cc0ab094794b40b637dd3e80cd134cb68e716e064ae03da8d91c0039ba4f71e45b
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # editors
5
+ *.swp
6
+
7
+ # Bundler/Rubygems
8
+ *.gem
9
+ .bundle
10
+ pkg/*
11
+ tags
12
+ Gemfile.lock
13
+
14
+ # Vagrant
15
+ .vagrant
16
+ Vagrantfile
17
+ !example_box/Vagrantfile
18
+
19
+ # RVM files for gemset/ruby setting
20
+ .ruby-*
21
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "vmfloaty", "0.5.0"
6
+
7
+ group :development do
8
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
9
+ gem "rspec"
10
+ gem "rake"
11
+ end
12
+
13
+ group :plugins do
14
+ gem "vagrant-vmpooler", path: "."
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ vagrant-vmpooler
2
+
3
+ Copyright (C) 2016 Brian cain
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Vagrant Vmpooler Provider
2
+
3
+ vagrant-vmpooler is still a work in progress and a lot of things might not work at the moment. If you find a bug, feel free to open up an issue on this repository.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/vagrant-vmpooler.svg)](https://badge.fury.io/rb/vagrant-vmpooler)
6
+
7
+ ### Features
8
+
9
+ * Quickly provision virtual machines with vmpooler and vagrant
10
+ * SSH into machines
11
+ * Provision the instances with any built-in Vagrant provisioner
12
+ * Sync folders with Rsync
13
+ * Built off of the [vmfloaty](https://github.com/briancain/vmfloaty) library, using the [vmpooler](https://github.com/puppetlabs/vmpooler) api
14
+
15
+ ## Usage
16
+
17
+ ### Quick Start
18
+
19
+ To quickly get started, install the vagrant plugin with the command below. Then you'll want to add a dummy box from the [example_box](example_box) directory...finally create a Vagrantfile and run the up command with the `vmpooler` provider.
20
+
21
+ ```
22
+ $ vagrant plugin install vagrant-vmpooler
23
+ ...
24
+ $ vagrant box add dummy https://github.com/briancain/vagrant-vmpooler/blob/master/example_box/dummy.box
25
+ ...
26
+ $ vagrant up --provider=vmpooler
27
+ ...
28
+ ```
29
+
30
+ ### Example Vagrantfile
31
+
32
+ A few examples to get you started
33
+
34
+ ```ruby
35
+ # -*- mode: ruby -*-
36
+ # vi: set ft=ruby :
37
+
38
+ # Provisioning script
39
+ provision_script = <<SCRIPT
40
+ #!/bin/bash
41
+ echo "Hello there" > ~/hi.txt
42
+ SCRIPT
43
+
44
+ Vagrant.configure("2") do |config|
45
+ config.vm.box = "dummy"
46
+
47
+ # vagrant-vmpooler already assumes you are root
48
+ config.vm.provision :shell, :inline => provision_script, privileged: false
49
+
50
+ config.vm.provider :vmpooler do |vmpooler|
51
+ vmpooler.os = "centos-7-x86_64"
52
+ vmpooler.ttl = 24
53
+ vmpooler.password = "secretpassword"
54
+ end
55
+ end
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ Similar to [vmfloaty](https://github.com/briancain/vmfloaty#vmfloaty-dotfile), a few of these settings can be defined in the `vmfloaty` dotfile located in your home directory. However, they can be overridden in a Vagrantfile if needed. The configuration values that can be set in that dotfile below are explicitly called out.
61
+
62
+ * `url`
63
+ + __REQUIRED__
64
+ + __vmfloaty dotfile config setting__
65
+ + string
66
+ + The url to your vmpooler installation
67
+ * `os`
68
+ + __REQUIRED__
69
+ + string
70
+ + The type of operatingsystem to get from the pooler
71
+ * `password`
72
+ + __REQUIRED__
73
+ + string
74
+ + The password to use to log into the vmpooler machine
75
+ * `verbose`
76
+ + boolean
77
+ + Whether or not to run vmfloaty api calls in verbose mode
78
+ + defaults to `false`
79
+ * `token`
80
+ + __vmfloaty dotfile config setting__
81
+ + string
82
+ + The token used to obtain vms
83
+ * `ttl`
84
+ + integer
85
+ + How long the vm should additionally stay active for (default is 12 with token)
86
+ * `disk`
87
+ + integer
88
+ + Increases default disk space by this size
89
+
90
+ These can be set like any other vagrant provider:
91
+
92
+ ```ruby
93
+ Vagrant.configure("2") do |config|
94
+ # ... other stuff
95
+
96
+ config.vm.provider :vmpooler do |vmpooler|
97
+ vmpooler.password = "foo"
98
+ vmpooler.os = "ubuntu-1604-x86_64"
99
+ vmpooler.ttl = 48
100
+ end
101
+ end
102
+ ```
103
+
104
+ ## Synced Folders
105
+
106
+ At the moment, vagrant-vmpooler only supports rsync for syncing folders. It requires both the host machine and remote machine to have rsync installed. Right now there's a basic setup step that will install rsync on the remote host before syncing folders since several vmpooler machines do not have it installed by default.
107
+
108
+ ## Limitations
109
+
110
+ Both of the commands are not supported in this plugin since vmpooler gives no api support for halting or suspending vms. Running these commands will result in a warning from vagrant-vmpooler.
111
+
112
+ * `vagrant halt`
113
+ * `vagrant suspend`
114
+
115
+ vagrant-vmpooler assumes that it will be logging in as root or Administrator (windows) to any vmpooler vm.
116
+
117
+ ## Development
118
+
119
+ To work on the `vagrant-vmpooler` plugin, clone this repository out, and use
120
+ [Bundler](http://gembundler.com) to get the dependencies:
121
+
122
+ ```
123
+ $ bundle
124
+ ```
125
+
126
+ Once you have the dependencies, verify the unit tests pass with `rake`:
127
+
128
+ ```
129
+ $ bundle exec rake
130
+ ```
131
+
132
+ If those pass, you're ready to start developing the plugin. You can test
133
+ the plugin without installing it into your Vagrant environment by just
134
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
135
+ and add the following line to your `Vagrantfile`
136
+
137
+ ```ruby
138
+ Vagrant.require_plugin "vagrant-vmpooler"
139
+ ```
140
+ Use bundler to execute Vagrant:
141
+ ```
142
+ $ bundle exec vagrant up --provider=vmpooler
143
+ ```
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new(:spec) do |t|
19
+ t.rspec_opts = "--order defined"
20
+ end
21
+ # Default task is to run the unit tests
22
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Provisioning script
5
+ provision_script = <<SCRIPT
6
+ #!/bin/bash
7
+ echo "Hello there" > ~/hi.txt
8
+ SCRIPT
9
+
10
+ Vagrant.configure("2") do |config|
11
+ config.vm.box = "dummy"
12
+
13
+ # vagrant-vmpooler already assumes you are root
14
+ config.vm.provision :shell, :inline => provision_script, privileged: false
15
+
16
+ config.vm.provider :vmpooler do |vmpooler|
17
+ vmpooler.os = "centos-7-x86_64"
18
+ #vmpooler.os = "ubuntu-1604-x86_64"
19
+ vmpooler.ttl = 24
20
+ vmpooler.password = "Qu@lity!"
21
+ end
22
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "vmpooler"
3
+ }
@@ -0,0 +1,8 @@
1
+ # Vagrant vmpooler example Vagrantfile
2
+
3
+ Creating and adding a dummy box
4
+
5
+ ```shell
6
+ tar -czvf dummy.box metadata.json
7
+ vagrant box add dummy.box --name dummy
8
+ ```
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-vmpooler/plugin"
4
+
5
+ module VagrantPlugins
6
+ module Vmpooler
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-vmpooler", __FILE__))
8
+ autoload :Errors, lib_path.join("errors")
9
+
10
+ # This initializes the i18n load path so that the plugin-specific
11
+ # translations work.
12
+ def self.init_i18n
13
+ I18n.load_path << File.expand_path("locales/en.yml", source_root)
14
+ I18n.reload!
15
+ end
16
+
17
+ # This initializes the logging so that our logs are outputted at
18
+ # the same level as Vagrant core logs.
19
+ def self.init_logging
20
+ # Initialize logging
21
+ level = nil
22
+ begin
23
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
24
+ rescue NameError
25
+ # This means that the logging constant wasn't found,
26
+ # which is fine. We just keep `level` as `nil`. But
27
+ # we tell the user.
28
+ level = nil
29
+ end
30
+
31
+ # Some constants, such as "true" resolve to booleans, so the
32
+ # above error checking doesn't catch it. This will check to make
33
+ # sure that the log level is an integer, as Log4r requires.
34
+ level = nil if !level.is_a?(Integer)
35
+
36
+ # Set the logging level on all "vagrant" namespaced
37
+ # logs as long as we have a valid level.
38
+ if level
39
+ logger = Log4r::Logger.new("vagrant_vmpooler")
40
+ logger.outputters = Log4r::Outputter.stderr
41
+ logger.level = level
42
+ logger = nil
43
+ end
44
+ end
45
+
46
+ # This returns the path to the source of this plugin.
47
+ #
48
+ # @return [Pathname]
49
+ def self.source_root
50
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,212 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module Vmpooler
7
+ module Action
8
+ # Include the built-in modules so we can use them as top-level things.
9
+ include Vagrant::Action::Builtin
10
+
11
+ # This action is called when `vagrant destroy` is executed.
12
+ def self.action_destroy
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use ConfigValidate
15
+ b.use Call, DestroyConfirm do |env, b1|
16
+ if env[:result]
17
+ b1.use DeleteServer
18
+ else
19
+ b1.use MessageWillNotDestroy
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # This action is called to read the SSH info of the machine. The
26
+ # resulting state is expected to be put into the `:machine_ssh_info`
27
+ # key.
28
+ def self.action_read_ssh_info
29
+ Vagrant::Action::Builder.new.tap do |b|
30
+ b.use ConfigValidate
31
+ b.use ReadSSHInfo
32
+ end
33
+ end
34
+
35
+ # This action is called to read the state of the machine. The
36
+ # resulting state is expected to be put into the `:machine_state_id`
37
+ # key.
38
+ def self.action_read_state
39
+ Vagrant::Action::Builder.new.tap do |b|
40
+ b.use ConfigValidate
41
+ b.use ReadState
42
+ end
43
+ end
44
+
45
+ # This action is called when `vagrant ssh` is executed.
46
+ def self.action_ssh
47
+ Vagrant::Action::Builder.new.tap do |b|
48
+ b.use ConfigValidate
49
+ b.use Call, IsCreated do |env, b1|
50
+ unless env[:result]
51
+ b1.use MessageNotCreated
52
+ next
53
+ end
54
+
55
+ b1.use SSHExec
56
+ end
57
+ end
58
+ end
59
+
60
+ def self.action_ssh_run
61
+ Vagrant::Action::Builder.new.tap do |b|
62
+ b.use ConfigValidate
63
+ b.use Call, IsCreated do |env, b1|
64
+ unless env[:result]
65
+ b1.use MessageNotCreated
66
+ next
67
+ end
68
+
69
+ b1.use SSHRun
70
+ end
71
+ end
72
+ end
73
+
74
+ def self.action_prepare_boot
75
+ Vagrant::Action::Builder.new.tap do |b|
76
+ b.use Provision
77
+ b.use SyncFolders
78
+ b.use SetHostname
79
+ end
80
+ end
81
+
82
+ # This action is called when `vagrant up` is executed.
83
+ def self.action_up
84
+ Vagrant::Action::Builder.new.tap do |b|
85
+ b.use HandleBox
86
+ b.use ConfigValidate
87
+ b.use Call, IsCreated do |env, b1|
88
+ unless env[:result]
89
+ b1.use action_prepare_boot
90
+ b1.use CreateServer
91
+ b1.use SetupRsync
92
+ else
93
+ b1.use action_resume
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ # This action is called when `vagrant provision` is executed.
100
+ def self.action_provision
101
+ Vagrant::Action::Builder.new.tap do |b|
102
+ b.use ConfigValidate
103
+ b.use Call, IsCreated do |env, b1|
104
+ unless env[:result]
105
+ b1.use MessageNotCreated
106
+ next
107
+ end
108
+
109
+ b1.use Provision
110
+ b1.use SyncFolders
111
+ end
112
+ end
113
+ end
114
+
115
+ # This action is called when `vagrant reload` is executed.
116
+ def self.action_reload
117
+ Vagrant::Action::Builder.new.tap do |b|
118
+ b.use ConfigValidate
119
+ b.use Call, IsPaused do |env, b1|
120
+ unless env[:result]
121
+ b1.use Call, IsSuspended do |env2, b2|
122
+ env[:ui].warn(I18n.t("vagrant_vmpooler.not_supported"))
123
+ #b2.use RebootServer
124
+ end
125
+ end
126
+
127
+ b1.use Call, WaitForState, [:active], 120 do |env2, b2|
128
+ unless env2[:result]
129
+ env[:ui].warn(I18n.t("vagrant_vmpooler.not_supported"))
130
+ #b2.use HardRebootServer
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ # This action is called when `vagrant halt` is executed.
138
+ def self.action_halt
139
+ Vagrant::Action::Builder.new.tap do |b|
140
+ b.use ConfigValidate
141
+ b.use Call, IsCreated do |env, b1|
142
+ # throw error?
143
+ env[:ui].warn(I18n.t("vagrant_vmpooler.not_supported"))
144
+ end
145
+ end
146
+ end
147
+
148
+ # This action is called when `vagrant resume` is executed.
149
+ def self.action_resume
150
+ Vagrant::Action::Builder.new.tap do |b|
151
+ b.use ConfigValidate
152
+ b.use Call, IsCreated do |env, b1|
153
+ if env[:result]
154
+ b1.use MessageServerRunning
155
+ next
156
+ end
157
+
158
+ b1.use ResumeServer
159
+ b1.use SyncFolders
160
+ end
161
+ end
162
+ end
163
+
164
+ # This action is called when `vagrant suspend` is executed.
165
+ def self.action_suspend
166
+ Vagrant::Action::Builder.new.tap do |b|
167
+ b.use ConfigValidate
168
+ b.use Call, IsCreated do |env, b1|
169
+ env[:ui].warn(I18n.t("vagrant_vmpooler.not_supported"))
170
+ end
171
+ end
172
+ end
173
+
174
+ def self.action_take_snapshot
175
+ Vagrant::Action::Builder.new.tap do |b|
176
+ b.use ConfigValidate
177
+ b.use Call, IsCreated do |env, b1|
178
+ if env[:result]
179
+ b2.use TakeSnapshot
180
+ else
181
+ b1.use MessageNotCreated
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ # The autoload farm
188
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
189
+ autoload :CreateServer, action_root.join("create_server")
190
+ autoload :DeleteServer, action_root.join("delete_server")
191
+ autoload :HardRebootServer, action_root.join("hard_reboot_server")
192
+ autoload :IsCreated, action_root.join("is_created")
193
+ autoload :IsPaused, action_root.join("is_paused")
194
+ autoload :IsSuspended, action_root.join("is_suspended")
195
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
196
+ autoload :MessageNotCreated, action_root.join("message_not_created")
197
+ autoload :MessageNotSuspended, action_root.join("message_not_suspended")
198
+ autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
199
+ autoload :MessageServerRunning, action_root.join("message_server_running")
200
+ autoload :PauseServer, action_root.join("pause_server")
201
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
202
+ autoload :ReadState, action_root.join("read_state")
203
+ autoload :RebootServer, action_root.join("reboot_server")
204
+ autoload :ResumeServer, action_root.join("resume_server")
205
+ autoload :SuspendServer, action_root.join("suspend_server")
206
+ autoload :SyncFolders, action_root.join("sync_folders")
207
+ autoload :TakeSnapshot, action_root.join("take_snapshot")
208
+ autoload :WaitForState, action_root.join("wait_for_state")
209
+ autoload :SetupRsync, action_root.join("setup_rsync")
210
+ end
211
+ end
212
+ end