vagrant-nitrousio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.env-example +4 -0
  3. data/.gitignore +17 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE +10 -0
  7. data/README.md +97 -0
  8. data/Rakefile +26 -0
  9. data/example_box/README.md +13 -0
  10. data/example_box/metadata.json +3 -0
  11. data/lib/vagrant-nitrousio/action/add_pub_key.rb +44 -0
  12. data/lib/vagrant-nitrousio/action/connect_nitrousio.rb +31 -0
  13. data/lib/vagrant-nitrousio/action/create.rb +79 -0
  14. data/lib/vagrant-nitrousio/action/is_created.rb +18 -0
  15. data/lib/vagrant-nitrousio/action/is_running.rb +18 -0
  16. data/lib/vagrant-nitrousio/action/is_stopped.rb +18 -0
  17. data/lib/vagrant-nitrousio/action/is_terminated.rb +18 -0
  18. data/lib/vagrant-nitrousio/action/message_already_created.rb +16 -0
  19. data/lib/vagrant-nitrousio/action/message_already_terminated.rb +16 -0
  20. data/lib/vagrant-nitrousio/action/message_cannot_halt.rb +16 -0
  21. data/lib/vagrant-nitrousio/action/message_cannot_terminate.rb +16 -0
  22. data/lib/vagrant-nitrousio/action/message_not_created.rb +16 -0
  23. data/lib/vagrant-nitrousio/action/message_not_running.rb +16 -0
  24. data/lib/vagrant-nitrousio/action/message_provisioning_not_yet_supported.rb +16 -0
  25. data/lib/vagrant-nitrousio/action/read_ssh_info.rb +60 -0
  26. data/lib/vagrant-nitrousio/action/read_state.rb +36 -0
  27. data/lib/vagrant-nitrousio/action/remove_machine_id.rb +19 -0
  28. data/lib/vagrant-nitrousio/action/start.rb +31 -0
  29. data/lib/vagrant-nitrousio/action/stop.rb +31 -0
  30. data/lib/vagrant-nitrousio/action/sync_folders.rb +57 -0
  31. data/lib/vagrant-nitrousio/action/terminate.rb +34 -0
  32. data/lib/vagrant-nitrousio/action/timed_provision.rb +21 -0
  33. data/lib/vagrant-nitrousio/action/warn_networks.rb +19 -0
  34. data/lib/vagrant-nitrousio/action.rb +166 -0
  35. data/lib/vagrant-nitrousio/client.rb +57 -0
  36. data/lib/vagrant-nitrousio/config.rb +94 -0
  37. data/lib/vagrant-nitrousio/errors.rb +55 -0
  38. data/lib/vagrant-nitrousio/plugin.rb +73 -0
  39. data/lib/vagrant-nitrousio/provider.rb +50 -0
  40. data/lib/vagrant-nitrousio/util/env.rb +12 -0
  41. data/lib/vagrant-nitrousio/util/timer.rb +17 -0
  42. data/lib/vagrant-nitrousio/version.rb +5 -0
  43. data/lib/vagrant-nitrousio.rb +18 -0
  44. data/locales/en.yml +139 -0
  45. data/nitrousio.box +0 -0
  46. data/sample/cookbooks/test/recipes/default.rb +1 -0
  47. data/sample/provision.sh +3 -0
  48. data/sample/puppet/manifests/site.pp +2 -0
  49. data/sample/puppet/modules/baseconfig/files/bashrc +107 -0
  50. data/sample/puppet/modules/baseconfig/manifests/init.pp +21 -0
  51. data/sample/test/hello.txt +1 -0
  52. data/spec/vagrant-nitrousio/action/create_spec.rb +36 -0
  53. data/spec/vagrant-nitrousio/action/read_ssh_info_spec.rb +59 -0
  54. data/spec/vagrant-nitrousio/action/read_state_spec.rb +46 -0
  55. data/spec/vagrant-nitrousio/action/start_spec.rb +32 -0
  56. data/spec/vagrant-nitrousio/action/stop_spec.rb +20 -0
  57. data/spec/vagrant-nitrousio/action/terminate_spec.rb +20 -0
  58. data/spec/vagrant-nitrousio/client_spec.rb +209 -0
  59. data/spec/vagrant-nitrousio/config_spec.rb +48 -0
  60. data/vagrant-nitrousio.gemspec +59 -0
  61. metadata +193 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94d3ce9a1598b2afa84fae47b829b9f6679a30ec
4
+ data.tar.gz: 2c18ff49dc0f120f3eba97e8810e8209c4cf6799
5
+ SHA512:
6
+ metadata.gz: 25c9520ae892b6e64b8ae18a527d1ef08d5af72f933a072ab56bf099ea918616ce36cdc33b7cd4d890a38a5f9a3d537c9ac48d491123a3f63139bca9cf99c211
7
+ data.tar.gz: ac7bfb0fbc7bd16857270f5f7a7449d6054a9ee9e40482ab3e50d39858cc0941e72cb1d77847093732219ec70f731fb6e28cda7df0e50246deac77d98af35e16
data/.env-example ADDED
@@ -0,0 +1,4 @@
1
+ VAGRANT_NITROUSIO_OAUTH_ID=0f53c0c1dc8f85c250b92ace97b3608256b20ff0feff116a63df241301513fd5
2
+ VAGRANT_NITROUSIO_OAUTH_SECRET=0e5138e61c65a7f259b23a1b0c6161e67440d44d41160a36deac1b64d792bc17
3
+ VAGRANT_NITROUSIO_VERIFY_SSL=false
4
+ VAGRANT_NITROUSIO_HOST=https://www.n2odev.com:5000
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .env
2
+
3
+ # OS-specific
4
+ .DS_Store
5
+
6
+ # Bundler/Rubygems
7
+ *.gem
8
+ .bundle
9
+ pkg/*
10
+ tags
11
+ Gemfile.lock
12
+ vendor/bundle
13
+
14
+ # Vagrant
15
+ .vagrant
16
+ Vagrantfile
17
+ !example_box/Vagrantfile
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --profile
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2013 Irrational Industries Inc. and Mitchell Hashimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # Vagrant Nitrous.IO Provider
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com/) 1.6+ plugin that adds an
4
+ [Nitrous.IO](https://www.nitrous.io/) provider to Vagrant, allowing Vagrant
5
+ to control and provision containers in Nitrous.IO.
6
+
7
+ ## Features
8
+
9
+ * Create and boot Nitrous.IO containers (boxes) with Vagrant.
10
+ * SSH into Nitrous.IO containers.
11
+ * Minimal synced folder support via `rsync`.
12
+ * Provision the boxes with any built-in Vagrant provisioner
13
+
14
+ ## Install
15
+
16
+ Install using standard Vagrant plugin installation methods. After
17
+ installing, `vagrant up` and specify the `nitrousio` provider. An example is
18
+ shown below.
19
+
20
+ ```
21
+ $ vagrant plugin install vagrant-nitrousio
22
+ ```
23
+
24
+ ## Configure
25
+
26
+ Once the provider has been installed, you will need to configure your project
27
+ to use it. A sample `Vagrantfile` to create a container on Nitrous.IO
28
+ is shown below:
29
+
30
+ ```ruby
31
+ Vagrant.configure("2") do |config|
32
+ config.vm.hostname = 'test-box'
33
+
34
+ config.vm.provider :nitrousio do |provider, override|
35
+ override.vm.box = 'nitrousio'
36
+ override.vm.box_url = 'https://github.com/nitrous-io/vagrant-nitrousio/raw/master/nitrousio.box'
37
+
38
+ provider.host = "HOST_SLUG" # copy the host slug from Nitrous.IO web app or CLI
39
+ provider.username = ENV['NITROUS_USERNAME']
40
+ provider.password = ENV['NITROUS_PASSWORD']
41
+ provider.ssh_private_key_path = "~/.ssh/id_rsa"
42
+
43
+ # remove this to sync your project folder on provision
44
+ override.vm.synced_folder '.', '/vagrant', :disabled => true
45
+ end
46
+ end
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ Once you have configured the Vagrantfile, you can create a new container by running:
52
+
53
+ ```
54
+ $ vagrant up --provider=nitrousio
55
+ ```
56
+
57
+ **Supported Commands**
58
+
59
+ The provider supports the following Vagrant sub-commands:
60
+ - `vagrant destroy` - Destroys the container.
61
+ - `vagrant ssh` - Logs into the container using the default user
62
+ account.
63
+ - `vagrant halt` - Stops the container.
64
+ - `vagrant provision` - Runs the configured provisioners and rsyncs any
65
+ specified `config.vm.synced_folder`.
66
+
67
+ ## Configuration
68
+
69
+ The provider exposes a few provider-specific configuration options:
70
+
71
+ * `username` - Username of your Nitrous.IO account.
72
+ * `password` - Password of your Nitrous.IO account.
73
+ * `host` - Slug of your Nitrous.IO host (you can check this from the web app or CLI)
74
+ * `image` - Set a base image for the container. This can be a path to a Docker repository.
75
+ By default, all vagrant boxes will use `nitrousio/vagrant-base` as the image.
76
+
77
+ ## Networks
78
+
79
+ Networking features in the form of `config.vm.network` are not
80
+ supported with `vagrant-nitrousio`, currently. If any of these are
81
+ specified, Vagrant will emit a warning, but will otherwise boot
82
+ the Nitrous.IO box.
83
+
84
+ ## Synced Folders
85
+
86
+ There is minimal support for synced folders. Upon `vagrant up`,
87
+ `vagrant reload`, and `vagrant provision`, the Actin.IO provider
88
+ will use `rsync` (if available) to uni-directionally sync the folder
89
+ to the remote machine over SSH.
90
+
91
+ This is good enough for all built-in Vagrant provisioners (shell,
92
+ chef, and puppet) to work!
93
+
94
+ ## License
95
+
96
+ Copyright (c) 2014 Nitrous, Inc. (formerly Irrational Industries Inc.) and Mitchell Hashimoto
97
+ This software is licensed under the [MIT License](https://raw.github.com/action-io/vagrant-nitrousio/master/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
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
19
+
20
+ # Default task is to run the unit tests
21
+ task :default => 'install'
22
+
23
+ desc 'Installs the plugin to test locally'
24
+ task :install => ['spec'] do
25
+ system "rm -rf pkg && rake build && /usr/bin/vagrant plugin uninstall vagrant-nitrousio && /usr/bin/vagrant plugin install pkg/*.gem"
26
+ end
@@ -0,0 +1,13 @@
1
+ # Vagrant Nitrous.IO Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `nitrousio` provider.
5
+ To turn this into a `.box` file:
6
+
7
+ ```
8
+ $ tar cvzf nitrousio.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for Nitrous.IO These defaults can easily be overwritten by
13
+ higher-level Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "nitrousio"
3
+ }
@@ -0,0 +1,44 @@
1
+ require 'log4r'
2
+ require 'vagrant/util/retryable'
3
+ require 'vagrant-nitrousio/errors'
4
+
5
+ module VagrantPlugins
6
+ module NitrousIO
7
+ module Action
8
+ # This add the public key to the box.
9
+ class AddPubKey
10
+ include Vagrant::Util::Retryable
11
+
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_nitrousio::action::start_instance')
15
+ end
16
+
17
+ def call(env)
18
+ add_pub_key(env[:nitrousio], env[:machine])
19
+
20
+ # Poll server to check whether the box is ready
21
+ env[:ui].info(I18n.t('vagrant_nitrousio.adding_pub_key'))
22
+
23
+ @app.call(env)
24
+ end
25
+
26
+ def add_pub_key(nitrousio, machine)
27
+ # assumed public key exists on the same path as the prviate key with .pub ext
28
+ path = machine.provider_config.ssh_private_key_path
29
+ path = path[0] if path.is_a?(Array)
30
+ path = File.expand_path(path, machine.env.root_path)
31
+ pub_key = read_pub_key(path)
32
+
33
+ nitrousio.request(:post, "/containers/#{machine.id}/keys", params: { key: pub_key })
34
+ end
35
+
36
+ def read_pub_key(private_key_path)
37
+ File.read("#{private_key_path}.pub")
38
+ rescue
39
+ raise Errors::PublicKeyError, path: "#{private_key_path}.pub"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'log4r'
2
+ require 'vagrant-nitrousio/client'
3
+ require 'vagrant-nitrousio/errors'
4
+
5
+ module VagrantPlugins
6
+ module NitrousIO
7
+ module Action
8
+ # This action connects to NitrousIO, verifies credentials work, and
9
+ # puts the NitrousIO connection object into the `:nitrousio` key
10
+ # in the environment.
11
+ class ConnectNitrousIO
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new('vagrant_nitrousio::action::connect_nitrousio')
16
+ end
17
+
18
+ def call(env)
19
+ username = env[:machine].provider_config.username
20
+ password = env[:machine].provider_config.password
21
+ client = Client.new
22
+ client.authorize(username, password)
23
+
24
+ env[:nitrousio] = client
25
+
26
+ @app.call(env)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,79 @@
1
+ require 'log4r'
2
+ require 'vagrant/util/retryable'
3
+ require 'vagrant-nitrousio/util/timer'
4
+ require 'vagrant-nitrousio/errors'
5
+ require 'securerandom'
6
+
7
+ module VagrantPlugins
8
+ module NitrousIO
9
+ module Action
10
+ # This creates a new container.
11
+ class Create
12
+ include Vagrant::Util::Retryable
13
+
14
+ def initialize(app, env)
15
+ @app = app
16
+ @logger = Log4r::Logger.new('vagrant_nitrousio::action::run_instance')
17
+ end
18
+
19
+ def call(env)
20
+ # Initialize metrics if they haven't been
21
+ env[:metrics] ||= {}
22
+
23
+ nitrousio = env[:nitrousio]
24
+ machine = env[:machine]
25
+
26
+ # Get the configs
27
+ prefix = machine.config.vm.hostname || machine.name || "vagrant"
28
+ privileged = machine.provider_config.privileged
29
+ name = "#{prefix}-#{SecureRandom.random_number 10000}"
30
+ host = machine.provider_config.host
31
+ image = machine.provider_config.image
32
+
33
+ # Launch!
34
+ env[:ui].info I18n.t('vagrant_nitrousio.launching_box')
35
+ env[:ui].info " -- Box Name: #{name}"
36
+ env[:ui].info " -- Host: #{host}"
37
+ env[:ui].info " -- Image: #{image}"
38
+
39
+ env[:ui].info(I18n.t('vagrant_nitrousio.pulling_image'))
40
+ pull_image(nitrousio, machine, host, image)
41
+
42
+ env[:ui].info(I18n.t('vagrant_nitrousio.creating_box'))
43
+ create_container(nitrousio, machine, host, image, name, privileged)
44
+
45
+ if !env[:interrupted]
46
+ # Ready and booted!
47
+ env[:ui].info(I18n.t('vagrant_nitrousio.box_ready'))
48
+ end
49
+
50
+ # Terminate the instance if we were interrupted
51
+ terminate(env) if env[:interrupted]
52
+
53
+ @logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
54
+
55
+ @app.call(env)
56
+ end
57
+
58
+ def pull_image(nitrousio, machine, host, image)
59
+ nitrousio.request(:post, "/hosts/#{host}/images/pull", params: { repository: image })
60
+ end
61
+
62
+ def create_container(nitrousio, machine, host, image, box_name, privileged = false)
63
+ response = nitrousio.request(:post, '/containers', body: { slug: box_name, host: host, image: image, privileged: privileged })
64
+
65
+ # save box id
66
+ machine.id = response.parsed['container']['id']
67
+ end
68
+
69
+ def terminate(env)
70
+ destroy_env = env.dup
71
+ destroy_env.delete(:interrupted)
72
+ destroy_env[:config_validate] = false
73
+ destroy_env[:force_confirm_destroy] = true
74
+ env[:action_runner].run(Action.action_destroy, destroy_env)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is running and branch in the middleware.
6
+ class IsRunning
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :running
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is stopped and branch in the middleware.
6
+ class IsStopped
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = [:stopped, :host_stopped].include?(env[:machine].state.id)
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is terminated and branch in the middleware.
6
+ class IsTerminated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].id == nil
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.already_created'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageAlreadyTerminated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.already_terminated'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageCannotHalt
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.cannot_halt'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageCannotTerminate
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.cannot_terminate'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.not_created'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageNotRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.not_running'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ class MessageProvisioningNotYetSupported
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_nitrousio.provisioning_not_yet_supported'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module NitrousIO
5
+ module Action
6
+ # This action reads the SSH info for the machine and puts it into the
7
+ # `:machine_ssh_info` key in the environment.
8
+ class ReadSSHInfo
9
+ NITROUS_HOST_HOSTNAME = "nitrouspro.com"
10
+
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new("vagrant_nitrousio::action::read_ssh_info")
14
+ end
15
+
16
+ def call(env)
17
+ nitrousio = env[:nitrousio]
18
+ machine = env[:machine]
19
+
20
+ return nil if machine.id.nil?
21
+
22
+ # Find the box
23
+ begin
24
+ response = nitrousio.request(:get, "/containers/#{machine.id}/config")
25
+ rescue => e
26
+ if e.respond_to?(:response) && e.response.status == 404
27
+ # The machine can't be found
28
+ @logger.info("Box not found on Nitrous.IO, assuming it got destroyed.")
29
+ machine.id = nil
30
+ return nil
31
+ else
32
+ raise e
33
+ end
34
+ end
35
+
36
+ ssh_port = nil
37
+ box_config = response.parsed['config']
38
+ ssh_port = box_config['port'].map {|p| entry = /\Apublic:([^:]+):22(\/tcp)?\z/.match(p); entry ? entry[1] : nil }.compact.pop
39
+
40
+ unless ssh_port
41
+ @logger.info("Box doesn't expose a SSH port")
42
+ return nil
43
+ end
44
+
45
+ # Get the configuration
46
+ config = machine.provider_config
47
+
48
+ env[:machine_ssh_info] = {
49
+ host: "#{config.host}.#{NITROUS_HOST_HOSTNAME}", # FIXME: config response should include the hostname
50
+ port: ssh_port,
51
+ private_key_path: config.ssh_private_key_path,
52
+ username: 'action' # FIXME: read from the config response
53
+ }
54
+
55
+ @app.call(env)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ require 'log4r'
2
+ require 'vagrant-nitrousio/errors'
3
+
4
+ module VagrantPlugins
5
+ module NitrousIO
6
+ module Action
7
+ # This action reads the state of the machine and puts it in the
8
+ # `:machine_state_id` key in the environment.
9
+ class ReadState
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_nitrousio::action::read_state")
13
+ end
14
+
15
+ def call(env)
16
+ env[:machine_state_id] = read_state(env[:nitrousio], env[:machine])
17
+
18
+ @app.call(env)
19
+ end
20
+
21
+ def read_state(nitrousio, machine)
22
+ return :not_created if machine.id.nil?
23
+
24
+ # Find the box
25
+ state = nitrousio.fetch_box_state(machine.id)
26
+ if state.nil?
27
+ @logger.info("Box not found on Nitrous.IO, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return :not_created
30
+ end
31
+ state
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is terminated and branch in the middleware.
6
+ class RemoveMachineId
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:machine].id = nil
13
+
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end