vagrant-chef-zero 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +5 -0
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG.md +37 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE.txt +18 -0
  6. data/Makefile +15 -0
  7. data/README.md +68 -0
  8. data/Rakefile +31 -0
  9. data/Vagrantfile +17 -0
  10. data/coverage/.last_run.json +5 -0
  11. data/coverage/.resultset.json +125 -0
  12. data/lib/vagrant-chef-zero/action/default.rb +1 -0
  13. data/lib/vagrant-chef-zero/action/reconfig.rb +38 -0
  14. data/lib/vagrant-chef-zero/action/start.rb +28 -0
  15. data/lib/vagrant-chef-zero/action/stop.rb +27 -0
  16. data/lib/vagrant-chef-zero/action/upload.rb +154 -0
  17. data/lib/vagrant-chef-zero/action.rb +43 -0
  18. data/lib/vagrant-chef-zero/config.rb +61 -0
  19. data/lib/vagrant-chef-zero/env.rb +15 -0
  20. data/lib/vagrant-chef-zero/env_helpers.rb +105 -0
  21. data/lib/vagrant-chef-zero/plugin.rb +53 -0
  22. data/lib/vagrant-chef-zero/server_helpers.rb +44 -0
  23. data/lib/vagrant-chef-zero/version.rb +5 -0
  24. data/lib/vagrant-chef-zero.rb +15 -0
  25. data/spec/lib/server_helpers_spec.rb +65 -0
  26. data/spec/spec_helper.rb +21 -0
  27. data/spec/vagrant-chef-zero/fixtures/cookbooks/blah/metadata.rb +3 -0
  28. data/spec/vagrant-chef-zero/fixtures/cookbooks/blah/recipes/default.rb +1 -0
  29. data/spec/vagrant-chef-zero/fixtures/cookbooks/blah/templates/default/hi +1 -0
  30. data/spec/vagrant-chef-zero/fixtures/cookbooks/blork/recipes/default.rb +1 -0
  31. data/spec/vagrant-chef-zero/fixtures/cookbooks/blork/templates/default/hi +1 -0
  32. data/spec/vagrant-chef-zero/fixtures/data_bags/foo/bar.json +1 -0
  33. data/spec/vagrant-chef-zero/fixtures/data_bags/foo/baz.json +1 -0
  34. data/spec/vagrant-chef-zero/fixtures/data_bags/foo/blarghle.json +1 -0
  35. data/spec/vagrant-chef-zero/fixtures/data_bags/foom/x.json +5 -0
  36. data/spec/vagrant-chef-zero/fixtures/data_bags/widdle/blank.json +1 -0
  37. data/spec/vagrant-chef-zero/fixtures/data_bags/widdle/wow.json +1 -0
  38. data/spec/vagrant-chef-zero/fixtures/environments/desert.json +13 -0
  39. data/spec/vagrant-chef-zero/fixtures/environments/rainforest.json +13 -0
  40. data/spec/vagrant-chef-zero/fixtures/environments/semi_arid_plains.json +13 -0
  41. data/spec/vagrant-chef-zero/fixtures/nodes/blah.json +7 -0
  42. data/spec/vagrant-chef-zero/fixtures/nodes/blarrrrgh.json +7 -0
  43. data/spec/vagrant-chef-zero/fixtures/nodes/boxer.json +7 -0
  44. data/spec/vagrant-chef-zero/fixtures/nodes/camel.json +7 -0
  45. data/spec/vagrant-chef-zero/fixtures/nodes/monkey.json +7 -0
  46. data/vagrant-chef-zero.gemspec +74 -0
  47. metadata +292 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.lock
2
+ .vagrant
3
+ pkg
4
+ coverage
5
+ Berksfile
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ gemfile:
5
+ - Gemfile
6
+ branches:
7
+ only:
8
+ - master
data/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ ## 0.2.10
2
+
3
+ * Fix bug where we could find multiple gem paths with 'vagrant' in them, causing the construction of an erroneous Chef Zero binary path. Fixes [#10](https://github.com/andrewgross/vagrant-chef-zero/issues/10)
4
+
5
+ ## 0.2.9
6
+
7
+ * Fix Berkshelf support by being selfish and putting Chef Zero before Berkshelf (and anything else) in the load order for `up`, `provision` and `reload`
8
+
9
+
10
+ ## 0.2.8
11
+
12
+ * Fix Berkshelf support by monkeypatching `client_key` in all Berkshelf Objects
13
+
14
+
15
+ ## 0.2.7
16
+
17
+ * Re-add ActiveSupport dependency because otherwise the plugin cannot install correctly in Vagrant.
18
+
19
+
20
+ ## 0.2.6
21
+
22
+ * Remove unused ActiveSupport dependency.
23
+ * Add MIT License
24
+
25
+
26
+ ## 0.2.5
27
+
28
+ * Fix bug where the PID of the Chef-Zero server could not be found due to inconsistencies in the process name across operating systems. Fixes [#11](https://github.com/andrewgross/vagrant-chef-zero/issues/11)
29
+
30
+ ## 0.2.4
31
+
32
+ * Fix bug where `chef-zero` binary could not be found in RVM environments. `vagrant-chef-zero` will now search the GEM_PATH for 'vagrant' and extrapolate to `bin/chef-zero` accordingly. Fixes [#8](https://github.com/andrewgross/vagrant-chef-zero/pull/8)
33
+
34
+ ## 0.2.3
35
+
36
+ * Initial Beta Release with support for *NIX variants
37
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'json', '~> 1.7.7'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ # We depend on Vagrant for development, but we don't add it as a
9
+ # gem dependency because we expect to be installed within the
10
+ # Vagrant environment itself using `vagrant plugin`.
11
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
12
+ gem "debugger"
13
+ gem "vagrant-berkshelf", ">= 1.3.3"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013 Andrew Gross
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,15 @@
1
+ all: clean install test
2
+
3
+ install:
4
+ @bundle install
5
+
6
+ clean:
7
+ @bundle exec rake clean
8
+ test:
9
+ @bundle exec rake test
10
+
11
+ vagrant:
12
+ @bundle exec vagrant up
13
+
14
+ release:
15
+ @bundle exec rake release
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Vagrant-Chef-Zero
2
+ [![Build Status](https://travis-ci.org/andrewgross/vagrant-chef-zero.png)](https://travis-ci.org/andrewgross/vagrant-chef-zero)
3
+ [![Code Climate](https://codeclimate.com/repos/51e419cc89af7e3a2a003663/badges/c7a21cef56cddb54ab12/gpa.png)](https://codeclimate.com/repos/51e419cc89af7e3a2a003663/feed)
4
+ [![Dependency Status](https://gemnasium.com/andrewgross/vagrant-chef-zero.png)](https://gemnasium.com/andrewgross/vagrant-chef-zero)
5
+ [![Coverage Status](https://coveralls.io/repos/andrewgross/vagrant-chef-zero/badge.png)](https://coveralls.io/r/andrewgross/vagrant-chef-zero)
6
+
7
+ This is a plugin designed to help integrate Chef-Zero into a Vagrant run, similar to Berkshelf. Chef-Zero will be started on the host machine and populated with the specified data. When the Vagrant machine is destroyed Chef-Zero will be killed.
8
+
9
+ Note: Only NIX systems supported at this time due to a call to `lsof` to find running Chef Zero servers.
10
+
11
+ ### Installation
12
+
13
+ ```bash
14
+ vagrant plugin install vagrant-chef-zero
15
+ ```
16
+
17
+ ### Compatability
18
+
19
+ Currently only NIX systems supported at this time due to a call to `lsof` to find running Chef Zero servers.
20
+
21
+ As for Vagrant providers, it has only been tested with VirtualBox. It should be possible to add support for other providers by changing certain assumptions, such as always running Chef-Zero on the host machine.
22
+
23
+ ### Activation
24
+
25
+ Just set your Vagrant provisioner to `:chef_client`. If you wish to use `:chef_client` without using `vagrant-chef-zero` just set `config.chef_zero.enabled = false` inside your Vagrantfile configuration block.
26
+
27
+ ### Configuration
28
+
29
+ Inside of your Vagrant file you will have access to the following configuration options:
30
+
31
+ ```ruby
32
+ config.chef_zero.nodes = "../foobar/nodes"
33
+ config.chef_zero.environments = "../foobar/environments/baz.json"
34
+ config.chef_zero.data_bags = "../foobar/data_bags"
35
+ config.chef_zero.roles = "../foobar/roles/*.json"
36
+ config.chef_zero.cookbooks = "spec/fixtures/cookbooks"
37
+ ```
38
+
39
+ As Vagrant is booting up, `vagrant-chef-zero` will search each specified location for files to upload to Chef-Zero. The upload will be done via Ridley APIs.
40
+
41
+ Check out the included [Vagrantfile](https://github.com/andrewgross/vagrant-chef-zero/blob/master/Vagrantfile) for example usage.
42
+
43
+ ### Cookbooks
44
+
45
+ These are uploaded via the `Ridley` gem. It is the same backend that `Berkshelf` uses, though I am sure my usage is not as complete. It expects a path to a `cookbooks/` directory, or an array of paths to individual cookbooks. If you omit this field, you can have `Berkshelf` upload cookbooks as usual (It will find the Chef-Zero URL automatically).
46
+
47
+ ### JSON vs `.rb`
48
+
49
+ Currently only JSON files are supported as we do not have the Chef libraries to serialize `.rb` files.
50
+
51
+ ### Lingering Chef-Zero Servers
52
+
53
+ If for some reason you are unable to have Vagrant destroy the Chef-Zero server, you can find the PID it by running `lsof -i tcp:#{port}` where `port` is 4000 by default.
54
+
55
+ ## Chef Server Configuration
56
+
57
+ ### Authentication
58
+
59
+ None! `vagrant-chef-zero` performs some ruby black magic to generate a fake RSA key and patch it in to the `chef-client` configuration. You should not need to worry about providing `validation_key_path`.
60
+
61
+ ### URL
62
+
63
+ You don't need to specify one! If no url is specified, `Vagrant-Chef-Zero` will find your local IPv4 address and bind to it, on port `4000`. If you specify a Chef Server url, `Vagrant-Chef-Zero` will try to parse it and bind appropriately.
64
+
65
+ ### Validation Client Name
66
+
67
+ Not required. As `Chef-Zero` does no authentication we can fake this. If it is left unspecified we will use a default value of `dummy-validator`.
68
+
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
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
+ # Default task is to run the unit tests
18
+ task :default => "test"
19
+
20
+ Rake::TestTask.new do |t|
21
+ t.pattern = 'spec/**/*_spec.rb'
22
+ end
23
+
24
+ task :clean do |t|
25
+ require 'fileutils'
26
+ FileUtils.rm_rf 'pkg'
27
+ system('bundle exec vagrant destroy -f')
28
+ FileUtils.rm_rf '.vagrant'
29
+ FileUtils.rm_rf 'coverage'
30
+ FileUtils.rm_rf 'Gemfile.lock'
31
+ end
data/Vagrantfile ADDED
@@ -0,0 +1,17 @@
1
+ Vagrant.require_plugin "vagrant-chef-zero"
2
+ Vagrant.require_plugin "vagrant-berkshelf"
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.berkshelf.enabled = true
6
+ config.chef_zero.nodes = "spec/vagrant-chef-zero/fixtures/nodes"
7
+ config.chef_zero.environments = "spec/vagrant-chef-zero/fixtures/environments"
8
+ config.chef_zero.data_bags = "spec/vagrant-chef-zero/fixtures/data_bags"
9
+ config.chef_zero.cookbooks = "spec/vagrant-chef-zero/fixtures/cookbooks"
10
+ config.chef_zero.roles = "foobar"
11
+
12
+ config.vm.box = ENV['YIPIT_VAGRANT_BOX']
13
+ config.vm.provision :chef_client do |chef|
14
+ chef.run_list = [
15
+ ]
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "result": {
3
+ "covered_percent": 56.67
4
+ }
5
+ }
@@ -0,0 +1,125 @@
1
+ {
2
+ "RSpec": {
3
+ "coverage": {
4
+ "/Users/andrewgross/dev/andrew/vagrant-chef-zero/lib/vagrant-chef-zero.rb": [
5
+ 1,
6
+ 1,
7
+ null,
8
+ 0,
9
+ null,
10
+ null,
11
+ 1,
12
+ 1,
13
+ 1,
14
+ 1,
15
+ 1,
16
+ null,
17
+ null,
18
+ null,
19
+ 1
20
+ ],
21
+ "/Users/andrewgross/dev/andrew/vagrant-chef-zero/lib/vagrant-chef-zero/plugin.rb": [
22
+ 1,
23
+ null,
24
+ null,
25
+ null,
26
+ 1,
27
+ 0,
28
+ null,
29
+ null,
30
+ 1,
31
+ 1,
32
+ 1,
33
+ null,
34
+ 1,
35
+ 1,
36
+ 0,
37
+ 0,
38
+ null,
39
+ null,
40
+ 1,
41
+ 0,
42
+ null,
43
+ null,
44
+ 1,
45
+ 0,
46
+ null,
47
+ null,
48
+ null,
49
+ null,
50
+ 1,
51
+ null,
52
+ null,
53
+ null,
54
+ 1,
55
+ null,
56
+ null,
57
+ 1,
58
+ null,
59
+ 1,
60
+ null,
61
+ 1,
62
+ null,
63
+ 1,
64
+ null,
65
+ 1,
66
+ null,
67
+ 1,
68
+ 0,
69
+ 0,
70
+ null,
71
+ null,
72
+ null,
73
+ null,
74
+ null
75
+ ],
76
+ "/Users/andrewgross/dev/andrew/vagrant-chef-zero/lib/vagrant-chef-zero/server_helpers.rb": [
77
+ 1,
78
+ 1,
79
+ 1,
80
+ null,
81
+ 1,
82
+ 0,
83
+ 0,
84
+ 0,
85
+ 0,
86
+ 0,
87
+ 0,
88
+ 0,
89
+ null,
90
+ 0,
91
+ 0,
92
+ 0,
93
+ null,
94
+ null,
95
+ null,
96
+ 1,
97
+ 0,
98
+ 0,
99
+ 0,
100
+ 0,
101
+ 0,
102
+ null,
103
+ null,
104
+ null,
105
+ 1,
106
+ 2,
107
+ 2,
108
+ null,
109
+ null,
110
+ 1,
111
+ 0,
112
+ 0,
113
+ 0,
114
+ null,
115
+ null,
116
+ null,
117
+ null,
118
+ null,
119
+ null,
120
+ null
121
+ ]
122
+ },
123
+ "timestamp": 1374073965
124
+ }
125
+ }
@@ -0,0 +1 @@
1
+ default.rb
@@ -0,0 +1,38 @@
1
+ module VagrantPlugins
2
+ module ChefZero
3
+ module Action
4
+
5
+ class Reconfig
6
+
7
+ include VagrantPlugins::ChefZero::EnvHelpers
8
+ include VagrantPlugins::ChefZero::ServerHelpers
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+
13
+ if chef_zero_enabled?(env)
14
+ @key = get_key_path(env)
15
+ set_config("@validation_key_path", @key, env)
16
+
17
+ @chef_server_url = get_chef_server_url(env)
18
+ set_config("@chef_server_url", @chef_server_url, env)
19
+
20
+ @validation_client_name = get_validation_client_name(env)
21
+ set_config("@validation_client_name", @validation_client_name, env)
22
+ end
23
+
24
+ if berkshelf_enabled?(env)
25
+ @key = get_key_path(env)
26
+ set_berkshelf_client_key(@key)
27
+ end
28
+ end
29
+
30
+ def call(env)
31
+ @app.call(env)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ module VagrantPlugins
2
+ module ChefZero
3
+ module Action
4
+
5
+ class Start
6
+
7
+ include VagrantPlugins::ChefZero::EnvHelpers
8
+ include VagrantPlugins::ChefZero::ServerHelpers
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @key = get_key_path(env)
13
+ end
14
+
15
+ def call(env)
16
+ unless chef_zero_enabled?(env)
17
+ return @app.call(env)
18
+ end
19
+
20
+ start_chef_zero(env)
21
+ @app.call(env)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module VagrantPlugins
2
+ module ChefZero
3
+ module Action
4
+
5
+ class Stop
6
+
7
+ include VagrantPlugins::ChefZero::EnvHelpers
8
+ include VagrantPlugins::ChefZero::ServerHelpers
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @key = get_key_path(env)
13
+ end
14
+
15
+ def call(env)
16
+ unless chef_zero_enabled?(env)
17
+ return @app.call(env)
18
+ end
19
+ stop_chef_zero(env)
20
+ @app.call(env)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,154 @@
1
+ module VagrantPlugins
2
+ module ChefZero
3
+ module Action
4
+
5
+ class Upload
6
+
7
+ include VagrantPlugins::ChefZero::EnvHelpers
8
+ include VagrantPlugins::ChefZero::ServerHelpers
9
+
10
+ def initialize(app, env)
11
+ @conn = nil
12
+ @app = app
13
+ @env = env
14
+ @url = server_info(env)[:host]
15
+ @client_name = server_info(env)[:client_name]
16
+ @client_key = server_info(env)[:client_key]
17
+ end
18
+
19
+ def call(env)
20
+ unless chef_zero_enabled?(env)
21
+ return @app.call(env)
22
+ end
23
+
24
+ setup_connection
25
+ upload_cookbooks(env)
26
+ upload_environments(env)
27
+ upload_roles(env)
28
+ upload_nodes(env)
29
+ upload_data_bags(env)
30
+ @app.call(env)
31
+ end
32
+
33
+ def upload_cookbooks(env)
34
+ path = env[:machine].config.chef_zero.cookbooks
35
+ cookbooks = select_items(path)
36
+ env[:chef_zero].ui.info("Loading cookbooks from #{path}") unless cookbooks.empty?
37
+ cookbooks.each do |cookbook|
38
+ name = File.basename(cookbook)
39
+ env[:chef_zero].ui.info("Uploading Cookbook #{name}")
40
+ @conn.cookbook.upload(cookbook, options: {name: name})
41
+ end
42
+ end
43
+
44
+ def upload_nodes(env)
45
+ path = env[:machine].config.chef_zero.nodes
46
+ existing_nodes = @conn.node.all
47
+
48
+ nodes = select_items(path)
49
+ nodes.each do |n|
50
+ node = JSON.parse(IO.read(n)).to_hash
51
+ if ! existing_nodes.any?{ |e| e['name'] == node['name'] }
52
+ env[:chef_zero].ui.info("Creating Node #{node['name']}")
53
+ @conn.node.create(node)
54
+ else
55
+ env[:chef_zero].ui.info("Updating Node #{node['name']}")
56
+ @conn.node.update(node)
57
+ end
58
+ end
59
+ end
60
+
61
+ def upload_environments(env)
62
+ path = env[:machine].config.chef_zero.environments
63
+ existing_envs = @conn.environment.all
64
+
65
+ environments = select_items(path)
66
+ environments.each do |e|
67
+ environment = JSON.parse(IO.read(e)).to_hash
68
+ if ! existing_envs.any?{ |ee| ee['name'] == environment['name'] }
69
+ env[:chef_zero].ui.info("Creating Environment #{environment['name']}")
70
+ @conn.environment.create(environment)
71
+ else
72
+ env[:chef_zero].ui.info("Updating Environment #{environment['name']}")
73
+ @conn.environment.update(environment)
74
+ end
75
+ end
76
+ end
77
+
78
+ def upload_roles(env)
79
+ path = env[:machine].config.chef_zero.roles
80
+ existing_roles = @conn.role.all
81
+
82
+ roles = select_items(path)
83
+ roles.each do |r|
84
+ role = JSON.parse(IO.read(r)).to_hash
85
+ if ! existing_roles.any?{ |er| er['name'] == role['name'] }
86
+ env[:chef_zero].ui.info("Creating role #{role['name']}")
87
+ @conn.role.create(role)
88
+ else
89
+ env[:chef_zero].ui.info("Updating role #{role['name']}")
90
+ @conn.role.update(role)
91
+ end
92
+ end
93
+ end
94
+
95
+ def upload_data_bags(env)
96
+ path = env[:machine].config.chef_zero.data_bags
97
+ if path && path.is_a?(String) && File.directory?(path)
98
+ data_bags = Dir.glob("#{path}/*").select{|d| File.directory? d}
99
+
100
+ data_bags.each do |data_bag_dir|
101
+ bag_name = File.basename(data_bag_dir)
102
+ data_bag = @conn.data_bag.find(bag_name)
103
+ if ! data_bag
104
+ env[:chef_zero].ui.info("Creating Data Bag #{bag_name}")
105
+ data_bag = @conn.data_bag.create(name: bag_name)
106
+ end
107
+
108
+ Dir.glob("#{data_bag_dir}/*.json").each do |i|
109
+ item_as_hash = JSON.parse(IO.read(i)).to_hash
110
+ if data_bag.item.find(item_as_hash['id'])
111
+ env[:chef_zero].ui.info("Updating item #{item_as_hash['id']} in Data Bag #{bag_name}")
112
+ data_bag.item.update(item_as_hash)
113
+ else
114
+ env[:chef_zero].ui.info("Creating item #{item_as_hash['id']} in Data Bag #{bag_name}")
115
+ data_bag.item.create(item_as_hash)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ def select_items(path)
123
+ if path.nil?
124
+ path = []
125
+ elsif path.respond_to?('empty?') && path.empty?
126
+ path = []
127
+ elsif path.is_a?(Array)
128
+ path
129
+ elsif path.is_a?(String) && File.directory?(path)
130
+ path = Dir.glob("#{path}/*.json")
131
+ elsif path.is_a?(String) && File.exists?(path)
132
+ path = [path]
133
+ else
134
+ @env[:chef_zero].ui.warn("Warning: Unable to normalize #{path}, skipping")
135
+ path = []
136
+ end
137
+ path
138
+ end
139
+
140
+ def setup_connection
141
+ if ! @conn
142
+ require 'ridley'
143
+ @conn = Ridley.new(server_url: @url,
144
+ client_name: @client_name,
145
+ client_key: @client_key)
146
+ end
147
+ @conn
148
+ end
149
+
150
+ end
151
+
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,43 @@
1
+ require 'vagrant/action/builder'
2
+ require 'vagrant-chef-zero/env_helpers'
3
+ require 'vagrant-chef-zero/server_helpers'
4
+
5
+ module VagrantPlugins
6
+ module ChefZero
7
+ module Action
8
+
9
+ include Vagrant::Action::Builtin
10
+
11
+ autoload :Reconfig, 'vagrant-chef-zero/action/reconfig'
12
+ autoload :Start, 'vagrant-chef-zero/action/start'
13
+ autoload :Upload, 'vagrant-chef-zero/action/upload'
14
+ autoload :Stop, 'vagrant-chef-zero/action/stop'
15
+
16
+ def self.chef_zero_provision
17
+ Vagrant::Action::Builder.new.tap do |b|
18
+ b.use VagrantPlugins::ChefZero::Action::Start
19
+ b.use VagrantPlugins::ChefZero::Action::Upload
20
+ end
21
+ end
22
+
23
+ def self.chef_zero_destroy
24
+ Vagrant::Action::Builder.new.tap do |b|
25
+ b.use VagrantPlugins::ChefZero::Action::Stop
26
+ end
27
+ end
28
+
29
+ def self.chef_zero_reconfig
30
+ Vagrant::Action::Builder.new.tap do |b|
31
+ b.use VagrantPlugins::ChefZero::Action::Reconfig
32
+ end
33
+ end
34
+
35
+ def self.chef_zero_ui_setup
36
+ Vagrant::Action::Builder.new.tap do |b|
37
+ b.use ::Vagrant::Action::Builtin::EnvSet, chef_zero: VagrantPlugins::ChefZero::Env.new
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end