vagrant-digitalocean 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +1 -4
  3. data/LICENSE.txt +2 -1
  4. data/README.md +114 -96
  5. data/Rakefile +8 -10
  6. data/box/digital_ocean.box +0 -0
  7. data/lib/vagrant-digitalocean.rb +12 -4
  8. data/lib/vagrant-digitalocean/actions.rb +159 -0
  9. data/lib/vagrant-digitalocean/actions/check_state.rb +19 -0
  10. data/lib/vagrant-digitalocean/actions/create.rb +36 -21
  11. data/lib/vagrant-digitalocean/actions/destroy.rb +10 -8
  12. data/lib/vagrant-digitalocean/actions/modify_provision_path.rb +15 -17
  13. data/lib/vagrant-digitalocean/actions/power_off.rb +33 -0
  14. data/lib/vagrant-digitalocean/actions/power_on.rb +34 -0
  15. data/lib/vagrant-digitalocean/actions/rebuild.rb +9 -9
  16. data/lib/vagrant-digitalocean/actions/reload.rb +31 -0
  17. data/lib/vagrant-digitalocean/actions/setup_key.rb +56 -0
  18. data/lib/vagrant-digitalocean/actions/setup_provisioner.rb +26 -15
  19. data/lib/vagrant-digitalocean/actions/setup_sudo.rb +19 -12
  20. data/lib/vagrant-digitalocean/actions/setup_user.rb +25 -27
  21. data/lib/vagrant-digitalocean/actions/sync_folders.rb +18 -17
  22. data/lib/vagrant-digitalocean/commands/rebuild.rb +2 -3
  23. data/lib/vagrant-digitalocean/config.rb +30 -33
  24. data/lib/vagrant-digitalocean/errors.rb +0 -2
  25. data/lib/vagrant-digitalocean/helpers/client.rb +13 -15
  26. data/lib/vagrant-digitalocean/plugin.rb +5 -14
  27. data/lib/vagrant-digitalocean/provider.rb +48 -34
  28. data/lib/vagrant-digitalocean/version.rb +1 -1
  29. data/locales/en.yml +32 -40
  30. data/test/Vagrantfile +37 -0
  31. data/test/cookbooks/test/recipes/default.rb +1 -1
  32. data/test/scripts/provision.sh +3 -0
  33. data/test/test.sh +14 -0
  34. metadata +15 -27
  35. data/bin/build.sh +0 -39
  36. data/bin/test_run.sh +0 -15
  37. data/box/Vagrantfile +0 -20
  38. data/box/cookbooks/foo/recipes/default.rb +0 -1
  39. data/lib/vagrant-digitalocean/action.rb +0 -105
  40. data/lib/vagrant-digitalocean/actions/check_ssh_user.rb +0 -46
  41. data/lib/vagrant-digitalocean/actions/is_active.rb +0 -16
  42. data/lib/vagrant-digitalocean/actions/message_is_active.rb +0 -18
  43. data/lib/vagrant-digitalocean/actions/read_state.rb +0 -33
  44. data/lib/vagrant-digitalocean/actions/setup_ssh_key.rb +0 -60
  45. data/lib/vagrant-digitalocean/helpers/file.rb +0 -41
  46. data/lib/vagrant-digitalocean/helpers/translator.rb +0 -20
  47. data/scripts/chef/debian.sh +0 -5
  48. data/scripts/chef/redhat.sh +0 -5
  49. data/scripts/nfs/debian.sh +0 -4
  50. data/scripts/nfs/redhat.sh +0 -11
  51. data/scripts/sudo/redhat.sh +0 -2
  52. data/test/Vagrantfile.centos +0 -19
  53. data/test/Vagrantfile.ubuntu +0 -21
  54. data/test/provision.sh +0 -3
  55. data/test/scripts/setup_user.sh +0 -18
data/.gitignore CHANGED
@@ -14,5 +14,5 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- test/Vagrantfile
17
+ test/.vagrant
18
18
  tmp
data/Gemfile CHANGED
@@ -1,7 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # TODO switch on release
4
- gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
5
-
6
- # Specify your gem's dependencies in vagrant-digitalocean.gemspec
3
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.1.5'
7
4
  gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,5 @@
1
1
  Copyright (c) 2013 John Bender
2
+ Copyright (c) 2013 Shawn Dahlen
2
3
 
3
4
  MIT License
4
5
 
@@ -19,4 +20,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
20
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
21
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
22
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,116 +1,134 @@
1
- # Vagrant Digital Ocean
2
-
3
- `vagrant-digitalocean` is a provider plugin for Vagrant that allows the
1
+ Digital Ocean Vagrant Provider
2
+ ==============================
3
+ `vagrant-digitalocean` is a provider plugin for Vagrant that supports the
4
4
  management of [Digital Ocean](https://www.digitalocean.com/) droplets
5
5
  (instances).
6
6
 
7
- ## SSH Authentication
8
-
9
- This provider does not support the use of Vagrant's insecure key for SSH
10
- access. You must specify your own SSH key. The key may be defined within
11
- the global config section, `config.ssh.private_key_path`, or within the
12
- provider config section, `provider.ssh_private_key_path`. The provider
13
- config will take precedence. Additionally, you may provide a name for
14
- the SSH key using the `ssh_key_name` attribute within the provider config
15
- section. This is useful for de-conflict SSH keys used by different
16
- individuals when creating machines on Digital Ocean.
17
-
18
- ```ruby
19
- config.vm.provider :digital_ocean do |provider|
20
- provider.ssh_key_name = "My Laptop"
21
- provider.ssh_private_key_path = "~/.ssh/id_rsa.pub"
22
-
23
- # additional configuration here
24
- end
25
- ```
26
-
27
- The provider will assume the public key path is identical to the private
28
- key path with the *.pub* extention.
29
-
30
- By default, the provider uses the `root` account for SSH access. This is
31
- required for initial droplet creation and provisioning. You may specify
32
- an account that may be used for subsequent SSH access and provisioning
33
- by setting the `ssh_username` attribute within the provider config
34
- section.
35
-
36
- ## Supported Guests/Hosts
37
-
38
- The project is currently in alpha state and has been tested on the
39
- following hosts and guests:
40
-
41
- Hosts:
42
-
43
- * Ubuntu 12.04
44
- * Mac OS X
7
+ Current features include:
8
+ - create and destroy droplets
9
+ - power on and off droplets
10
+ - rebuild a droplet
11
+ - provision a droplet with the shell or Chef provisioners
12
+ - setup a SSH public key for authentication
13
+ - create a new user account during droplet creation
45
14
 
46
- Guests:
15
+ The provider has been tested with Vagrant 1.1.5 using Ubuntu 12.04 and
16
+ CentOS 6.3 guest operating systems.
47
17
 
48
- * Ubuntu 12.04
49
- * CentOS 6
18
+ Install
19
+ -------
20
+ Installation of the provider requires two steps:
50
21
 
51
- ## Supported Provisioners
22
+ 1. Install the provider plugin using the Vagrant command-line interface:
52
23
 
53
- The shell provisioner is supported by default but other provisioners require
54
- bootstrapping on the server. Chef is currently the only supported provisioner.
55
- Adding support for puppet and others requires adding the install scripts.
24
+ $ vagrant plugin install vagrant-digitalocean
56
25
 
57
- ## Installation
26
+ 2. Install the default provider box:
58
27
 
59
- Installation is performed in the prescribed manner for Vagrant 1.1 plugins.
28
+ $ vagrant box add digital_ocean https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box
60
29
 
61
- vagrant plugin install vagrant-digitalocean
30
+ **NOTE:** If you are using a Mac, you may need to install a CA bundle to enable SSL
31
+ communication with the Digital Ocean API. It is recommended to first install
32
+ [Homebrew](http://mxcl.github.io/homebrew/). With Homebrew installed, run
33
+ the following command to install the bundle:
62
34
 
63
- In addition to installing the plugin the default box associated with the
64
- provider needs to be installed.
35
+ $ brew install curl-ca-bundle
65
36
 
66
- vagrant box add digital_ocean https://raw.github.com/johnbender/vagrant-digitalocean/master/box/digital_ocean.box
37
+ Once the bundle is installed, add the following environment variable to your
38
+ `.bash_profile` script and `source` it:
67
39
 
68
- ## Usage
69
-
70
- To use the Digital Ocean provider you will need to visit the
71
- [API access page](https://www.digitalocean.com/api_access) to retrieve
72
- the client identifier and API key associated with your account.
73
-
74
- ### Config
40
+ ```bash
41
+ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
42
+ ```
75
43
 
76
- Supported provider configuration options are as follows:
44
+ Configure
45
+ ---------
46
+ Once the provider has been installed, you will need to configure your project
47
+ to use it. The most basic `Vagrantfile` to create a droplet on Digital Ocean
48
+ is shown below:
77
49
 
78
50
  ```ruby
79
- Vagrant.configure("2") do |config|
80
- config.vm.box = "digital_ocean"
81
-
82
- config.vm.provider :digital_ocean do |vm|
83
- vm.client_id = ENV["DO_CLIENT_ID"]
84
- vm.api_key = ENV["DO_API_KEY"]
85
- vm.image = "Ubuntu 12.04 x32 Server"
86
- vm.region = "New York 1"
87
- vm.size = "512MB"
88
- vm.ssh_key_name = "My Key"
89
- vm.ssh_private_key_path = "~/.ssh/id_rsa"
90
- vm.ssh_username = "test"
91
-
92
- # optional config for SSL cert on OSX and others
93
- vm.ca_path = "/usr/local/etc/openssl/ca-bundle.crt"
51
+ Vagrant.configure('2') do
52
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
53
+ config.vm.box = 'digital_ocean'
54
+ config.vm.provider :digital_ocean do |provider|
55
+ provider.client_id = 'YOUR CLIENT ID'
56
+ provider.api_key = 'YOUR API KEY'
94
57
  end
95
58
  end
96
59
  ```
97
60
 
98
- Note that the example contains the default value. The client identifier and API key are pulled from the environment and the other values are the string representations of the droplet configuration options as provided by the [Digital Ocean API](https://www.digitalocean.com/api). The ca_path configuration option may be necessary depending on your system setup.
99
-
100
- ## Tests
101
-
102
- Testing is very simple initially. There is no guaranteed cleanup. That is, if you are testing using `rake test` **you** are responsible for making sure that there aren't large numbers of test machines left on your Digital Ocean account.
103
-
104
- ```bash
105
- rake test # and wait ...
106
- ```
107
-
108
- Cleanup will be added eventually but will have to be specified explicitly because of the risk of machine deletetion.
109
-
110
- ## Contributing
111
-
112
- 1. Fork it
113
- 2. Create your feature branch (`git checkout -b my-new-feature`)
114
- 3. Commit your changes (`git commit -am 'Add some feature'`)
115
- 4. Push to the branch (`git push origin my-new-feature`)
116
- 5. Create new Pull Request
61
+ Please note the following:
62
+ - You *must* specify the `config.ssh.private_key_path` to enable authentication
63
+ with the droplet. The provider will create a new Digital Ocean SSH key using
64
+ your public key which is assumed to be the `private_key_path` with a *.pub*
65
+ extension.
66
+ - You *must* specify your Digital Ocean Client and API keys. These may be
67
+ found on the control panel within the *My Settings > API Access* section.
68
+
69
+ **Supported Configuration Attributes**
70
+
71
+ The following attributes are available to further configure the provider:
72
+ - `provider.image` - A string representing the image to use when creating a
73
+ new droplet (e.g. `Debian 6.0 x64`). The available options may
74
+ be found on Digital Ocean's new droplet [form](https://www.digitalocean.com/droplets/new).
75
+ It defaults to `Ubuntu 12.04 x64 Server`.
76
+ - `provider.region` - A string representing the region to create the new
77
+ droplet in. The available options are `New York 1` and `Amsterdam 1`. It
78
+ defaults to `New York 1`.
79
+ - `provider.size` - A string representing the size to use when creating a
80
+ new droplet (e.g. `1GB`). It defaults to `512MB`.
81
+ - `provider.ssh_key_name` - A String representing the name to use when creating
82
+ a Digital Ocean SSH key for droplet authentication. It defaults to `Vagrant`.
83
+
84
+ By default, the provider will create a new user account, `vagrant`, and setup
85
+ the specified SSH key for authentication. To change the user, set
86
+ `config.ssh.username` to the name of the account to create. When Vagrant 1.2 is
87
+ released, a new user account will only be created if `config.ssh.username` is
88
+ set.
89
+
90
+ *NOTE:* For those using a 0.0.x version of the provider,
91
+ `provider.ssh_username` and `provider.ssh_private_key_path` have been removed
92
+ in favor of the configuration options above. This approach better aligns the
93
+ provider with upcoming changes in Vagrant 1.2.
94
+
95
+ Run
96
+ ---
97
+ After creating your project's `Vagrantfile` with the required configuration
98
+ attributes described above, you may create a new droplet with the following
99
+ command:
100
+
101
+ $ vagrant up --provider=digital_ocean
102
+
103
+ This command will create a new droplet, setup your SSH key for authentication,
104
+ create a new user account, and run the provisioners you have configured.
105
+
106
+ **Supported Commands**
107
+
108
+ The provider supports the following Vagrant sub-commands:
109
+ - `vagrant destroy` - Destroys the droplet instance.
110
+ - `vagrant ssh` - Logs into the droplet instance using the configured user
111
+ account.
112
+ - `vagrant halt` - Powers off the droplet instance.
113
+ - `vagrant provision` - Runs the configured provisioners and rsyncs any
114
+ specified `config.vm.synced_folder`.
115
+ - `vagrant reload` - Reboots the droplet instance.
116
+ - `vagrant rebuild` - Destroys the droplet instance and recreates it with the
117
+ same IP address is was assigned to previously.
118
+ - `vagrant status` - Outputs the status (active, off, not created) for the
119
+ droplet instance.
120
+
121
+ Contribute
122
+ ----------
123
+ To contribute, clone the repository, and use [Bundler](http://gembundler.com)
124
+ to install dependencies:
125
+
126
+ $ bundle
127
+
128
+ To run the provider's tests:
129
+
130
+ $ bundle exec rake test
131
+
132
+ You can now make modifications. Running `vagrant` within the Bundler
133
+ environment will ensure that plugins installed in your Vagrant
134
+ environment are not loaded.
data/Rakefile CHANGED
@@ -1,24 +1,22 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_helper'
2
2
 
3
- namespace "dev" do
4
- task "build" do
5
- system "bash bin/build.sh"
6
- end
3
+ namespace :gem do
4
+ Bundler::GemHelper.install_tasks
7
5
  end
8
6
 
9
- task "test" do
10
- result = system("bash bin/test_run.sh")
7
+ task :test do
8
+ result = sh 'bash test/test.sh'
11
9
 
12
10
  if result
13
- puts "Success!"
11
+ puts 'Success!'
14
12
  else
15
- puts "Failure!"
13
+ puts 'Failure!'
16
14
  exit 1
17
15
  end
18
16
  end
19
17
 
20
18
  def env
21
- ['DO_CLIENT_ID', 'DO_API_KEY', 'VAGRANT_LOG'].inject("") do |acc, key|
19
+ ['DO_CLIENT_ID', 'DO_API_KEY', 'VAGRANT_LOG'].inject('') do |acc, key|
22
20
  acc += "#{key}=#{ENV[key] || 'error'} "
23
21
  end
24
22
  end
Binary file
@@ -1,12 +1,20 @@
1
- require "vagrant"
2
- require "vagrant-digitalocean/version"
3
- require "vagrant-digitalocean/plugin"
4
- require "vagrant-digitalocean/errors"
1
+ require 'vagrant-digitalocean/version'
2
+ require 'vagrant-digitalocean/plugin'
3
+ require 'vagrant-digitalocean/errors'
5
4
 
6
5
  module VagrantPlugins
7
6
  module DigitalOcean
8
7
  def self.source_root
9
8
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
10
9
  end
10
+
11
+ def self.public_key(private_key_path)
12
+ File.read("#{private_key_path}.pub")
13
+ rescue
14
+ raise Errors::PublicKeyError, :path => "#{private_key_path}.pub"
15
+ end
16
+
17
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
18
+ I18n.reload!
11
19
  end
12
20
  end
@@ -0,0 +1,159 @@
1
+ require 'vagrant-digitalocean/actions/check_state'
2
+ require 'vagrant-digitalocean/actions/create'
3
+ require 'vagrant-digitalocean/actions/destroy'
4
+ require 'vagrant-digitalocean/actions/power_off'
5
+ require 'vagrant-digitalocean/actions/power_on'
6
+ require 'vagrant-digitalocean/actions/rebuild'
7
+ require 'vagrant-digitalocean/actions/reload'
8
+ require 'vagrant-digitalocean/actions/setup_user'
9
+ require 'vagrant-digitalocean/actions/setup_sudo'
10
+ require 'vagrant-digitalocean/actions/setup_provisioner'
11
+ require 'vagrant-digitalocean/actions/setup_key'
12
+ require 'vagrant-digitalocean/actions/sync_folders'
13
+ require 'vagrant-digitalocean/actions/modify_provision_path'
14
+
15
+ module VagrantPlugins
16
+ module DigitalOcean
17
+ module Actions
18
+ include Vagrant::Action::Builtin
19
+
20
+ def self.destroy
21
+ return Vagrant::Action::Builder.new.tap do |builder|
22
+ builder.use ConfigValidate
23
+ builder.use Call, CheckState do |env, b|
24
+ case env[:machine_state]
25
+ when :not_created
26
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
27
+ else
28
+ b.use Destroy
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.ssh
35
+ return Vagrant::Action::Builder.new.tap do |builder|
36
+ builder.use ConfigValidate
37
+ builder.use Call, CheckState do |env, b|
38
+ case env[:machine_state]
39
+ when :active
40
+ b.use SSHExec
41
+ when :off
42
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.off')
43
+ when :not_created
44
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.ssh_run
51
+ return Vagrant::Action::Builder.new.tap do |builder|
52
+ builder.use ConfigValidate
53
+ builder.use Call, CheckState do |env, b|
54
+ case env[:machine_state]
55
+ when :active
56
+ b.use SSHRun
57
+ when :off
58
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.off')
59
+ when :not_created
60
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.provision
67
+ return Vagrant::Action::Builder.new.tap do |builder|
68
+ builder.use ConfigValidate
69
+ builder.use Call, CheckState do |env, b|
70
+ case env[:machine_state]
71
+ when :active
72
+ b.use Provision
73
+ b.use SetupProvisioner
74
+ b.use ModifyProvisionPath
75
+ b.use SyncFolders
76
+ when :off
77
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.off')
78
+ when :not_created
79
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.up
86
+ return Vagrant::Action::Builder.new.tap do |builder|
87
+ builder.use ConfigValidate
88
+ builder.use Call, CheckState do |env, b|
89
+ case env[:machine_state]
90
+ when :active
91
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.already_active')
92
+ when :off
93
+ b.use PowerOn
94
+ b.use provision
95
+ when :not_created
96
+ b.use SetupKey
97
+ b.use Create
98
+ b.use SetupSudo
99
+ b.use SetupUser
100
+ b.use provision
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def self.halt
107
+ return Vagrant::Action::Builder.new.tap do |builder|
108
+ builder.use ConfigValidate
109
+ builder.use Call, CheckState do |env, b|
110
+ case env[:machine_state]
111
+ when :active
112
+ b.use PowerOff
113
+ when :off
114
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.already_off')
115
+ when :not_created
116
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ def self.reload
123
+ return Vagrant::Action::Builder.new.tap do |builder|
124
+ builder.use ConfigValidate
125
+ builder.use Call, CheckState do |env, b|
126
+ case env[:machine_state]
127
+ when :active
128
+ b.use Reload
129
+ b.use provision
130
+ when :off
131
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.off')
132
+ when :not_created
133
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ def self.rebuild
140
+ return Vagrant::Action::Builder.new.tap do |builder|
141
+ builder.use ConfigValidate
142
+ builder.use Call, CheckState do |env, b|
143
+ case env[:machine_state]
144
+ when :active
145
+ b.use Rebuild
146
+ b.use SetupSudo
147
+ b.use SetupUser
148
+ b.use provision
149
+ when :off
150
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.off')
151
+ when :not_created
152
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.not_created')
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end