chef-vpc-toolkit 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +2 -0
  2. data/COPYING +26 -0
  3. data/README.rdoc +75 -0
  4. data/Rakefile +34 -0
  5. data/VERSION +1 -0
  6. data/bin/chef-vpc-toolkit +80 -0
  7. data/config/chef_installer.yml +20 -0
  8. data/config/databags.json.example +24 -0
  9. data/config/nodes.json +10 -0
  10. data/config/server_group.json +16 -0
  11. data/contrib/doc/ChefVPCToolkit.odt +0 -0
  12. data/contrib/doc/ChefVPCToolkit.pdf +0 -0
  13. data/contrib/etc/chef_vpc_toolkit.conf +10 -0
  14. data/contrib/rake/Rakefile +23 -0
  15. data/cookbook-repos/local/README +5 -0
  16. data/cookbook-repos/local/Rakefile +66 -0
  17. data/cookbook-repos/local/certificates/README +1 -0
  18. data/cookbook-repos/local/config/client.rb.example +21 -0
  19. data/cookbook-repos/local/config/knife.rb.example +10 -0
  20. data/cookbook-repos/local/config/rake.rb +60 -0
  21. data/cookbook-repos/local/config/server.rb.example +42 -0
  22. data/cookbook-repos/local/config/solo.rb.example +13 -0
  23. data/cookbook-repos/local/cookbooks/README +4 -0
  24. data/cookbook-repos/local/cookbooks/motd/README.rdoc +15 -0
  25. data/cookbook-repos/local/cookbooks/motd/attributes/motd.rb +1 -0
  26. data/cookbook-repos/local/cookbooks/motd/metadata.rb +6 -0
  27. data/cookbook-repos/local/cookbooks/motd/recipes/default.rb +13 -0
  28. data/cookbook-repos/local/cookbooks/motd/templates/default/motd.erb +1 -0
  29. data/cookbook-repos/local/roles/README +4 -0
  30. data/lib/chef-vpc-toolkit.rb +6 -0
  31. data/lib/chef-vpc-toolkit/chef-0.9.bash +232 -0
  32. data/lib/chef-vpc-toolkit/chef_bootstrap/centos.bash +47 -0
  33. data/lib/chef-vpc-toolkit/chef_bootstrap/fedora.bash +41 -0
  34. data/lib/chef-vpc-toolkit/chef_bootstrap/rhel.bash +38 -0
  35. data/lib/chef-vpc-toolkit/chef_bootstrap/ubuntu.bash +32 -0
  36. data/lib/chef-vpc-toolkit/chef_installer.rb +276 -0
  37. data/lib/chef-vpc-toolkit/cloud_files.bash +67 -0
  38. data/lib/chef-vpc-toolkit/cloud_servers_vpc.rb +285 -0
  39. data/lib/chef-vpc-toolkit/http_util.rb +117 -0
  40. data/lib/chef-vpc-toolkit/ssh_util.rb +22 -0
  41. data/lib/chef-vpc-toolkit/util.rb +56 -0
  42. data/lib/chef-vpc-toolkit/version.rb +8 -0
  43. data/rake/chef_vpc_toolkit.rake +284 -0
  44. data/test/cloud_servers_vpc_test.rb +174 -0
  45. data/test/test_helper.rb +25 -0
  46. metadata +153 -0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ tmp
2
+ pkg
data/COPYING ADDED
@@ -0,0 +1,26 @@
1
+ Unless otherwise noted, all files are released under the MIT license,
2
+ exceptions contain licensing information in them.
3
+
4
+ Copyright (C) 2010 Rackspace US, Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
24
+ Except as contained in this notice, the name of Rackspace US, Inc. shall not
25
+ be used in advertising or otherwise to promote the sale, use or other dealings
26
+ in this Software without prior written authorization from Rackspace US, Inc.
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ = Chef VPC Toolkit
2
+
3
+ Chef Virtual Private Cloud Toolkit
4
+
5
+ == Description
6
+
7
+ The Chef VPC Toolkit is a set of Rake tasks that provide a framework to help automate the creation and configuration of “identical” VPC server groups in the cloud. The Chef VPC Toolkit provides the ability to create “toolkit projects” that can be used by team members and continuous integration systems to spin up groups of servers for development and testing. Configuration information is stored in JSON and YAML formats which can be easily parsed, edited, and version controlled.
8
+
9
+ == Features
10
+
11
+ -Supports Rackspace Cloud Servers.
12
+
13
+ -Uses Cloud Servers VPC to create secure groups of servers in the public cloud.
14
+
15
+ -Supports Centos, Fedora, RHEL, and Ubuntu.
16
+
17
+ -Creates a local Chef Server within the server group.
18
+
19
+ -Installs and configures a Chef client on each node with the Chef Server.
20
+
21
+ -Automatically configures Chef Cookbooks, Databags, Roles, and Node attributes.
22
+
23
+ == Installation
24
+
25
+ Requires Ruby and Rubygems. The app was developed with Ruby 1.8.7.
26
+
27
+ The following gems are required:
28
+
29
+ rake
30
+ builder (2.1.2)
31
+ json (> 1.4.3)
32
+
33
+ To install the gem:
34
+
35
+ rake build
36
+ gem install chef-vpc-toolkit
37
+
38
+ == Examples
39
+
40
+ Example commands:
41
+
42
+ - Create a new cloud server group, upload cookbooks, install chef
43
+ on all the nodes, sync share data and cookbooks.
44
+
45
+ $ rake create
46
+
47
+ - List your currently running cloud server groups.
48
+
49
+ $ rake group:list
50
+
51
+ - SSH into the current (most recently created) cloud server group
52
+
53
+ $ rake ssh
54
+
55
+ - SSH into a cloud server group with an ID of 3
56
+
57
+ $ rake ssh GROUP_ID=3
58
+
59
+ - Delete the cloud server group with an ID of 3
60
+
61
+ $ rake group:delete GROUP_ID=3
62
+
63
+ - Rebuild/Re-Chef the 'db1' server in the most recently created cloud
64
+ server group
65
+
66
+ $ rake rechef SERVER_NAME=db1
67
+
68
+ == Author
69
+
70
+ Dan Prince <dan.prince@rackspace.com>
71
+
72
+ == License
73
+
74
+ See COPYING for license information.
75
+ Copyright (c) 2010, Rackspace US, Inc.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'rake/testtask'
2
+
3
+ CHEF_VPC_PROJECT = "#{File.dirname(__FILE__)}" unless defined?(CHEF_VPC_PROJECT)
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),'lib')
6
+ require 'chef-vpc-toolkit'
7
+ include ChefVPCToolkit
8
+
9
+ Dir[File.join(File.dirname(__FILE__), 'rake', '*.rake')].each do |rakefile|
10
+ import(rakefile)
11
+ end
12
+
13
+ Rake::TestTask.new(:test) do |t|
14
+ t.pattern = 'test/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+ Rake::Task['test'].comment = "Unit"
18
+
19
+ begin
20
+ require 'jeweler'
21
+ Jeweler::Tasks.new do |gemspec|
22
+ gemspec.name = "chef-vpc-toolkit"
23
+ gemspec.summary = "Rake tasks to automate and configure server groups in the cloud with Chef."
24
+ gemspec.description = "The Chef VPC Toolkit is a set of Rake tasks that provide a framework to help automate the creation and configuration of VPC server groups in the cloud."
25
+ gemspec.email = "dan.prince@rackspace.com"
26
+ gemspec.homepage = "http://github.com/rackspace/chef-vpc-toolkit"
27
+ gemspec.authors = ["Dan Prince"]
28
+ gemspec.add_dependency 'rake'
29
+ gemspec.add_dependency 'builder'
30
+ gemspec.add_dependency 'json'
31
+ end
32
+ rescue LoadError
33
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
34
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'rubygems'
5
+ require 'fileutils'
6
+
7
+ CHEF_VPC_PROJECT = "#{File.dirname(__FILE__)}" unless defined?(CHEF_VPC_PROJECT)
8
+ require 'chef-vpc-toolkit'
9
+ include ChefVPCToolkit
10
+
11
+ options = {}
12
+ opts = OptionParser.new
13
+
14
+ options[:name] = ""
15
+ opts.on("-n name", "--name", String,
16
+ "Create a new cloud project with the given directory name.") do |name|
17
+ options[:name] = name
18
+ end
19
+
20
+ options[:upgrade] = false
21
+ opts.on("-u", "--upgrade", "Upgrade a cloud project to work with the latest Cloud Toolkit.") do
22
+ options[:upgrade] = true
23
+ end
24
+
25
+ opts.on_tail("-v", "--version", "Print version") do
26
+ puts "Cloud Toolkit Version: #{Version::VERSION}"
27
+ exit
28
+ end
29
+
30
+ opts.on_tail("-h", "--help", "Show help") do
31
+ puts opts
32
+ exit
33
+ end
34
+
35
+ opts.parse!(ARGV)
36
+
37
+ # simple validations
38
+ def exit_if_nil_or_empty(options, sym)
39
+ if options[sym].nil? || options[sym].empty? then
40
+ puts "Please specify a valid #{sym.to_s} parameter."
41
+ puts "Run with --help for more information."
42
+ exit 1
43
+ end
44
+ end
45
+
46
+ if options[:upgrade]
47
+
48
+ # Rakefile
49
+ if not File.exists?("Rakefile") then
50
+ puts "Unable to find Rakefile. Run the 'cloud-toolkit -u' commmand from within a cloud project directory."
51
+ exit 1
52
+ else
53
+ FileUtils.cp("#{Version::CHEF_VPC_TOOLKIT_ROOT}/contrib/Rakefile", "Rakefile")
54
+ end
55
+
56
+ # chef_installer.yml
57
+ if File.exists?("config/chef_installer.conf") then
58
+ FileUtils.mv("config/chef_installer.conf", "config/chef_installer.yml")
59
+ end
60
+
61
+ else
62
+ exit_if_nil_or_empty(options, :name)
63
+
64
+ if File.exists?(options[:name]) then
65
+ puts "'#{options[:name]}' already exists."
66
+ exit 1
67
+ end
68
+
69
+ ["", "share"].each do |dir|
70
+ FileUtils.mkdir_p options[:name] + File::SEPARATOR + dir
71
+ end
72
+
73
+ ["config", "cookbook-repos"].each do |dir|
74
+ FileUtils.cp_r(Version::CHEF_VPC_TOOLKIT_ROOT+File::SEPARATOR+dir, File.join(options[:name], dir))
75
+ end
76
+
77
+ FileUtils.cp("#{Version::CHEF_VPC_TOOLKIT_ROOT}/VERSION", File.join(options[:name], "config", "TOOLKIT_VERSION"))
78
+
79
+ FileUtils.cp("#{Version::CHEF_VPC_TOOLKIT_ROOT}/contrib/rake/Rakefile", File.join(options[:name], "Rakefile"))
80
+ end
@@ -0,0 +1,20 @@
1
+ # Options for the Chef Installer.
2
+
3
+ # Public cookbook repo. (Full URL)
4
+ #chef_cookbook_repos: http://localhost/cookbook-repo1.tar.gz
5
+
6
+ # Shared Chef cookbook repository hosted in Rackspace Cloud Files.
7
+ #chef_cookbook_repos: CookbookRepos/cookbook-repo1.tar.gz
8
+
9
+ # Optionally you can specify multiple repos:
10
+ #chef_cookbook_repos:
11
+ #- CookbookRepos/cookbook_repo1-1.1.tar.gz
12
+ #- CookbookRepos/cookbook_repo2-trunk.tar.gz
13
+
14
+ # The Chef JSON configuration contains attributes and recipes for nodes.
15
+ chef_json_file: config/nodes.json
16
+
17
+ #databags_json_file: config/databags.json
18
+
19
+ # Chef server name
20
+ chef_server_name: login
@@ -0,0 +1,24 @@
1
+ {
2
+ "ip_interfaces": [
3
+ {
4
+ "id": "gate1",
5
+ "ip1": "123.123.123.1",
6
+ "ip2": "123.123.123.2"
7
+ },
8
+ {
9
+ "id": "gate2",
10
+ "ip1": "123.123.123.3",
11
+ "ip2": "123.123.123.4"
12
+ }
13
+ ],
14
+ "admins": [
15
+ {
16
+ "id": "jim",
17
+ "first_name": "Jim"
18
+ },
19
+ {
20
+ "id": "bill",
21
+ "first_name": "William"
22
+ }
23
+ ]
24
+ }
data/config/nodes.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "login": {
3
+ "run_list": [
4
+ ]
5
+ },
6
+ "client1": {
7
+ "run_list": [
8
+ ]
9
+ }
10
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "test",
3
+ "domain_name": "vpc",
4
+ "description": "test description",
5
+ "servers": {
6
+ "login": {
7
+ "image_id": "51",
8
+ "flavor_id": "4",
9
+ "openvpn_server": "true"
10
+ },
11
+ "client1": {
12
+ "image_id": "51",
13
+ "flavor_id": "4"
14
+ }
15
+ }
16
+ }
Binary file
Binary file
@@ -0,0 +1,10 @@
1
+ # Copy this file to $HOME/.chef_vpc_toolkit.conf to add your own settings
2
+
3
+ # Cloud Control settings
4
+ cloud_servers_vpc_url:
5
+ cloud_servers_vpc_username:
6
+ cloud_servers_vpc_password:
7
+
8
+ # The text editor to use for Chef knife commands. Used when a new server group
9
+ # is created. Default: vim
10
+ # knife_editor: vim
@@ -0,0 +1,23 @@
1
+ CHEF_VPC_PROJECT = "#{File.dirname(__FILE__)}" unless defined?(CHEF_VPC_PROJECT)
2
+
3
+ require 'rubygems'
4
+
5
+ version_file=(File.join(CHEF_VPC_PROJECT, 'config', 'TOOLKIT_VERSION'))
6
+ toolkit_version=nil
7
+ if ENV['CHEF_VPC_TOOLKIT_VERSION'] then
8
+ toolkit_version=ENV['CHEF_VPC_TOOLKIT_VERSION']
9
+ elsif File.exists?(version_file)
10
+ toolkit_version=IO.read(version_file)
11
+ end
12
+
13
+ puts "Chef VPC Toolkit Version: #{toolkit_version}"
14
+
15
+ gem 'chef-vpc-toolkit', "= #{toolkit_version}" if toolkit_version
16
+
17
+ require 'chef-vpc-toolkit'
18
+
19
+ include ChefVPCToolkit
20
+
21
+ Dir[File.join("#{ChefVPCToolkit::Version::CHEF_VPC_TOOLKIT_ROOT}/rake", '*.rake')].each do |rakefile|
22
+ import(rakefile)
23
+ end
@@ -0,0 +1,5 @@
1
+ This is a blank repository you can use as a starting point for your
2
+ local chef configuration. For full details on the parts aside from
3
+ information contained in the README files, see the Chef wiki document
4
+
5
+ http://wiki.opscode.com/display/chef/Chef+Repository
@@ -0,0 +1,66 @@
1
+ #
2
+ # Rakefile for Chef Server Repository
3
+ #
4
+ # Author:: Adam Jacob (<adam@opscode.com>)
5
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'rubygems'
22
+ require 'chef'
23
+ require 'json'
24
+
25
+ # Load constants from rake config file.
26
+ require File.join(File.dirname(__FILE__), 'config', 'rake')
27
+
28
+ # Detect the version control system and assign to $vcs. Used by the update
29
+ # task in chef_repo.rake (below). The install task calls update, so this
30
+ # is run whenever the repo is installed.
31
+ #
32
+ # Comment out these lines to skip the update.
33
+
34
+ if File.directory?(File.join(TOPDIR, ".svn"))
35
+ $vcs = :svn
36
+ elsif File.directory?(File.join(TOPDIR, ".git"))
37
+ $vcs = :git
38
+ end
39
+
40
+ # Load common, useful tasks from Chef.
41
+ # rake -T to see the tasks this loads.
42
+
43
+ load 'chef/tasks/chef_repo.rake'
44
+
45
+ desc "Bundle a single cookbook for distribution"
46
+ task :bundle_cookbook => [ :metadata ]
47
+ task :bundle_cookbook, :cookbook do |t, args|
48
+ tarball_name = "#{args.cookbook}.tar.gz"
49
+ temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
50
+ temp_cookbook_dir = File.join(temp_dir, args.cookbook)
51
+ tarball_dir = File.join(TOPDIR, "pkgs")
52
+ FileUtils.mkdir_p(tarball_dir)
53
+ FileUtils.mkdir(temp_dir)
54
+ FileUtils.mkdir(temp_cookbook_dir)
55
+
56
+ child_folders = [ "cookbooks/#{args.cookbook}", "site-cookbooks/#{args.cookbook}" ]
57
+ child_folders.each do |folder|
58
+ file_path = File.join(TOPDIR, folder, ".")
59
+ FileUtils.cp_r(file_path, temp_cookbook_dir) if File.directory?(file_path)
60
+ end
61
+
62
+ system("tar", "-C", temp_dir, "-cvzf", File.join(tarball_dir, tarball_name), "./#{args.cookbook}")
63
+
64
+ FileUtils.rm_rf temp_dir
65
+ end
66
+
@@ -0,0 +1 @@
1
+ This directory contains certificates created by the Rakefile.
@@ -0,0 +1,21 @@
1
+ #
2
+ # Example Chef Client Config File
3
+ #
4
+ # We recommend using Opscode's chef cookbook for managing chef itself,
5
+ # instead of using this file. It is provided as an example.
6
+
7
+ log_level :info
8
+ log_location STDOUT
9
+ ssl_verify_mode :verify_none
10
+ chef_server_url "http://chef.example.com:4000"
11
+
12
+ validation_client_name "chef-validator"
13
+ validation_key "/etc/chef/validation.pem"
14
+ client_key "/etc/chef/client.pem"
15
+
16
+ file_store_path "/srv/chef/file_store"
17
+ file_cache_path "/srv/chef/cache"
18
+
19
+ pid_file "/var/run/chef/chef-client.pid"
20
+
21
+ Mixlib::Log::Formatter.show_time = true