rs_vagrant_shim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ryan J. Geyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = rs_vagrant_shim
2
+
3
+ == Usage
4
+
5
+ Install it
6
+
7
+ gem install rs_vagrant_shim
8
+
9
+ Create a new project
10
+
11
+ rs_vagrant_shim a_new_project
12
+
13
+ Add some stuff to the default runlist found at a_new_project/runlists/default/default.json
14
+
15
+ Fire up the vagrant box
16
+
17
+ bundle exec vagrant up default
18
+
19
+ Create some new runlists at a_new_project/runlists/default/new_runlist.json
20
+
21
+ Run some of the other runlists by copying them to a_new_project/rs_vagrant_shim/default/dispatch
22
+
23
+ cp a_new_project/runlists/default/new_runlist.json a_new_project/rs_vagrant_shim/default/dispatch/
24
+ bundle exec vagrant provision default
25
+
26
+ Or specifying a "runlist" environment variable
27
+
28
+ runlist=new_runlist bundle exec vagrant provision default
29
+
30
+ == Bundle Exec?
31
+
32
+ So, you'll notice that your project directory contains a gemfile, and all the examples use bundle exec. This is because vagrant has a fairly poor plugin mechanism in version ~> 1.0, so we just skip it all by making sure all the necessary gems are loaded by bundler.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2013 Ryan J. Geyer
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.
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rs_vagrant_shim'))
25
+
26
+ RsVagrantShim::Cli.start(ARGV)
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'thor'
23
+ require 'vagrant'
24
+ require 'berkshelf'
25
+
26
+ glob_path = File.expand_path(File.join(File.dirname(__FILE__), 'rs_vagrant_shim')) + '/**/*.rb'
27
+ Dir.glob(glob_path, &method(:require))
28
+
29
+ locales_file = File.expand_path("../locales/en.yml", File.dirname(__FILE__))
30
+
31
+ I18n.load_path << locales_file
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # Monkey patch the berkshelf config class so it does it's magic
23
+ # even when the RsVagrantShim provisioner is used.
24
+ module Berkshelf
25
+ module Vagrant
26
+ def self.provisioners(shortcut, config)
27
+ if shortcut == :chef_solo
28
+ config.vm.provisioners.select do |prov|
29
+ prov.shortcut == :chef_solo || prov.shortcut.to_s == "Vagrant::RsVagrantShim::Provisioners::RsVagrantShim"
30
+ end
31
+ else
32
+ config.vm.provisioners.select { |prov| prov.shortcut == shortcut }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,138 @@
1
+ # Copyright (c) 2013 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module RsVagrantShim
23
+ class Cli < Thor
24
+
25
+ desc "init PROJECTNAME", "Creates a new rs_vagrant_shim project in a directory specified by PROJECTNAME, including all the goodies you need like a Berksfile, Vagrantfile, etc"
26
+ option :vmnames,
27
+ :desc => "The name of one more many VMs to add to the Vagrantfile",
28
+ :type => :array
29
+ def init(projectname)
30
+ if File.directory? projectname
31
+ puts "A directory named #{projectname} already exists, please specify a different project name"
32
+ return
33
+ else
34
+ FileUtils.mkdir_p projectname
35
+ end
36
+
37
+ vagrantfile_template = <<-EOF
38
+ require 'berkshelf/vagrant'
39
+ require 'rs_vagrant_shim'
40
+
41
+ Vagrant::Config.run do |config|
42
+ <% boxes.each do |vmname| %>
43
+ config.vm.define :<%= vmname %> do |<%= vmname %>_config|
44
+ <%= vmname %>_config.berkshelf.berksfile_path = "Berksfile"
45
+
46
+ <%= vmname %>_config.vm.host_name = "<%= vmname %>"
47
+
48
+ <%= vmname %>_config.vm.box = "ri_centos6.3_v5.8.8"
49
+ <%= vmname %>_config.vm.box_url = "https://s3.amazonaws.com/rgeyer/pub/ri_centos6.3_v5.8.8_vagrant.box"
50
+
51
+ # TODO: Increment this for each VM in a multi VM Vagrant file
52
+ <%= vmname %>_config.vm.network :hostonly, "33.33.33.10"
53
+
54
+ <%= vmname %>_config.ssh.max_tries = 40
55
+ <%= vmname %>_config.ssh.timeout = 120
56
+
57
+ <%= vmname %>_config.vm.provision Vagrant::RsVagrantShim::Provisioners::RsVagrantShim do |chef|
58
+ chef.run_list_dir = "runlists/<%= vmname %>"
59
+ chef.shim_dir = "rs_vagrant_shim/<%= vmname %>"
60
+ end
61
+ end
62
+ <% end %>
63
+ end
64
+ EOF
65
+
66
+ default_runlist_template = <<-EOF
67
+ {
68
+ "cloud": { "provider": "vagrant" },
69
+ "rightscale": { "instance_uuid": "uuid-<%= box %>" },
70
+ "run_list": [
71
+ "recipe[rs_vagrant_shim]"
72
+ ]
73
+ }
74
+ EOF
75
+
76
+ vagrantfile_erb = ERB.new(vagrantfile_template)
77
+ boxes = ["default"]
78
+ boxes = options[:vmnames] if options[:vmnames] && !options[:vmnames].empty?
79
+ File.open(File.join(projectname, "Vagrantfile"), "w") do |file|
80
+ file.write(vagrantfile_erb.result(binding))
81
+ end
82
+
83
+ boxes.each do |box|
84
+ runlist_dir = File.join(projectname, "runlists", box)
85
+ shim_dir = File.join(projectname, "rs_vagrant_shim", box)
86
+ FileUtils.mkdir_p runlist_dir unless File.directory? runlist_dir
87
+ FileUtils.mkdir_p shim_dir unless File.directory? shim_dir
88
+ default_runlist_file = File.join(runlist_dir, "default.json")
89
+ default_runlist_erb = ERB.new(default_runlist_template)
90
+ File.open(File.join(default_runlist_file), "w") do |file|
91
+ file.write(default_runlist_erb.result(binding))
92
+ end
93
+ end
94
+
95
+ # This is where the gemfile definition is copied from the .gemspec, probably
96
+ # need to store these in a single file and source them from both locations
97
+ File.open(File.join(projectname, "Gemfile"), "w") do |file|
98
+ file.write <<-EOF
99
+ source :rubygems
100
+
101
+ # This is probably a bad idea during dev, you might wanna consider specifying
102
+ # a specific rs_vagrant_shim
103
+ gem "rs_vagrant_shim", "~> 0.0.1"
104
+
105
+ gem "berkshelf", "~> 1.1"
106
+ gem "vagrant", "~> 1.0.5"
107
+ EOF
108
+ end
109
+
110
+ File.open(File.join(projectname, "Berksfile"), "w") do |file|
111
+ file.write <<-EOF
112
+ site :opscode
113
+
114
+ cookbook "rightscale",
115
+ git: "git://github.com/rightscale/rightscale_cookbooks.git",
116
+ branch: "v13.2",
117
+ rel: "cookbooks/rightscale"
118
+
119
+ cookbook "sys",
120
+ git: "git://github.com/rightscale/rightscale_cookbooks.git",
121
+ branch: "v13.2",
122
+ rel: "cookbooks/sys"
123
+
124
+ cookbook "sys_firewall",
125
+ git: "git://github.com/rightscale/rightscale_cookbooks.git",
126
+ branch: "v13.2",
127
+ rel: "cookbooks/sys_firewall"
128
+
129
+ group :vagrant_only do
130
+ cookbook "rs_vagrant_shim",
131
+ git: "https://github.com/rgeyer-rs-cookbooks/rs_vagrant_shim.git",
132
+ rel: "cookbooks/rs_vagrant_shim"
133
+ end
134
+ EOF
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,84 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Vagrant
23
+ module RsVagrantShim
24
+ module Provisioners
25
+ class RsVagrantShim < Vagrant::Provisioners::ChefSolo
26
+
27
+ class Config < Vagrant::Provisioners::ChefSolo::Config
28
+ attr_accessor :shim_dir
29
+ attr_accessor :run_list_dir
30
+ attr_reader :one_time_runlist_file
31
+
32
+ # TODO: Better error handling, verify shim dir and runlist dir exist, catch json errors when parsing runlists
33
+ def validate(env, errors)
34
+
35
+ errors.add(I18n.t("vagrant.config.rs_vagrant_shim.shim_dir_missing")) if !@shim_dir || @shim_dir.empty?
36
+ errors.add(I18n.t("vagrant.config.rs_vagrant_shim.run_list_dir_missing")) if !@run_list_dir || @run_list_dir.empty?
37
+
38
+ if @shim_dir && !@shim_dir.empty? && @run_list_dir && !@run_list_dir.empty?
39
+ dispatch_dir = File.join(Dir.pwd, @shim_dir, 'dispatch')
40
+ FileUtils.mkdir_p dispatch_dir unless File.directory? dispatch_dir
41
+
42
+ dispatch_files = Dir.entries(dispatch_dir).reject{|f| /^\.+/ =~ f}.sort_by{|f| File.mtime(File.join(dispatch_dir, f))}
43
+
44
+ runlist = JSON.parse(File.read(File.join(Dir.pwd, @run_list_dir, 'default.json')))
45
+
46
+ # A specified runlist trumps all, but still inherits from default
47
+ if ENV['runlist']
48
+ runlist_file = File.join(Dir.pwd, @run_list_dir, "#{ENV['runlist']}.json")
49
+ runlist.merge!(JSON.parse(File.read(runlist_file))) if File.exist? runlist_file
50
+ elsif dispatch_files.length > 0
51
+ dispatch_file = File.join(dispatch_dir, dispatch_files.first)
52
+ runlist.merge!(JSON.parse(File.read(dispatch_file)))
53
+ @one_time_runlist_file = dispatch_file
54
+ end
55
+
56
+ @json = {:rs_vagrant_shim => to_hash}.merge(runlist)
57
+ @run_list = runlist['run_list']
58
+ end
59
+
60
+ super(env, errors)
61
+ end
62
+
63
+ end
64
+
65
+ def self.config_class
66
+ Config
67
+ end
68
+
69
+ def provision!
70
+ super
71
+
72
+ # Delete the one-time runlist file
73
+ FileUtils.rm @config.one_time_runlist_file if @config.one_time_runlist_file && File.exist?(@config.one_time_runlist_file)
74
+ end
75
+
76
+ def cleanup
77
+ @hostname_dir = File.join(Dir.pwd, 'rs_vagrant_shim', @env[:vm].config.vm.host_name)
78
+ FileUtils.rm_rf @hostname_dir if File.directory? @hostname_dir
79
+ super
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,6 @@
1
+ en:
2
+ vagrant:
3
+ config:
4
+ rs_vagrant_shim:
5
+ shim_dir_missing: "Must specify a directory where rs_vagrant_shim will use for runtime persistence for the VM"
6
+ run_list_dir_missing: "Must specify a directory where chef solo json config files (used as runlists) can be found for the VM"
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rs_vagrant_shim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan J. Geyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: berkshelf
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: vagrant
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: thor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.16.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.0
62
+ description: Allows RightScale ServerTemplate development to be performed primarily
63
+ within Vagrant
64
+ email: ryan.geyer@rightscale.com
65
+ executables:
66
+ - rs_vagrant_shim
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - lib/rs_vagrant_shim/berkshelf/vagrant.rb
71
+ - lib/rs_vagrant_shim/cli.rb
72
+ - lib/rs_vagrant_shim/vagrant/rs_vagrant_shim/provisioners/rs_vagrant_shim.rb
73
+ - lib/rs_vagrant_shim.rb
74
+ - bin/rs_vagrant_shim
75
+ - locales/en.yml
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ homepage: https://github.com/rgeyer-rs-cookbooks/rs_vagrant_shim
79
+ licenses:
80
+ - MIT
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
92
+ - 0
93
+ hash: 2104702453997691042
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
101
+ - 0
102
+ hash: 2104702453997691042
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Allows RightScale ServerTemplate development to be performed primarily within
109
+ Vagrant
110
+ test_files: []