vagrant-openstack-provider 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Appraisals +13 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +22 -0
  7. data/RELEASE.md +15 -0
  8. data/Rakefile +21 -0
  9. data/Vagrantfile +37 -0
  10. data/dummy.box +0 -0
  11. data/example_box/README.md +13 -0
  12. data/example_box/metadata.json +3 -0
  13. data/features/provision.feature +35 -0
  14. data/features/steps/sdk_steps.rb +13 -0
  15. data/features/steps/server_steps.rb +25 -0
  16. data/features/support/env.rb +37 -0
  17. data/features/support/fog_mock.rb +19 -0
  18. data/features/vagrant-openstack.feature +70 -0
  19. data/gemfiles/latest_stable.gemfile +13 -0
  20. data/gemfiles/oldest_current.gemfile +13 -0
  21. data/gemfiles/previous_release.gemfile +13 -0
  22. data/lib/vagrant-openstack.rb +53 -0
  23. data/lib/vagrant-openstack/action.rb +123 -0
  24. data/lib/vagrant-openstack/action/connect_openstack.rb +30 -0
  25. data/lib/vagrant-openstack/action/create_server.rb +134 -0
  26. data/lib/vagrant-openstack/action/delete_server.rb +26 -0
  27. data/lib/vagrant-openstack/action/is_created.rb +16 -0
  28. data/lib/vagrant-openstack/action/message_already_created.rb +16 -0
  29. data/lib/vagrant-openstack/action/message_not_created.rb +16 -0
  30. data/lib/vagrant-openstack/action/read_ssh_info.rb +52 -0
  31. data/lib/vagrant-openstack/action/read_state.rb +40 -0
  32. data/lib/vagrant-openstack/action/sync_folders.rb +125 -0
  33. data/lib/vagrant-openstack/config.rb +229 -0
  34. data/lib/vagrant-openstack/errors.rb +36 -0
  35. data/lib/vagrant-openstack/openstack_client.rb +91 -0
  36. data/lib/vagrant-openstack/plugin.rb +37 -0
  37. data/lib/vagrant-openstack/provider.rb +50 -0
  38. data/lib/vagrant-openstack/version.rb +5 -0
  39. data/locales/en.yml +85 -0
  40. data/spec/vagrant-openstack/config_spec.rb +184 -0
  41. data/stackrc +32 -0
  42. data/vagrant-openstack.gemspec +23 -0
  43. metadata +135 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 908865e1b9897b7afc639fc22442dc8839fc42c4
4
+ data.tar.gz: 5a0fc9107ecb65364814134334f55cb4726ac79a
5
+ SHA512:
6
+ metadata.gz: 62965f062fae64f384161b82655ebf4cd5de23ef2c35cbf33b98e4ed8351ced68b2d2b10f038cffde84594bab4bcec43858ba3432bb4c02b234b3d3d0eb353e3
7
+ data.tar.gz: 81f7486115cfc6903455c737f8eacada8b19161e7763fa3964d8a38c2d06de6b8087be01b0663742954caea0dccabe9ec6b5b0551854d52450a8017e0e69d01d
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.iml
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .vagrant
7
+ .yardoc
8
+ Gemfile.lock
9
+ gemfiles/*.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ .venv
22
+ .idea/
@@ -0,0 +1,13 @@
1
+ appraise "latest-stable" do
2
+ gem "vagrant", :git => 'git://github.com/mitchellh/vagrant.git', :branch => 'v1.4.2'
3
+ end
4
+
5
+ # Oldest (current release)
6
+ appraise "oldest-current" do
7
+ gem "vagrant", :git => 'git://github.com/mitchellh/vagrant.git', :branch => 'v1.4.0'
8
+ end
9
+
10
+ # Latest patch (previous release)
11
+ appraise "previous-release" do
12
+ gem "vagrant", :git => 'git://github.com/mitchellh/vagrant.git', :branch => 'v1.3.5'
13
+ end
@@ -0,0 +1,5 @@
1
+ # 0.1 (April 24, 2014)
2
+
3
+ BUG FIXES:
4
+
5
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "appraisal", "1.0.0"
6
+ gem "restclient", "0.10.0"
7
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"
8
+
9
+ group :development do
10
+ # We depend on Vagrant for development, but we don't add it as a
11
+ # gem dependency because we expect to be installed within the
12
+ # Vagrant environment itself using `vagrant plugin`.
13
+ gem 'coveralls', require: false
14
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mitchell Hashimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ 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.
@@ -0,0 +1,15 @@
1
+ # Release process
2
+
3
+ This is vagrant-openstack-provider's current release process, documented so people know what is
4
+ currently done.
5
+
6
+ ## Prepare the release
7
+
8
+ * Update the version in "lib/vagrant-openstack/version.rb"
9
+ * Update the version in CHANGELOG.md
10
+ * Use "rake release". This will make sure to tag that commit and push it RubyGems.
11
+ * Update the version again in both files to a dev version for working again.
12
+
13
+ The CHANGELOG.md should be maintained in a similar format to Vagrant:
14
+
15
+ https://github.com/mitchellh/vagrant/blob/master/CHANGELOG.md
@@ -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"
@@ -0,0 +1,37 @@
1
+ require 'vagrant-openstack'
2
+
3
+ Vagrant.configure("2") do |config|
4
+
5
+ config.vm.box = "dummy-openstack"
6
+ config.vm.box_url = "https://github.com/ggiamarchi/vagrant-openstack-plugin/raw/new_version/source/dummy.box"
7
+
8
+ config.ssh.private_key_path = "/home/vagrant/.ssh/id_rsa"
9
+ config.ssh.shell = "sh"
10
+
11
+ config.vm.provider :openstack do |os|
12
+
13
+ os.server_name = "vagrant-os-plugin-test"
14
+ os.username = ENV['OS_USERNAME']
15
+ os.floating_ip = "185.39.216.118"
16
+ os.api_key = ENV['OS_PASSWORD']
17
+ #os.network = "private"
18
+ os.flavor = /Linux-XL.2plus-4vCpu-32G/
19
+ os.image = /ubuntu-12.04_x86_64_LVM/
20
+ os.openstack_auth_url = ENV['OS_AUTH_URL']
21
+ os.openstack_compute_url = ENV['OS_COMPUTE_URL']
22
+ os.availability_zone = "nova"
23
+ os.tenant_name = ENV['OS_TENANT_NAME']
24
+ os.keypair_name = "julien-vagrant"
25
+ os.ssh_username = "stack"
26
+
27
+ # os.metadata = {"key" => "value"} # optional
28
+ # os.user_data = "#cloud-config\nmanage_etc_hosts: True" # optional
29
+ # os.networks = [ "internal", "external" ] # optional, overrides os.network
30
+ # os.address_id = "YOUR ADDRESS ID" # optional (`network` above has higher precedence)
31
+ # os.scheduler_hints = {
32
+ # :cell => 'australia'
33
+ # } # optional
34
+ # os.security_groups = ['ssh', 'http'] # optional
35
+
36
+ end
37
+ end
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,35 @@
1
+ @announce
2
+ @vagrant-openstack
3
+ Feature: vagrant-openstack fog tests
4
+
5
+ Background:
6
+ Given I have Openstack credentials available
7
+ And I have a "fog_mock.rb" file
8
+
9
+ Scenario: Create a single server (with provisioning)
10
+ Given a file named "Vagrantfile" with:
11
+ """
12
+ Vagrant.configure("2") do |config|
13
+ Vagrant.require_plugin "vagrant-openstack"
14
+
15
+ config.vm.box = "dummy"
16
+ config.ssh.private_key_path = "~/.ssh/id_rsa"
17
+
18
+
19
+ config.vm.provider :openstack do |rs|
20
+ rs.server_name = 'vagrant-provisioned-server'
21
+ rs.username = ENV['RAX_USERNAME']
22
+ rs.api_key = ENV['RAX_API_KEY']
23
+ rs.openstack_region = ENV['RAX_REGION'].downcase.to_sym
24
+ rs.flavor = /1 GB Performance/
25
+ rs.image = /Ubuntu/
26
+ rs.public_key_path = "~/.ssh/id_rsa.pub"
27
+ end
28
+
29
+ config.vm.provision :shell, :inline => "echo Hello, World"
30
+ end
31
+ """
32
+ When I successfully run `bundle exec vagrant up --provider openstack`
33
+ # I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
34
+ # And I get the server from "Instance ID:"
35
+ Then the server "vagrant-provisioned-server" should be active
@@ -0,0 +1,13 @@
1
+ Given(/^I have Openstack credentials available$/) do
2
+ fail unless ENV['RAX_USERNAME'] && ENV['RAX_API_KEY']
3
+ end
4
+
5
+ Given(/^I have a "fog_mock.rb" file$/) do
6
+ script = File.open("features/support/fog_mock.rb").read
7
+ steps %Q{
8
+ Given a file named "fog_mock.rb" with:
9
+ """
10
+ #{script}
11
+ """
12
+ }
13
+ end
@@ -0,0 +1,25 @@
1
+ When(/^I get the server from "(.*?)"$/) do |label|
2
+ @server_id = all_output.match(/#{label}\s([\w-]*)/)[1]
3
+ puts "Server: #{@server_id}"
4
+ end
5
+
6
+ When(/^I load the server$/) do
7
+ @server_id = all_output.strip.lines.to_a.last
8
+ puts "Server: #{@server_id}"
9
+ end
10
+
11
+ Then(/^the server should be active$/) do
12
+ unless Fog.mock? # unfortunately we can't assert this with Fog.mock!, since mocked objects do not persist from the subprocess
13
+ assert_active @server_id
14
+ end
15
+ end
16
+
17
+ Then(/^the server "(.+)" should be active$/) do |server_name|
18
+ server = @compute.servers.all.find{|s| s.name == server_name}
19
+ assert_active server.id
20
+ end
21
+
22
+ def assert_active server_id
23
+ server = @compute.servers.get server_id
24
+ server.state.should == 'ACTIVE'
25
+ end
@@ -0,0 +1,37 @@
1
+ require 'fog'
2
+ require 'aruba/cucumber'
3
+
4
+ Fog.mock! if ENV['RAX_MOCK'] == 'true'
5
+
6
+ Before do | scenario |
7
+ @aruba_timeout_seconds = 600
8
+ @scenario = File.basename(scenario.file)
9
+ ENV['CASSETTE'] = @scenario
10
+
11
+ proxy_options = {
12
+ :connection_options => {
13
+ :proxy => ENV['https_proxy'],
14
+ :ssl_verify_peer => false
15
+ }
16
+ }
17
+
18
+ connect_options = {
19
+ :provider => 'openstack',
20
+ :openstack_username => ENV['RAX_USERNAME'],
21
+ :openstack_api_key => ENV['RAX_API_KEY'],
22
+ :version => :v2, # Use Next Gen Cloud Servers
23
+ :openstack_region => ENV['RAX_REGION'].downcase.to_sym
24
+ }
25
+ connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
26
+ @compute = Fog::Compute.new(connect_options)
27
+ end
28
+
29
+ Around do | scenario, block |
30
+ Bundler.with_clean_env do
31
+ block.call
32
+ end
33
+ end
34
+
35
+ After('@creates_server') do
36
+ @compute.servers.delete @server_id
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'fog'
2
+ if ENV['RAX_MOCK'] == 'true'
3
+ Fog.mock!
4
+ Fog::Openstack::MockData.configure do |c|
5
+ c[:image_name_generator] = Proc.new { "Ubuntu" }
6
+ c[:ipv4_generator] = Proc.new { "10.11.12.2"}
7
+ end
8
+ connect_options = {
9
+ :provider => 'openstack',
10
+ :openstack_username => ENV['RAX_USERNAME'],
11
+ :openstack_api_key => ENV['RAX_API_KEY'],
12
+ :version => :v2, # Use Next Gen Cloud Servers
13
+ :openstack_region => :ord #Use Chicago Region
14
+ }
15
+ connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
16
+ compute = Fog::Compute.new(connect_options)
17
+ # Force creation of Ubuntu image so it will show up in compute.images.list
18
+ compute.images.get(0)
19
+ end
@@ -0,0 +1,70 @@
1
+ @announce
2
+ @vagrant-openstack
3
+ Feature: vagrant-openstack fog tests
4
+ As a Fog developer
5
+ I want to smoke (or "fog") test vagrant-openstack.
6
+ So I am confident my upstream changes did not create downstream problems.
7
+
8
+ Background:
9
+ Given I have Openstack credentials available
10
+ And I have a "fog_mock.rb" file
11
+
12
+ Scenario: Create a single server (region)
13
+ Given a file named "Vagrantfile" with:
14
+ """
15
+ # Testing options
16
+ require File.expand_path '../fog_mock', __FILE__
17
+
18
+ Vagrant.configure("2") do |config|
19
+ # dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-openstack'
20
+ Vagrant.require_plugin "vagrant-openstack"
21
+
22
+ config.vm.box = "dummy"
23
+ config.ssh.username = "vagrant" if Fog.mock?
24
+ config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
25
+
26
+ config.vm.provider :openstack do |rs|
27
+ rs.server_name = 'vagrant-single-server'
28
+ rs.username = ENV['RAX_USERNAME']
29
+ rs.api_key = ENV['RAX_API_KEY']
30
+ rs.openstack_region = ENV['RAX_REGION'].downcase.to_sym
31
+ rs.flavor = /1 GB Performance/
32
+ rs.image = /Ubuntu/
33
+ rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
34
+ end
35
+ end
36
+ """
37
+ When I successfully run `bundle exec vagrant up --provider openstack`
38
+ # I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
39
+ # And I get the server from "Instance ID:"
40
+ Then the server "vagrant-single-server" should be active
41
+
42
+ Scenario: Create a single server (openstack_compute_url)
43
+ Given a file named "Vagrantfile" with:
44
+ """
45
+ # Testing options
46
+ require File.expand_path '../fog_mock', __FILE__
47
+
48
+ Vagrant.configure("2") do |config|
49
+ # dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-openstack'
50
+ Vagrant.require_plugin "vagrant-openstack"
51
+
52
+ config.vm.box = "dummy"
53
+ config.ssh.username = "vagrant" if Fog.mock?
54
+ config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
55
+
56
+ config.vm.provider :openstack do |rs|
57
+ rs.server_name = 'vagrant-single-server'
58
+ rs.username = ENV['RAX_USERNAME']
59
+ rs.api_key = ENV['RAX_API_KEY']
60
+ rs.openstack_compute_url = "https://#{ENV['RAX_REGION'].downcase}.servers.api.openstackcloud.com/v2"
61
+ rs.flavor = /1 GB Performance/
62
+ rs.image = /Ubuntu/
63
+ rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
64
+ end
65
+ end
66
+ """
67
+ When I successfully run `bundle exec vagrant up --provider openstack`
68
+ # I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
69
+ # And I get the server from "Instance ID:"
70
+ Then the server "vagrant-single-server" should be active
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "1.0.0"
6
+ gem "restclient", "0.10.0"
7
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"
8
+
9
+ group :development do
10
+ gem "coveralls", :require => false
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "1.0.0"
6
+ gem "restclient", "0.10.0"
7
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"
8
+
9
+ group :development do
10
+ gem "coveralls", :require => false
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "1.0.0"
6
+ gem "restclient", "0.10.0"
7
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"
8
+
9
+ group :development do
10
+ gem "coveralls", :require => false
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-openstack/plugin"
4
+
5
+ module VagrantPlugins
6
+ module Openstack
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-openstack", __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