coral_vagrant 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralInit < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral init -hdf [ {server_name} ... ]'
15
+ opts.separator ''
16
+
17
+ opts.on('-d', '--destroy', 'Remove existing servers and start from scratch') do |d|
18
+ options[:destroy] = d
19
+ end
20
+
21
+ opts.on('-f', '--force', 'Destroy without confirmation') do |f|
22
+ options[:force] = f
23
+ end
24
+
25
+ #---
26
+
27
+ options[:min] = 1
28
+ opts.on('-m', '--min TRIES', 'Minimum number of provision runs (1)') do |m|
29
+ options[:min] = m
30
+ end
31
+
32
+ options[:tries] = 1
33
+ opts.on('-t', '--tries TRIES', 'Number of provision attempts before stopping with an error (1)') do |t|
34
+ options[:tries] = t
35
+ end
36
+
37
+ options[:exit] = ''
38
+ opts.on('-e', '--exit CONDITIONS', 'Conditions on which to exit in the format separated by a comma: "User[git]:ensure:created"') do |e|
39
+ options[:exit] = e
40
+ end
41
+
42
+ options[:repos] = ''
43
+ opts.on('-r', '--repos REPO_DIR,...', 'Local directories of repositories to syncronize remotes relative to the Vagrantfile root') do |r|
44
+ options[:repos] = r
45
+ end
46
+ end
47
+
48
+ options[:min] = 1
49
+ options[:auth] = true
50
+
51
+ #---
52
+
53
+ servers = parse_options(opts)
54
+ return unless servers
55
+
56
+ with_target_vms(servers) do |vm|
57
+ @env.ui.info("Starting initialization run for: #{vm.name}")
58
+
59
+ server = Cloud::Server.new({
60
+ :cloud => Coral.vagrant,
61
+ :machine => vm,
62
+ :logger => @logger,
63
+ :ui => @env.ui,
64
+ })
65
+
66
+ if options[:destroy]
67
+ success = server.destroy(options) if success
68
+ end
69
+ success = server.start(options) if success
70
+ success = server.update(options) if success
71
+ end
72
+ exit success ? 0 : 1
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,83 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralPush < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral push -hcet --repos={repository_name},... [ {server_name} ... ]'
15
+ opts.separator ''
16
+
17
+ opts.on('-c', '--commit', 'Commit any uncommitted changes before pushing to remotes') do |c|
18
+ options[:commit] = c
19
+ end
20
+
21
+ opts.on('-e', '--empty', 'Allow commits with no changes') do |e|
22
+ options[:allow_empty] = e
23
+ end
24
+
25
+ opts.on('-t', '--tags', 'Push all local tags with selected branch') do |t|
26
+ options[:tags] = t
27
+ end
28
+
29
+ #---
30
+
31
+ options[:message] = ''
32
+ opts.on('-m', '--message MESSAGE', 'Commit message') do |m|
33
+ options[:message] = m
34
+ end
35
+
36
+ options[:author] = ''
37
+ opts.on('-a', '--author AUTHOR', 'Author of the changes being committed if different from the committer') do |a|
38
+ options[:author] = a
39
+ end
40
+
41
+ options[:branch] = ''
42
+ opts.on('-b', '--branch BRANCH', 'Local branch of the remotes to push') do |b|
43
+ options[:branch] = b
44
+ end
45
+
46
+ options[:repos] = ''
47
+ opts.on('-r', '--repos REPO_DIR,...', 'Local directories of repositories to push relative to the Vagrantfile root') do |r|
48
+ options[:repos] = r
49
+ end
50
+ end
51
+
52
+ options[:auth] = true
53
+
54
+ #---
55
+
56
+ remotes = parse_options(opts)
57
+ return unless remotes
58
+
59
+ if remotes.empty?
60
+ remotes = [ 'all' ]
61
+ end
62
+
63
+ remotes.each do |remote_name|
64
+ @env.ui.info("Starting push for: #{remote_name}")
65
+
66
+ server = Cloud::Server.new({
67
+ :cloud => Coral.vagrant,
68
+ :machine => remote_name,
69
+ :logger => @logger,
70
+ :ui => @env.ui,
71
+ })
72
+
73
+ if options[:commit]
74
+ success = server.commit(options) if success
75
+ end
76
+ success = server.push(options) if success
77
+ end
78
+ exit success ? 0 : 1
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,37 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralRemove < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral rm -h {name} [ {type} ]'
15
+ opts.separator ''
16
+
17
+ end
18
+
19
+ #---
20
+
21
+ args = parse_options(opts)
22
+ return unless args
23
+
24
+ raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if args.length < 1
25
+
26
+ project_name = args[0]
27
+ project_type = ( args.size < 2 ? 'module' : args[1] )
28
+
29
+ #---------
30
+ # Start
31
+
32
+ exit success ? 0 : 1
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralRun < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral run --dir={plan_dir} {plan_name} ...'
15
+ opts.separator ''
16
+
17
+ options[:repo] = '.'
18
+ opts.on('-r', '--repo REPO_DIR', 'Local directory of repository relative to the Vagrantfile root (.)') do |r|
19
+ options[:repo] = r
20
+ end
21
+
22
+ options[:directory] = 'plans'
23
+ opts.on('-d', '--dir DIRECTORY', 'Local directory that contains the plan(s) being executed (plans)') do |d|
24
+ options[:directory] = d
25
+ end
26
+ end
27
+
28
+ #---
29
+
30
+ plans = parse_options(opts)
31
+ return unless plans
32
+
33
+ plans.each do |plan_name|
34
+ @logger.debug("Running plan: #{plan_name}")
35
+
36
+ success = Coral.create_plan(plan_name, {
37
+ :home => Coral.vagrant,
38
+ :submodule => options[:repo],
39
+ :config_file => File.join([ options[:directory].to_s, "#{plan_name}.json" ]),
40
+ :logger => @logger,
41
+ :ui => @env.ui,
42
+ }).run(options)
43
+
44
+ break unless success
45
+ end
46
+
47
+ exit success ? 0 : 1
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralSend < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral send {provider} ...'
15
+ opts.separator ''
16
+
17
+ options[:tries] = 1
18
+ opts.on('-t', '--tries TRIES', 'Number of times to try sending to provider before stopping with an error (1)') do |t|
19
+ options[:tries] = t
20
+ end
21
+ end
22
+
23
+ options[:auth] = true
24
+
25
+ #---
26
+
27
+ providers = parse_options(opts)
28
+ return unless providers
29
+
30
+ raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if providers.length < 1
31
+
32
+ #---------
33
+ # Start
34
+
35
+
36
+
37
+ exit success ? 0 : 1
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ module Coral
2
+ module Vagrant
3
+ module SubCommand
4
+ class CoralUpdate < ::Vagrant.plugin('2', :command)
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Execution
8
+
9
+ def execute
10
+ options = {}
11
+ success = true
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: coral init -h [ {server_name} ... ]'
15
+ opts.separator ''
16
+
17
+ options[:min] = 1
18
+ opts.on('-m', '--min TRIES', 'Minimum number of provision runs (1)') do |m|
19
+ options[:min] = m
20
+ end
21
+
22
+ options[:tries] = 1
23
+ opts.on('-t', '--tries TRIES', 'Number of provision attempts before stopping with an error (1)') do |t|
24
+ options[:tries] = t
25
+ end
26
+
27
+ options[:exit] = ''
28
+ opts.on('-e', '--exit CONDITIONS', 'Conditions on which to exit in the format separated by comma: "User[git]:ensure:created"') do |e|
29
+ options[:exit] = e
30
+ end
31
+
32
+ options[:repos] = ''
33
+ opts.on('-r', '--repos REPO_DIR,...', 'Local directories of repositories to push relative to the Vagrantfile root') do |r|
34
+ options[:repos] = r
35
+ end
36
+ end
37
+
38
+ options[:auth] = true
39
+
40
+ #---
41
+
42
+ servers = parse_options(opts)
43
+ return unless servers
44
+
45
+ with_target_vms(servers) do |vm|
46
+ @env.ui.info("Starting update run for: #{vm.name}")
47
+
48
+ success = Cloud::Server.new({
49
+ :cloud => Coral.vagrant,
50
+ :machine => vm,
51
+ :logger => @logger,
52
+ :ui => @env.ui,
53
+ }).update(options) if success
54
+ end
55
+ exit success ? 0 : 1
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,79 +1,166 @@
1
-
2
- module Vagrant
3
- module Command
4
1
  module Coral
5
- class Base < Base
6
-
7
- #-----------------------------------------------------------------------------
8
- # Constructor / Destructor
2
+ module Vagrant
3
+ module Command
4
+ class CoralBase < ::Vagrant.plugin("2", :command)
9
5
 
10
- def initialize(argv, env)
11
- super
6
+ #-----------------------------------------------------------------------------
7
+ # Constructor / Destructor
8
+
9
+ def initialize(argv, env)
10
+ super
12
11
 
13
- @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
14
13
 
15
- @subcommands = Registry.new
16
- @subcommands.register(:init) { Vagrant::Command::Coral::Init }
17
- @subcommands.register(:update) { Vagrant::Command::Coral::Update }
18
- @subcommands.register(:push) { Vagrant::Command::Coral::Push }
19
- @subcommands.register(:run) { Vagrant::Command::Coral::Run }
20
- end
21
-
22
- #-----------------------------------------------------------------------------
23
- # Help
24
-
25
- def help
26
- opts = OptionParser.new do |opts|
27
- opts.banner = "Usage: vagrant coral <command> [<args>]"
28
- opts.separator ""
29
- opts.separator "Available subcommands:"
30
-
31
- # Add the available subcommands as separators in order to print them
32
- # out as well.
33
- keys = []
34
- @subcommands.each { |key, value| keys << key.to_s }
35
-
36
- keys.sort.each do |key|
37
- opts.separator " #{key}"
38
- end
14
+ @subcommands = ::Vagrant::Registry.new
39
15
 
40
- opts.separator ""
41
- opts.separator "For help on any individual command run `vagrant coral COMMAND -h`"
42
- end
16
+ #------------
17
+ # Builders
43
18
 
44
- @env.ui.info(opts.help, :prefix => false)
45
- end
46
-
47
- #-----------------------------------------------------------------------------
48
- # Execution
49
-
50
- def execute
51
- if @main_args.include?("-h") || @main_args.include?("--help")
52
- # Print the help for all the cluster commands.
53
- return help
54
- end
19
+ #
20
+ # coral create --repo={cluster_repository} [ {project_path} ]
21
+ #
22
+ # {cluster_repository} -> Defaults to the coral cluster core
23
+ # {project_path} -> Defaults to the current directory (must be empty)
24
+ #
25
+ # * calls: coral init
26
+ #
27
+ @subcommands.register(:create) { Coral::Vagrant::SubCommand::CoralCreate }
55
28
 
56
- # If we reached this far then we must have a subcommand. If not,
57
- # then we also just print the help and exit.
58
- command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
59
-
60
- if ! command_class && @sub_command
61
- command_class = @subcommands.get(:run)
62
- @sub_args.unshift(@sub_command)
63
- end
64
-
65
- return help if !command_class || !@sub_command
66
- @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
29
+ #
30
+ # coral add --repo={repository} {name} [ {type} ]
31
+ #
32
+ # {name} -> Name of the project (required)
33
+ # {type} -> Defaults to module (can be: cluster, profile, module)
34
+ # {repository} -> Defaults to a new template repository of {type}
35
+ #
36
+ @subcommands.register(:add) { Coral::Vagrant::SubCommand::CoralAdd }
67
37
 
68
- # Initialize and execute the command class
69
- command_class.new(@sub_args, @env).execute
70
- end
71
- end
72
- end
73
- end
74
- end
38
+ #
39
+ # coral rm {name} [ {type} ]
40
+ #
41
+ # {name} -> Name of the project (required)
42
+ # {type} -> Defaults to module (can be: cluster, profile, module)
43
+ #
44
+ @subcommands.register(:rm) { Coral::Vagrant::SubCommand::CoralRemove }
45
+
46
+ #------------------------------
47
+ # Configuration / Deployment
48
+
49
+ #
50
+ # coral config --dir={config_dir} {config_name} [ {value} ]
51
+ #
52
+ # {config_name} -> Dot separated configuration name (dot = directory entry)
53
+ # {value} -> Configuration value (if we are setting the configuration)
54
+ # {config_dir} -> Root directory of configuration files (default: config)
55
+ #
56
+ @subcommands.register(:config) { Coral::Vagrant::SubCommand::CoralConfig }
57
+
58
+ #
59
+ # coral push --repos={repository_name},... [ {server_name} ... ]
60
+ #
61
+ # {server_name} -> Server name of a local or remote server to push attached repositories to
62
+ # {repository_name} -> Local repository name for a local/remote repository relationship
63
+ #
64
+ @subcommands.register(:push) { Coral::Vagrant::SubCommand::CoralPush }
65
+
66
+ #
67
+ # coral send {provider} ...
68
+ #
69
+ # {provider} -> Remote cloud provider on which to send and initialize the coral cluster
70
+ #
71
+ # * calls: coral init
72
+ # coral image
73
+ #
74
+ @subcommands.register(:send) { Coral::Vagrant::SubCommand::CoralSend }
75
75
 
76
- #-------------------------------------------------------------------------------
76
+ #
77
+ # coral image --servers={server_name},... {provider} ...
78
+ #
79
+ # {provider} -> Remote cloud provider on which to create the image
80
+ # {server_name} -> Server name of a cluster server to create an image of
81
+ #
82
+ @subcommands.register(:image) { Coral::Vagrant::SubCommand::CoralImage }
77
83
 
78
- Vagrant.commands.register(:coral) { Vagrant::Command::Coral::Base }
84
+ #--------------
85
+ # Management
79
86
 
87
+ #
88
+ # coral init [ {server_name} ... ]
89
+ #
90
+ # {server_name} -> Server name of a cluster server to initialize
91
+ #
92
+ @subcommands.register(:init) { Coral::Vagrant::SubCommand::CoralInit }
93
+
94
+ #
95
+ # coral update [ {server_name} ... ]
96
+ #
97
+ # {server_name} -> Server name of a cluster server to update
98
+ #
99
+ @subcommands.register(:update) { Coral::Vagrant::SubCommand::CoralUpdate }
100
+
101
+ #
102
+ # coral run --dir={plan_dir} {plan_name} ...
103
+ #
104
+ # {plan_name} -> Name of JSON based execution plan to run
105
+ # {plan_dir} -> Root directory of exexution plan files (default: config/plans)
106
+ #
107
+ # * could call anything
108
+ #
109
+ @subcommands.register(:run) { Coral::Vagrant::SubCommand::CoralRun }
110
+ end
111
+
112
+ #-----------------------------------------------------------------------------
113
+ # Help
114
+
115
+ def help
116
+ opts = OptionParser.new do |opts|
117
+ opts.banner = 'Usage: vagrant coral <command> [<args>]'
118
+ opts.separator ''
119
+ opts.separator 'Available subcommands:'
120
+
121
+ # Add the available subcommands as separators in order to print them
122
+ # out as well.
123
+ keys = []
124
+ @subcommands.each { |key, value| keys << key.to_s }
125
+
126
+ keys.sort.each do |key|
127
+ opts.separator " #{key}"
128
+ end
129
+
130
+ opts.separator ''
131
+ opts.separator 'For help on any individual command run `vagrant coral COMMAND -h`'
132
+ end
133
+
134
+ @env.ui.info(opts.help, :prefix => false)
135
+ end
136
+
137
+ #-----------------------------------------------------------------------------
138
+ # Execution
139
+
140
+ def execute
141
+ if @main_args.include?('-h') || @main_args.include?('--help')
142
+ # Print the help for all the cluster commands.
143
+ return help
144
+ end
145
+
146
+ # Fetch our command class if we have a subcommand.
147
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
148
+
149
+ # If there is no class mapping, we try running the subcommand as an
150
+ # execution plan.
151
+ if !command_class && @sub_command
152
+ command_class = @subcommands.get(:run)
153
+ @sub_args.unshift(@sub_command)
154
+ end
155
+ # If all else fails print the help and exit.
156
+ return help if !command_class || !@sub_command
157
+
158
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
159
+
160
+ # Initialize and execute the command class
161
+ command_class.new(@sub_args, @env).execute
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end