vagrant-openstack-cloud-provider 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +11 -0
  4. data/AUTHORS +5 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE.txt +23 -0
  7. data/README.md +169 -0
  8. data/Rakefile +21 -0
  9. data/dummy.box +0 -0
  10. data/example_box/README.md +13 -0
  11. data/example_box/metadata.json +3 -0
  12. data/lib/vagrant-openstack-cloud-provider.rb +53 -0
  13. data/lib/vagrant-openstack-cloud-provider/action.rb +129 -0
  14. data/lib/vagrant-openstack-cloud-provider/action/connect_openstack.rb +34 -0
  15. data/lib/vagrant-openstack-cloud-provider/action/create_server.rb +185 -0
  16. data/lib/vagrant-openstack-cloud-provider/action/delete_server.rb +26 -0
  17. data/lib/vagrant-openstack-cloud-provider/action/is_created.rb +16 -0
  18. data/lib/vagrant-openstack-cloud-provider/action/message_already_created.rb +16 -0
  19. data/lib/vagrant-openstack-cloud-provider/action/message_not_created.rb +16 -0
  20. data/lib/vagrant-openstack-cloud-provider/action/read_ssh_info_from_api.rb +46 -0
  21. data/lib/vagrant-openstack-cloud-provider/action/read_ssh_info_from_cache.rb +53 -0
  22. data/lib/vagrant-openstack-cloud-provider/action/read_state.rb +38 -0
  23. data/lib/vagrant-openstack-cloud-provider/action/sync_folders.rb +58 -0
  24. data/lib/vagrant-openstack-cloud-provider/config.rb +126 -0
  25. data/lib/vagrant-openstack-cloud-provider/errors.rb +35 -0
  26. data/lib/vagrant-openstack-cloud-provider/plugin.rb +37 -0
  27. data/lib/vagrant-openstack-cloud-provider/provider.rb +50 -0
  28. data/lib/vagrant-openstack-cloud-provider/version.rb +5 -0
  29. data/locales/en.yml +81 -0
  30. data/spec/spec_helper.rb +21 -0
  31. data/spec/vagrant-openstack-cloud-provider/action/create_server_spec.rb +89 -0
  32. data/spec/vagrant-openstack-cloud-provider/action/read_ssh_info_spec.rb +122 -0
  33. data/spec/vagrant-openstack-cloud-provider/config_spec.rb +81 -0
  34. data/vagrant-openstack-cloud-provider.gemspec +25 -0
  35. metadata +123 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDBkNjliNDMzNGM0Njc0Yjc4YTJlYzgzMWViYjM2ZTJiM2YzMzc0OA==
5
+ data.tar.gz: !binary |-
6
+ MWYwMjhmMzM1NDg5YTE5ZWUzYTM1NDQ4ODJjOGI1ZjIzNGEwNTY4Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Yzg1YjI2MDYyODE1ODYyMDhjNmQ5YmI3MWFkOTZmZGVjZjM3MTAzMGE1ZWVh
10
+ NTkxYzUwOGU2OGVlYTcwZTdlODAzNzc4NzBjOWNlZDBjYzI3YWFmY2EwYTYy
11
+ M2IxMDdjYWEzYzg4ZTBiMjI4YjljNzY2MDBjMGZhMTU0YjA0OGQ=
12
+ data.tar.gz: !binary |-
13
+ ZDQ1ZDM1ZTk3MTJiZTM4ODAwZjc5NjVlNjkxMmVhMTdlNGMwZDQ3NDk0Y2Rh
14
+ ZjUyOTI4MzVhZDM1NTEwNTBjNzE0OTZhNzhiMjA2OWE3NmIyMDU4ODE0YzAy
15
+ MTgxMjI4ZGJhMDI1NDI3MTgxOTI3YTE4NjU2YmJkOTNmYmFlOGE=
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .rspec
2
+ .idea
3
+ *.iml
4
+ *.gem
5
+ *.rbc
6
+ .bundle
7
+ .config
8
+ .vagrant
9
+ .yardoc
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ lib/bundler/man
16
+ pkg
17
+ rdoc
18
+ spec/reports
19
+ test/tmp
20
+ test/version_tmp
21
+ tmp
22
+ Vagrantfile
23
+ vendor/
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ rvm:
3
+ - 2.0.0
4
+ deploy:
5
+ provider: rubygems
6
+ api_key:
7
+ secure: F5wfYwDeMrpiTpyq1V7Zrk1HygxH1NXB/9qD5CyLNsZlKWXKTNv94aTgOjjeUdu5NpNv+IwH7IAzKTvpxE9P1fcGNqBAy0KQ5uIBGqNi0kHphl82S+zpYeLacfPFm2cgz0rPI0hpRXmp3ZnXY1QiFmZs1BGOHc5bah01DHC0Euo=
8
+ gem: vagrant-openstack-cloud-provider
9
+ on:
10
+ tags: true
11
+ repo: mat128/vagrant-openstack-cloud-provider
data/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ Authors
2
+ =======
3
+
4
+ - Mitchell Hashimoto for vagrant-rackspace
5
+ - Thomas Kadauke from Cloudbau for the original vagrant-openstack, which was a fork of vagrant-rackspace.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => 'v1.8.1'
10
+ gem 'simplecov', :require => false
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013 Mitchell Hashimoto
2
+ Copyright (c) 2013 cloudbau GmbH
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Vagrant OpenStack Cloud Provider
2
+ [![Build Status](https://travis-ci.org/mat128/vagrant-openstack-cloud-provider.png?branch=master)](https://travis-ci.org/mat128/vagrant-openstack-cloud-provider)
3
+
4
+ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an
5
+ [OpenStack Cloud](http://www.openstack.org) provider to Vagrant,
6
+ allowing Vagrant to control and provision machines within an OpenStack
7
+ cloud.
8
+
9
+ This plugin started as a fork of the Vagrant Rackspace provider.
10
+
11
+ **Note:** This plugin requires Vagrant 1.2+. The last version of this plugin supporting Vagrant 1.1 is 0.3.0.
12
+
13
+ ## Features
14
+
15
+ * Boot OpenStack Cloud instances.
16
+ * SSH into the instances.
17
+ * Provision the instances with any built-in Vagrant provisioner.
18
+ * Minimal synced folder support via `rsync`.
19
+ * Create instances with a specific list of networks
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ $ git clone https://github.com/mat128/vagrant-openstack-cloud-provider.git
25
+ $ cd vagrant-openstack-cloud-provider
26
+ $ gem build vagrant-openstack-cloud-provider.gemspec
27
+ $ vagrant plugin install vagrant-openstack-cloud-provider-*.gem
28
+ ...
29
+ $ vagrant up --provider=openstack
30
+ ...
31
+ ```
32
+
33
+ Of course prior to doing this, you'll need to obtain an OpenStack-compatible
34
+ box file for Vagrant.
35
+
36
+ ## Quick Start
37
+
38
+ After installing the plugin (instructions above), the quickest way to get
39
+ started is to actually use a dummy OpenStack box and specify all the details
40
+ manually within a `config.vm.provider` block. So first, add the dummy
41
+ box using any name you want:
42
+
43
+ ```
44
+ $ vagrant box add dummy https://github.com/mat128/vagrant-openstack-cloud-provider/raw/master/dummy.box
45
+ ...
46
+ ```
47
+
48
+ And then make a Vagrantfile that looks like the following, filling in
49
+ your information where necessary.
50
+
51
+ ```
52
+ require 'vagrant-openstack-cloud-provider'
53
+
54
+ Vagrant.configure("2") do |config|
55
+ config.vm.box = "dummy"
56
+
57
+ config.vm.provider :openstack do |os| # e.g.
58
+ os.username = "YOUR USERNAME" # "#{ENV['OS_USERNAME']}"
59
+ os.api_key = "YOUR API KEY" # "#{ENV['OS_PASSWORD']}"
60
+ os.flavor = /m1.tiny/
61
+ os.image = /Ubuntu/
62
+ os.endpoint = "KEYSTONE AUTH URL" # "#{ENV['OS_AUTH_URL']}/tokens"
63
+ os.keypair_name = "YOUR KEYPAIR NAME"
64
+ os.ssh_username = "SSH USERNAME"
65
+ os.public_network_name = "NAME OF THE PUBLIC NETWORK"
66
+ os.networks = %w(net1 net2 net3)
67
+ os.tenant = "NAME OF THE TENANT"
68
+ os.region = "REGION_NAME"
69
+ end
70
+ end
71
+ ```
72
+
73
+ And then run `vagrant up --provider=openstack`.
74
+
75
+ This will start a tiny Ubuntu instance in your OpenStack installation within
76
+ your tenant. And assuming your SSH information was filled in properly
77
+ within your Vagrantfile, SSH and provisioning will work as well.
78
+
79
+ Note that normally a lot of this boilerplate is encoded within the box
80
+ file, but the box file used for the quick start, the "dummy" box, has
81
+ no preconfigured defaults.
82
+
83
+ ## Box Format
84
+
85
+ Every provider in Vagrant must introduce a custom box format. This
86
+ provider introduces `openstack` boxes. You can view an example box in
87
+ the [example_box/ directory](https://github.com/mat128/vagrant-openstack-cloud-provider/tree/master/example_box).
88
+ That directory also contains instructions on how to build a box.
89
+
90
+ The box format is basically just the required `metadata.json` file
91
+ along with a `Vagrantfile` that does default settings for the
92
+ provider-specific configuration for this provider.
93
+
94
+ ## Configuration
95
+
96
+ This provider exposes quite a few provider-specific configuration options:
97
+
98
+ * `api_key` - The API key for accessing OpenStack.
99
+ * `flavor` - The server flavor to boot. This can be a string matching
100
+ the exact ID or name of the server, or this can be a regular expression
101
+ to partially match some server flavor.
102
+ * `image` - The server image to boot. This can be a string matching the
103
+ exact ID or name of the image, or this can be a regular expression to
104
+ partially match some image.
105
+ * `endpoint` - The keystone authentication URL of your OpenStack installation.
106
+ * `server_name` - The name of the server within the OpenStack Cloud. This
107
+ defaults to the name of the Vagrant machine (via `config.vm.define`), but
108
+ can be overridden with this.
109
+ * `username` - The username with which to access OpenStack.
110
+ * `keypair_name` - The name of the keypair to access the machine.
111
+ * `ssh_username` - The username to access the machine.
112
+ * `public_network_name` - The name of the public network within your Openstack cluster
113
+ * `networks` - A list -- use %w(net1 net2) -- of networks to configure
114
+ on your instance.
115
+ * `tenant` - The name of the tenant on which the virtual machine should spawn.
116
+
117
+ These can be set like typical provider-specific configuration:
118
+
119
+ ```ruby
120
+ Vagrant.configure("2") do |config|
121
+ # ... other stuff
122
+
123
+ config.vm.provider :openstack do |os|
124
+ os.username = "mitchellh"
125
+ os.api_key = "foobarbaz"
126
+ end
127
+ end
128
+ ```
129
+
130
+ ## Networks
131
+
132
+ Networking features in the form of `config.vm.network` are not
133
+ supported with `vagrant-openstack`, currently. If any of these are
134
+ specified, Vagrant will emit a warning, but will otherwise boot
135
+ the OpenStack server.
136
+
137
+ ## Synced Folders
138
+
139
+ There is minimal support for synced folders. Upon `vagrant up`,
140
+ `vagrant reload`, and `vagrant provision`, the OpenStack provider will use
141
+ `rsync` (if available) to uni-directionally sync the folder to
142
+ the remote machine over SSH.
143
+
144
+ This is good enough for all built-in Vagrant provisioners (shell,
145
+ chef, and puppet) to work!
146
+
147
+ ## Development
148
+
149
+ To work on the `vagrant-openstack` plugin, clone this repository out, and use
150
+ [Bundler](http://gembundler.com) to get the dependencies:
151
+
152
+ ```
153
+ $ bundle
154
+ ```
155
+
156
+ Once you have the dependencies, verify the unit tests pass with `rake`:
157
+
158
+ ```
159
+ $ bundle exec rake
160
+ ```
161
+
162
+ If those pass, you're ready to start developing the plugin. You can test
163
+ the plugin without installing it into your Vagrant environment by just
164
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
165
+ that uses it, and uses bundler to execute Vagrant:
166
+
167
+ ```
168
+ $ bundle exec vagrant up --provider=openstack
169
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
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 => "spec"
data/dummy.box ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant OpenStack Cloud 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 `openstack` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf openstack.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for OpenStack. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "openstack"
3
+ }
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-openstack-cloud-provider/plugin"
4
+
5
+ module VagrantPlugins
6
+ module OpenStack
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-openstack-cloud-provider", __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_openstack")
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,129 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module OpenStack
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 to destroy the remote machine.
12
+ def self.action_destroy
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use ConfigValidate
15
+ b.use Call, IsCreated do |env, b2|
16
+ if !env[:result]
17
+ b2.use MessageNotCreated
18
+ next
19
+ end
20
+
21
+ b2.use ConnectOpenStack
22
+ b2.use DeleteServer
23
+ end
24
+ end
25
+ end
26
+
27
+ # This action is called to read the SSH info of the machine. The
28
+ # resulting state is expected to be put into the `:machine_ssh_info`
29
+ # key.
30
+ def self.action_read_ssh_info
31
+ Vagrant::Action::Builder.new.tap do |b|
32
+ b.use ConfigValidate
33
+ b.use Call, ReadSSHInfoFromCache do |env, b2|
34
+ if !env[:machine_ssh_info]
35
+ b2.use ConnectOpenStack
36
+ b2.use ReadSSHInfoFromAPI
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # This action is called to read the state of the machine. The
43
+ # resulting state is expected to be put into the `:machine_state_id`
44
+ # key.
45
+ def self.action_read_state
46
+ Vagrant::Action::Builder.new.tap do |b|
47
+ b.use ConfigValidate
48
+ b.use ConnectOpenStack
49
+ b.use ReadState
50
+ end
51
+ end
52
+
53
+ def self.action_ssh
54
+ Vagrant::Action::Builder.new.tap do |b|
55
+ b.use ConfigValidate
56
+ b.use Call, IsCreated do |env, b2|
57
+ if !env[:result]
58
+ b2.use MessageNotCreated
59
+ next
60
+ end
61
+
62
+ b2.use SSHExec
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.action_ssh_run
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Call, IsCreated do |env, b2|
71
+ if !env[:result]
72
+ b2.use MessageNotCreated
73
+ next
74
+ end
75
+
76
+ b2.use SSHRun
77
+ end
78
+ end
79
+ end
80
+
81
+ def self.action_up
82
+ Vagrant::Action::Builder.new.tap do |b|
83
+ b.use defined?(HandleBox) ? HandleBox : HandleBoxUrl
84
+ b.use ConfigValidate
85
+ b.use Call, IsCreated do |env, b2|
86
+ if env[:result]
87
+ b2.use MessageAlreadyCreated
88
+ next
89
+ end
90
+
91
+ b2.use ConnectOpenStack
92
+ b2.use Provision
93
+ b2.use SyncFolders
94
+ b2.use SetHostname
95
+ b2.use CreateServer
96
+ end
97
+ end
98
+ end
99
+
100
+ def self.action_provision
101
+ Vagrant::Action::Builder.new.tap do |b|
102
+ b.use ConfigValidate
103
+ b.use Call, IsCreated do |env, b2|
104
+ if !env[:result]
105
+ b2.use MessageNotCreated
106
+ next
107
+ end
108
+
109
+ b2.use Provision
110
+ b2.use SyncFolders
111
+ end
112
+ end
113
+ end
114
+
115
+ # The autoload farm
116
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
117
+ autoload :ConnectOpenStack, action_root.join("connect_openstack")
118
+ autoload :CreateServer, action_root.join("create_server")
119
+ autoload :DeleteServer, action_root.join("delete_server")
120
+ autoload :IsCreated, action_root.join("is_created")
121
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
122
+ autoload :MessageNotCreated, action_root.join("message_not_created")
123
+ autoload :ReadSSHInfoFromAPI, action_root.join("read_ssh_info_from_api")
124
+ autoload :ReadSSHInfoFromCache, action_root.join("read_ssh_info_from_cache")
125
+ autoload :ReadState, action_root.join("read_state")
126
+ autoload :SyncFolders, action_root.join("sync_folders")
127
+ end
128
+ end
129
+ end