caterer 0.11.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/README.md +34 -116
  2. data/Vagrantfile +4 -4
  3. data/lib/caterer.rb +3 -0
  4. data/lib/caterer/action.rb +1 -0
  5. data/lib/caterer/action/berkshelf/install.rb +3 -1
  6. data/lib/caterer/action/config/validate/provisioner.rb +16 -10
  7. data/lib/caterer/action/image.rb +9 -0
  8. data/lib/caterer/action/image/cleanup.rb +20 -0
  9. data/lib/caterer/action/image/prepare.rb +20 -0
  10. data/lib/caterer/action/image/run.rb +20 -0
  11. data/lib/caterer/action/provisioner.rb +0 -7
  12. data/lib/caterer/action/provisioner/cleanup.rb +19 -1
  13. data/lib/caterer/action/provisioner/prepare.rb +20 -2
  14. data/lib/caterer/action/provisioner/uninstall.rb +9 -1
  15. data/lib/caterer/action/server.rb +2 -1
  16. data/lib/caterer/action/{provisioner/install.rb → server/cleanup.rb} +5 -5
  17. data/lib/caterer/action/server/{reboot.rb → prepare.rb} +4 -2
  18. data/lib/caterer/actions.rb +8 -46
  19. data/lib/caterer/cli.rb +50 -4
  20. data/lib/caterer/command.rb +1 -4
  21. data/lib/caterer/command/base.rb +17 -108
  22. data/lib/caterer/command/berks.rb +5 -8
  23. data/lib/caterer/command/clean.rb +6 -4
  24. data/lib/caterer/command/lock.rb +5 -3
  25. data/lib/caterer/command/provision.rb +19 -4
  26. data/lib/caterer/command/server.rb +106 -0
  27. data/lib/caterer/command/unlock.rb +5 -3
  28. data/lib/caterer/commands.rb +0 -3
  29. data/lib/caterer/config.rb +0 -5
  30. data/lib/caterer/config/base.rb +5 -4
  31. data/lib/caterer/config/provisioner/chef_solo.rb +1 -2
  32. data/lib/caterer/group.rb +24 -0
  33. data/lib/caterer/image.rb +88 -0
  34. data/lib/caterer/member.rb +13 -0
  35. data/lib/caterer/provisioner.rb +1 -0
  36. data/lib/caterer/provisioner/base.rb +4 -3
  37. data/lib/caterer/provisioner/chef_solo.rb +58 -123
  38. data/lib/caterer/provisioner/shell.rb +83 -0
  39. data/lib/caterer/provisioners.rb +2 -1
  40. data/lib/caterer/server.rb +18 -36
  41. data/lib/caterer/version.rb +1 -1
  42. data/lib/templates/image/bin_wrapper.erb +8 -0
  43. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/debian.sh +0 -0
  44. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/el.sh +0 -0
  45. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/fedora.sh +0 -0
  46. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/sles.sh +0 -0
  47. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/smartos.sh +0 -0
  48. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/suse.sh +0 -0
  49. data/lib/templates/provisioner/chef_solo/{bootstrap → install}/ubuntu.sh +0 -0
  50. data/lib/templates/provisioner/chef_solo/solo.erb +1 -1
  51. data/lib/templates/provisioner/shell/script.erb +3 -0
  52. metadata +24 -26
  53. data/lib/caterer/action/provisioner/bootstrap.rb +0 -14
  54. data/lib/caterer/action/provisioner/load.rb +0 -29
  55. data/lib/caterer/action/provisioner/provision.rb +0 -14
  56. data/lib/caterer/action/provisioner/validate.rb +0 -10
  57. data/lib/caterer/action/provisioner/validate/bootstrapped.rb +0 -22
  58. data/lib/caterer/action/provisioner/validate/engine.rb +0 -24
  59. data/lib/caterer/command/bootstrap.rb +0 -24
  60. data/lib/caterer/command/reboot.rb +0 -24
  61. data/lib/caterer/command/test.rb +0 -19
  62. data/lib/caterer/command/up.rb +0 -24
  63. data/lib/caterer/config/group.rb +0 -26
  64. data/lib/caterer/config/image.rb +0 -21
  65. data/lib/caterer/config/member.rb +0 -15
@@ -1,9 +1,10 @@
1
1
  module Caterer
2
2
  module Action
3
3
  module Server
4
+ autoload :Cleanup, 'caterer/action/server/cleanup'
4
5
  autoload :Lock, 'caterer/action/server/lock'
5
6
  autoload :Platform, 'caterer/action/server/platform'
6
- autoload :Reboot, 'caterer/action/server/reboot'
7
+ autoload :Prepare, 'caterer/action/server/prepare'
7
8
  autoload :Validate, 'caterer/action/server/validate'
8
9
  autoload :Unlock, 'caterer/action/server/unlock'
9
10
  end
@@ -1,13 +1,13 @@
1
1
  module Caterer
2
2
  module Action
3
- module Provisioner
4
- class Install < Base
5
-
3
+ module Server
4
+ class Cleanup < Base
5
+
6
6
  def call(env)
7
- env[:provisioner].install(env[:server])
7
+ env[:server].cleanup! if env[:ghost_mode]
8
8
  @app.call(env)
9
9
  end
10
-
10
+
11
11
  end
12
12
  end
13
13
  end
@@ -1,11 +1,13 @@
1
1
  module Caterer
2
2
  module Action
3
3
  module Server
4
- class Reboot < Base
4
+ class Prepare < Base
5
+
5
6
  def call(env)
6
- env[:server].reboot!
7
+ env[:server].prepare!
7
8
  @app.call(env)
8
9
  end
10
+
9
11
  end
10
12
  end
11
13
  end
@@ -3,7 +3,6 @@ Caterer.actions.register(:validate) do
3
3
  Vli::Action::Builder.new do
4
4
  use Caterer::Action::Config::Validate::Image
5
5
  use Caterer::Action::Config::Validate::Provisioner
6
- use Caterer::Action::Provisioner::Validate::Engine
7
6
  use Caterer::Action::Server::Validate::SSH
8
7
  use Caterer::Action::Server::Validate::Unlocked
9
8
  end
@@ -25,67 +24,30 @@ Caterer.actions.register(:unlock) do
25
24
  end
26
25
  end
27
26
 
28
- Caterer.actions.register(:bootstrap) do
29
- Vli::Action::Builder.new do
30
- use Caterer::Action::Environment::Setup
31
- use Caterer.actions.get(:validate)
32
- use Caterer::Action::Server::Platform
33
- use Caterer::Action::Provisioner::Load
34
- use Caterer::Action::Provisioner::Prepare
35
- use Caterer::Action::Server::Lock
36
- use Caterer::Action::Provisioner::Bootstrap
37
- use Caterer::Action::Provisioner::Install
38
- use Caterer::Action::Provisioner::Cleanup
39
- use Caterer::Action::Server::Unlock
40
- end
41
- end
42
-
43
27
  Caterer.actions.register(:provision) do
44
28
  Vli::Action::Builder.new do
45
29
  use Caterer::Action::Environment::Setup
46
30
  use Caterer.actions.get(:validate)
47
31
  use Caterer::Action::Server::Platform
48
- use Caterer::Action::Provisioner::Load
49
- use Caterer::Action::Provisioner::Prepare
50
- use Caterer::Action::Provisioner::Validate::Bootstrapped
51
32
  use Caterer::Action::Server::Lock
52
- use Caterer::Action::Provisioner::Provision
53
- use Caterer::Action::Provisioner::Cleanup
54
- use Caterer::Action::Server::Unlock
55
- end
56
- end
57
-
58
- Caterer.actions.register(:up) do
59
- Vli::Action::Builder.new do
60
- use Caterer::Action::Environment::Setup
61
- use Caterer.actions.get(:validate)
62
- use Caterer::Action::Server::Platform
63
- use Caterer::Action::Provisioner::Load
33
+ use Caterer::Action::Server::Prepare
34
+ use Caterer::Action::Image::Prepare
64
35
  use Caterer::Action::Provisioner::Prepare
65
- use Caterer::Action::Server::Lock
66
- use Caterer::Action::Provisioner::Bootstrap
67
- use Caterer::Action::Provisioner::Install
68
- use Caterer::Action::Provisioner::Provision
36
+ use Caterer::Action::Image::Run
69
37
  use Caterer::Action::Provisioner::Cleanup
38
+ use Caterer::Action::Image::Cleanup
39
+ use Caterer::Action::Server::Cleanup
70
40
  use Caterer::Action::Server::Unlock
71
41
  end
72
42
  end
73
43
 
74
- Caterer.actions.register(:reboot) do
75
- Vli::Action::Builder.new do
76
- use Caterer::Action::Environment::Setup
77
- use Caterer::Action::Server::Validate::SSH
78
- use Caterer::Action::Server::Platform
79
- use Caterer::Action::Server::Reboot
80
- end
81
- end
82
-
83
44
  Caterer.actions.register(:clean) do
84
45
  Vli::Action::Builder.new do
85
46
  use Caterer::Action::Environment::Setup
86
47
  use Caterer.actions.get(:validate)
87
48
  use Caterer::Action::Server::Platform
88
- use Caterer::Action::Provisioner::Load
89
- use Caterer::Action::Provisioner::Uninstall
49
+ use Caterer::Action::Provisioner::Cleanup
50
+ use Caterer::Action::Image::Cleanup
51
+ use Caterer::Action::Server::Cleanup
90
52
  end
91
53
  end
@@ -1,14 +1,14 @@
1
1
  # Credit:
2
2
  # special thanks to Vagrant project: https://github.com/mitchellh/vagrant
3
- # where the source of this module was originally extracted.
3
+ # where parts of this module were extracted
4
4
 
5
5
  require 'optparse'
6
6
 
7
7
  module Caterer
8
- class Cli < Vli::Command::Base
8
+ class Cli
9
9
  def initialize(argv, env)
10
- super
11
-
10
+ @argv = argv
11
+ @env = env
12
12
  @logger = Log4r::Logger.new("caterer::cli")
13
13
  @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
14
14
 
@@ -67,5 +67,51 @@ module Caterer
67
67
  @env.ui.info opts.help, :prefix => false
68
68
  end
69
69
 
70
+ # This method will split the argv given into three parts: the
71
+ # flags to this command, the subcommand, and the flags to the
72
+ # subcommand. For example:
73
+ #
74
+ # -v status -h -v
75
+ #
76
+ # The above would yield 3 parts:
77
+ #
78
+ # ["-v"]
79
+ # "status"
80
+ # ["-h", "-v"]
81
+ #
82
+ # These parts are useful because the first is a list of arguments
83
+ # given to the current command, the second is a subcommand, and the
84
+ # third are the commands given to the subcommand.
85
+ #
86
+ # @return [Array] The three parts.
87
+ def split_main_and_subcommand(argv)
88
+ # Initialize return variables
89
+ main_args = nil
90
+ sub_command = nil
91
+ sub_args = []
92
+
93
+ # We split the arguments into two: One set containing any
94
+ # flags before a word, and then the rest. The rest are what
95
+ # get actually sent on to the subcommand.
96
+ argv.each_index do |i|
97
+ if !argv[i].start_with?("-")
98
+ # We found the beginning of the sub command. Split the
99
+ # args up.
100
+ main_args = argv[0, i]
101
+ sub_command = argv[i]
102
+ sub_args = argv[i + 1, argv.length - i + 1]
103
+
104
+ # Break so we don't find the next non flag and shift our
105
+ # main args.
106
+ break
107
+ end
108
+ end
109
+
110
+ # Handle the case that argv was empty or didn't contain any subcommand
111
+ main_args = argv.dup if main_args.nil?
112
+
113
+ return [main_args, sub_command, sub_args]
114
+ end
115
+
70
116
  end
71
117
  end
@@ -3,12 +3,9 @@ module Caterer
3
3
  autoload :Base, 'caterer/command/base'
4
4
  autoload :Clean, 'caterer/command/clean'
5
5
  autoload :Berks, 'caterer/command/berks'
6
- autoload :Bootstrap, 'caterer/command/bootstrap'
7
6
  autoload :Lock, 'caterer/command/lock'
8
7
  autoload :Provision, 'caterer/command/provision'
9
- autoload :Reboot, 'caterer/command/reboot'
10
- autoload :Test, 'caterer/command/test'
8
+ autoload :Server, 'caterer/command/server'
11
9
  autoload :Unlock, 'caterer/command/unlock'
12
- autoload :Up, 'caterer/command/up'
13
10
  end
14
11
  end
@@ -3,126 +3,35 @@ require 'multi_json'
3
3
 
4
4
  module Caterer
5
5
  module Command
6
- class Base < Vli::Command::Base
6
+ class Base
7
7
 
8
- def parse_options(opts=nil, options={}, force_argv=true)
8
+ include Vli::Util::SafePuts
9
+
10
+ def initialize(argv, env)
11
+ @argv = argv
12
+ @env = env
13
+ end
14
+
15
+ def execute; end
16
+
17
+ def parse_options(opts=nil, force_argv=false)
18
+ argv = @argv.dup
9
19
  opts ||= OptionParser.new
10
- opts.separator ""
11
- opts.on("-c CONFIG", 'assumes Caterfile in current directory')
12
- opts.separator ""
13
- opts.on("-u USER", "--user USER", 'assumes current username') do |u|
14
- options[:user] = u
15
- end
16
- opts.on('-p PASSWORD', '--password PASSWORD', 'assumes key') do |p|
17
- options[:pass] = p
18
- end
19
- opts.on('-k KEY', '--key KEY', 'path to private key') do |k|
20
- options[:key] = k
21
- end
22
- opts.on('-P PORT', '--port PORT', 'assumes 22') do |p|
23
- options[:port] = p
24
- end
25
- opts.on('-e ENGINE', '--engine ENGINE', 'provision engine' ) do |e|
26
- options[:engine] = e
27
- end
28
- opts.on('-d JSON', '--data JSON', 'json data that the provisioner may use' ) do |d|
29
- options[:data] = d
30
- end
31
- opts.on('-i IMAGE', '--image IMAGE', 'corresponds to a image in Caterfile') do |i|
32
- options[:image] = i
33
- end
34
- opts.on('-g GROUP', '--group GROUP', 'corresponds to a group in Caterfile') do |g|
35
- options[:group] = g
20
+
21
+ opts.on_tail("-h", "--help", "Print this help") do
22
+ safe_puts(opts.help)
23
+ return nil
36
24
  end
37
- opts.separator ""
38
25
 
39
26
  begin
40
- argv = super(opts)
27
+ opts.parse!(argv)
41
28
  raise if force_argv and (not argv or argv.length == 0)
42
29
  argv
43
30
  rescue
44
31
  safe_puts(opts.help)
45
32
  nil
46
33
  end
47
-
48
- end
49
-
50
- def with_target_servers(argv, options={})
51
- target_servers(argv, options).each do |server|
52
- yield server if block_given?
53
- end
54
- end
55
-
56
- def target_servers(argv, options={})
57
- @servers ||= begin
58
- servers = []
59
-
60
- argv.first.split(",").each do |host|
61
-
62
- if group = @env.config.groups[host.to_sym]
63
- group.members.each do |key, member|
64
- servers << init_server(group, member, options)
65
- end
66
- else
67
-
68
- if not host.match /::/
69
- host = "default::#{host}"
70
- end
71
34
 
72
- g, m = host.split "::"
73
- group = nil
74
- member = nil
75
-
76
- if group = @env.config.groups[g.to_sym]
77
- member = group.members[m.to_sym]
78
- end
79
-
80
- servers << init_server(group, member, options.merge(:host => m))
81
- end
82
- end
83
-
84
- servers
85
- end
86
- end
87
-
88
- def init_server(group=nil, member=nil, options={})
89
-
90
- group ||= Config::Group.new
91
- member ||= Config::Member.new
92
-
93
- opts = {}
94
- opts[:alias] = member.name
95
- opts[:user] = options[:user] || member.user || group.user
96
- opts[:pass] = options[:pass] || member.password || group.password
97
- opts[:host] = member.host || options[:host]
98
- opts[:port] = options[:port] || member.port
99
- opts[:images] = image_list(options) || member.images || group.images
100
- opts[:key] = options[:key] || member.key || group.key
101
-
102
- if engine = options[:engine]
103
- opts[:engine] = engine.to_sym
104
- end
105
-
106
- opts[:data] = begin
107
-
108
- data = group.data.merge(member.data)
109
-
110
- if options[:data]
111
- # todo: rather than puking if the json is valid, this should create a pretty language
112
- json = MultiJson.load options[:data], :symbolize_keys => true
113
- data = data.merge(json) if json and json.is_a? Hash
114
- end
115
-
116
- data
117
- end
118
-
119
- Server.new(@env, opts)
120
- end
121
-
122
- def image_list(options={})
123
- if images = options[:image]
124
- images.split(',').map(&:to_sym)
125
- end
126
35
  end
127
36
 
128
37
  end
@@ -1,19 +1,16 @@
1
1
  module Caterer
2
2
  module Command
3
- class Berks < Vli::Command::Base
3
+ class Berks < Base
4
4
 
5
5
  def execute
6
6
  options = {}
7
- opts = OptionParser.new do |opts|
7
+ parser = OptionParser.new do |opts|
8
8
  opts.banner = "Usage: cater berks install|update|clean"
9
9
  end
10
10
 
11
11
  # Parse the options
12
- argv = parse_options(opts)
13
- if not argv.any?
14
- safe_puts(opts.help)
15
- return
16
- end
12
+ argv = parse_options(parser, true)
13
+ return if not argv
17
14
 
18
15
  case argv.first
19
16
  when 'install'
@@ -23,7 +20,7 @@ module Caterer
23
20
  when 'clean'
24
21
  run_action :berks_clean, {force_berks_clean: true}
25
22
  else
26
- safe_puts(opts.help)
23
+ safe_puts(parser.help)
27
24
  end
28
25
 
29
26
  0
@@ -1,15 +1,17 @@
1
1
  module Caterer
2
2
  module Command
3
- class Clean < Base
3
+ class Clean < Server
4
4
 
5
5
  def execute
6
6
  options = {}
7
- opts = OptionParser.new do |opts|
8
- opts.banner = "Usage: cater provision HOST [options]"
7
+ parser = OptionParser.new do |opts|
8
+ opts.banner = "Usage: cater clean HOST [options]"
9
9
  end
10
10
 
11
+ add_server_opts(parser, options)
12
+
11
13
  # Parse the options
12
- argv = parse_options(opts, options, true)
14
+ argv = parse_options(parser, true)
13
15
  return if not argv
14
16
 
15
17
  with_target_servers(argv, options) do |server|
@@ -1,15 +1,17 @@
1
1
  module Caterer
2
2
  module Command
3
- class Lock < Base
3
+ class Lock < Server
4
4
 
5
5
  def execute
6
6
  options = {}
7
- opts = OptionParser.new do |opts|
7
+ parser = OptionParser.new do |opts|
8
8
  opts.banner = "Usage: cater lock HOST [options]"
9
9
  end
10
10
 
11
+ add_server_opts(parser, options)
12
+
11
13
  # Parse the options
12
- argv = parse_options(opts, options, true)
14
+ argv = parse_options(parser, true)
13
15
  return if not argv
14
16
 
15
17
  with_target_servers(argv, options) do |server|
@@ -1,19 +1,34 @@
1
1
  module Caterer
2
2
  module Command
3
- class Provision < Base
3
+ class Provision < Server
4
4
 
5
5
  def execute
6
6
  options = {}
7
- opts = OptionParser.new do |opts|
7
+ parser = OptionParser.new do |opts|
8
8
  opts.banner = "Usage: cater provision HOST [options]"
9
9
  end
10
10
 
11
+ add_server_opts(parser, options)
12
+
13
+ # add provision specific options
14
+ parser.on('-d JSON', '--data JSON', 'json data that the provisioner may use' ) do |d|
15
+ options[:data] = d
16
+ end
17
+ parser.on('--ghost', 'provision in ghost-mode (leave no trace)') do
18
+ options[:ghost] = true
19
+ end
20
+ parser.on('--dry', "sync provision configuration, but don't run the provisioner") do
21
+ options[:dry] = true
22
+ end
23
+
24
+ parser.separator ""
25
+
11
26
  # Parse the options
12
- argv = parse_options(opts, options, true)
27
+ argv = parse_options(parser, true)
13
28
  return if not argv
14
29
 
15
30
  with_target_servers(argv, options) do |server|
16
- server.provision
31
+ server.provision(dry_run: options[:dry], ghost_mode: options[:ghost])
17
32
  end
18
33
 
19
34
  0