corl 0.5.14 → 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7aa748974143ba8a58a9d80fb344ccb4156060d
4
- data.tar.gz: 8c3937130f2468a5462adc2fdb1171c730762387
3
+ metadata.gz: c360e505e5eaa8bdea103dad27a7868f06655153
4
+ data.tar.gz: 8cf2016ccc74e060bfa91372e7b54481b1a06a83
5
5
  SHA512:
6
- metadata.gz: 333a02982ceb698acec7f3d5c2064b327b783cefe0315e2d1b4eb6390f88988134c9d9a49c496bea297eb5dd946f96bd86099d41eb80ded6fcdfaf07fc36606d
7
- data.tar.gz: 9f086aca3037fa7c37eca60dc406d0167b0cacfd5b1577718ced41c36737500f58955eeb05cb9222f625ba996a3c64924fe69386a46330495b56fe6c043960c7
6
+ metadata.gz: f16e3bfa746c95710bd6e6b5aa0374e0de28ff8fe98374d76f237b74dbc9fdc341cc7880fbf5e4a5504122f739a7b337b19224340377e5f25d130acb01606ee3
7
+ data.tar.gz: f4e9f8fe0ca6e9478ae96018b346fcbb5ae509d10de97146cae1520b18787ec16ec673fa0f4ab46de9c795b0b3354abd4fff4a4ce36dc719b040e938382b6214
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.14
1
+ 0.5.15
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
  #-------------------------------------------------------------------------------
3
3
 
4
- PUPPET_PACKAGE="3.7.3-1puppetlabs1"
4
+ PUPPET_PACKAGE="3.7.4-1puppetlabs1"
5
5
 
6
6
  #---
7
7
 
data/corl.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: corl 0.5.14 ruby lib
5
+ # stub: corl 0.5.15 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "corl"
9
- s.version = "0.5.14"
9
+ s.version = "0.5.15"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Adrian Webb"]
14
- s.date = "2015-02-09"
14
+ s.date = "2015-02-19"
15
15
  s.description = "Framework that provides a simple foundation for growing organically in the cloud"
16
16
  s.email = "adrian.webb@coralnexus.com"
17
17
  s.executables = ["corl"]
@@ -144,6 +144,7 @@ Gem::Specification.new do |s|
144
144
  "lib/nucleon/action/plugins.rb",
145
145
  "lib/nucleon/event/puppet.rb",
146
146
  "lib/nucleon/extension/corl_config.rb",
147
+ "lib/nucleon/extension/corl_executable.rb",
147
148
  "lib/nucleon/extension/vagrant.rb",
148
149
  "lib/nucleon/template/environment.rb",
149
150
  "lib/puppet/indirector/corl.rb",
@@ -3,55 +3,55 @@ module CORL
3
3
  module Mixin
4
4
  module Macro
5
5
  module NetworkSettings
6
-
6
+
7
7
  def network_settings(_type)
8
-
8
+
9
9
  # Networks are inherited unless explicitely set
10
-
10
+
11
11
  define_method :network do
12
12
  plugin_parent
13
13
  end
14
-
14
+
15
15
  define_method :network= do |network|
16
16
  myself.plugin_parent = network
17
17
  end
18
-
18
+
19
19
  #---
20
-
20
+
21
21
  define_method :setting do |property, default = nil, format = false|
22
22
  network.send("#{_type}_setting", plugin_provider, plugin_name, property, default, format)
23
23
  end
24
-
24
+
25
25
  define_method :search do |property, default = nil, format = false, extra_groups = []|
26
26
  network.send("search_#{_type}", plugin_provider, plugin_name, property, default, format, extra_groups)
27
27
  end
28
-
28
+
29
29
  define_method :set_setting do |property, value = nil|
30
30
  network.send("set_#{_type}_setting", plugin_provider, plugin_name, property, value)
31
31
  end
32
-
32
+
33
33
  define_method :delete_setting do |property|
34
34
  network.send("delete_#{_type}_setting", plugin_provider, plugin_name, property)
35
35
  end
36
-
36
+
37
37
  #---
38
-
38
+
39
39
  define_method :[] do |name, default = nil, format = false|
40
40
  search(name, default, format)
41
41
  end
42
-
42
+
43
43
  #---
44
-
44
+
45
45
  define_method :[]= do |name, value|
46
46
  set_setting(name, value)
47
47
  end
48
-
48
+
49
49
  #---
50
-
50
+
51
51
  define_method :cache do
52
52
  network.cache
53
53
  end
54
-
54
+
55
55
  define_method :cache_setting do |keys, default = nil, format = false|
56
56
  cache.get([ _type, plugin_provider, plugin_name, keys ].flatten, default, format)
57
57
  end
@@ -69,22 +69,22 @@ module NetworkSettings
69
69
  end
70
70
 
71
71
  #---
72
-
72
+
73
73
  define_method :groups do
74
74
  array(myself[:settings])
75
75
  end
76
-
76
+
77
77
  #---
78
-
78
+
79
79
  define_method :add_groups do |groups|
80
80
  myself[:settings] = array(setting(:settings)) | array(groups)
81
81
  end
82
-
82
+
83
83
  #---
84
-
84
+
85
85
  define_method :remove_groups do |groups|
86
86
  myself[:settings] = array(setting(:settings)) - array(groups)
87
- end
87
+ end
88
88
  end
89
89
  end
90
90
  end
@@ -7,6 +7,15 @@ module Nucleon
7
7
  module Plugin
8
8
  class Agent < Nucleon.plugin_class(:nucleon, :cloud_action)
9
9
 
10
+ #-----------------------------------------------------------------------------
11
+ # Info
12
+
13
+ def self.describe_base(group = nil, action = 'unknown', weight = -1000, description = nil, help = nil, provider_override = nil)
14
+ group = array(group).collect! {|item| item.to_sym }
15
+ group = [ :agent ] | group
16
+ super(group.uniq, action, weight, description, help, provider_override)
17
+ end
18
+
10
19
  #-----------------------------------------------------------------------------
11
20
  # Property accessor / modifiers
12
21
 
@@ -19,9 +28,13 @@ class Agent < Nucleon.plugin_class(:nucleon, :cloud_action)
19
28
 
20
29
  #---
21
30
 
22
- def help
23
- # TODO: Localization
24
- 'AGENT ' + super
31
+ def arguments
32
+ # Don't use or the default log file naming will screw up due to having to
33
+ # move daemonization to the corl loader.
34
+ #
35
+ # See: lib/corl.rb
36
+ #
37
+ []
25
38
  end
26
39
 
27
40
  #-----------------------------------------------------------------------------
@@ -34,100 +47,49 @@ class Agent < Nucleon.plugin_class(:nucleon, :cloud_action)
34
47
  #---
35
48
 
36
49
  def agent_config
50
+ register_bool :log, true, 'corl.core.action.agent.options.log'
51
+ register_bool :truncate_log, true, 'corl.core.action.agent.options.truncate_log'
52
+
53
+ register_str :log_file, "/var/log/corl/#{plugin_provider}.log", 'corl.core.action.agent.options.log_file'
37
54
  end
38
55
 
39
56
  #-----------------------------------------------------------------------------
40
57
  # Operations
41
58
 
42
- def execute(use_network = true, &code)
59
+ def execute(use_network = true, &block)
43
60
  super do |node|
44
61
  ensure_network do
45
- daemonize(node)
46
- yield node
47
- end
48
- end
49
- end
50
-
51
- #---
52
-
53
- def daemonize(node)
54
- # Mostly derived from rack gem implementation
55
- #
56
- # https://github.com/rack/rack/blob/master/lib/rack/server.rb
57
- # http://www.jstorimer.com/blogs/workingwithcode/7766093-daemon-processes-in-ruby
58
- #
59
- if RUBY_VERSION < "1.9"
60
- exit if fork
61
- Process.setsid
62
- safe_exit if fork
63
-
64
- Dir.chdir network.directory
65
-
66
- STDIN.reopen "/dev/null"
67
- STDOUT.reopen "/dev/null", "a"
68
- STDERR.reopen "/dev/null", "a"
69
- else
70
- Process.daemon
71
- end
62
+ add_agent(node)
72
63
 
73
- #---
64
+ trap(:INT) do
65
+ safe_exit
66
+ end
74
67
 
75
- save_process(node)
76
-
77
- at_exit do
78
- shutdown_process(node)
79
- end
80
-
81
- trap(:INT) do
82
- safe_exit
68
+ block.call(node)
69
+ remove_agent(node) if myself.status == code.success
70
+ end
83
71
  end
84
72
  end
85
- protected :daemonize
86
73
 
87
74
  #-----------------------------------------------------------------------------
88
75
  # Utilities
89
76
 
90
- def process_status(node)
91
- agent_settings = node.agent(plugin_provider)
92
-
93
- return :not_running unless agent_settings && agent_settings.has_key?(:pid)
94
- return :dead if agent_settings[:pid] == 0
95
-
96
- Process.kill(0, agent_settings[:pid])
97
- :running
98
-
99
- rescue Errno::ESRCH
100
- :dead
101
- rescue Errno::EPERM
102
- :not_owned
103
- end
104
- protected :process_status
105
-
106
- #---
107
-
108
- def save_process(node)
77
+ def add_agent(node)
109
78
  settings[:pid] = Process.pid
110
79
 
111
- node.add_agent(plugin_provider, settings)
112
- node.save({
113
- :message => "Agent #{plugin_provider} starting up on #{node.plugin_name}",
114
- :remote => extension_set(:write_process_remote, :edit),
115
- :push => true
116
- })
80
+ stored_config = Util::Data.clean(settings.export)
81
+ stored_config = Util::Data.rm_keys(stored_config, [ :node_provider, :nodes, :color, :version ])
82
+
83
+ node.add_agent(plugin_provider, stored_config)
117
84
  end
118
- protected :save_process
85
+ protected :add_agent
119
86
 
120
87
  #---
121
88
 
122
- def shutdown_process(node)
89
+ def remove_agent(node)
123
90
  node.remove_agent(plugin_provider)
124
- node.save({
125
- :message => "Agent #{plugin_provider} shutting down on #{node.plugin_name}",
126
- :remote => extension_set(:shutdown_handler_remote, :edit),
127
- :push => true
128
- })
129
91
  end
130
- protected :shutdown_process
92
+ protected :remove_agent
131
93
 
132
94
  #---
133
95
 
@@ -221,7 +221,14 @@ class FogBase < Nucleon.plugin_class(:CORL, :node)
221
221
  # Utilities
222
222
 
223
223
  def filter_output(type, data)
224
- super
224
+ data = super
225
+
226
+ if type == :error
227
+ if data.include?('stdin: is not a tty') || data.include?('unable to re-open stdin')
228
+ data = ''
229
+ end
230
+ end
231
+ data
225
232
  end
226
233
  end
227
234
  end
@@ -336,7 +336,7 @@ class Network < Nucleon.plugin_class(:nucleon, :base)
336
336
  remote_name = config.delete(:remote, :edit)
337
337
 
338
338
  node_config = extended_config(:network_new_node, Config.new(Util::Data.clean({
339
- :settings => array(config.delete(:groups, [])) | [ "server" ],
339
+ :settings => [ "server" ] | array(config.delete(:groups, [])),
340
340
  :region => config.delete(:region, nil),
341
341
  :machine_type => config.delete(:machine_type, nil),
342
342
  :public_ip => config.delete(:public_ip, nil),
@@ -21,7 +21,7 @@ class Node < Nucleon.plugin_class(:nucleon, :base)
21
21
  ui.resource = Util::Console.colorize(hostname, @class_color)
22
22
  logger = hostname
23
23
 
24
- add_groups([ "all", plugin_provider.to_s, plugin_name.to_s ])
24
+ myself[:settings] = [ "all", plugin_provider.to_s, plugin_name.to_s ] | array(setting(:settings))
25
25
 
26
26
  unless reload
27
27
  @cli_interface = Util::Liquid.new do |method, args, &code|
@@ -386,10 +386,22 @@ class Node < Nucleon.plugin_class(:nucleon, :base)
386
386
 
387
387
  def add_agent(provider, settings)
388
388
  set_setting([ :agents, provider ], Config.new(settings).export)
389
+
390
+ save({
391
+ :message => "Agent #{provider} starting up on #{plugin_provider} #{plugin_name}",
392
+ :remote => extension_set(:add_agent_remote, :edit),
393
+ :push => true
394
+ })
389
395
  end
390
396
 
391
397
  def remove_agent(provider)
392
398
  delete_setting([ :agents, provider ])
399
+
400
+ save({
401
+ :message => "Agent #{provider} shutting down on #{plugin_provider} #{plugin_name}",
402
+ :remote => extension_set(:remove_agent_remote, :edit),
403
+ :push => true
404
+ })
393
405
  end
394
406
 
395
407
  #-----------------------------------------------------------------------------
@@ -830,20 +842,21 @@ class Node < Nucleon.plugin_class(:nucleon, :base)
830
842
 
831
843
  begin
832
844
  test = active_machine.exec(Util::Data.array(commands), config.export) do |type, command, data|
845
+ data = filter_output(type, data).rstrip
846
+
833
847
  unless quiet
834
848
  unless local?
835
- text_output = filter_output(type, data).rstrip
836
-
837
- unless text_output.empty?
849
+ unless data.empty?
838
850
  if type == :error
839
- warn(text_output, { :i18n => false })
851
+ warn(data, { :i18n => false })
840
852
  else
841
- info(text_output, { :i18n => false })
853
+ info(data, { :i18n => false })
842
854
  end
843
855
  end
844
856
  end
845
857
  yield(:progress, { :type => type, :command => command, :data => data }) if block_given?
846
858
  end
859
+ data
847
860
  end
848
861
  results = test if test
849
862
 
@@ -919,32 +932,37 @@ class Node < Nucleon.plugin_class(:nucleon, :base)
919
932
  codes :network_load_error
920
933
 
921
934
  config = Config.ensure(options).defaults({
922
- :log_level => Nucleon.log_level,
923
935
  :net_remote => :edit,
924
936
  :net_provider => network.plugin_provider
925
937
  })
926
938
 
927
939
  logger.info("Executing remote action #{provider} with encoded arguments: #{config.export.inspect}")
928
940
 
941
+ provider = provider.to_s.gsub('_', ' ')
942
+ action_agent = !!(provider =~ /^agent\s/)
929
943
  encoded_config = Util::CLI.encode(Util::Data.clean(config.export))
930
944
  action_config = extended_config(:action, {
931
- :command => provider.to_s.gsub('_', ' '),
932
- :data => { :encoded => encoded_config }
945
+ :command => provider,
946
+ :data => { :encoded => encoded_config }
933
947
  })
948
+ action_config[:data][:log_level] = Nucleon.log_level if Nucleon.log_level
934
949
 
935
950
  quiet = config.get(:quiet, false)
936
951
  parallel = config.get(:parallel, true)
937
952
 
938
953
  command_base = 'corl'
939
954
  command_base = "NUCLEON_NO_PARALLEL=1 #{command_base}" unless parallel
955
+ command_base = "NUCLEON_NO_COLOR=1 #{command_base}" if action_agent
940
956
 
941
957
  result = command(command_base, { :subcommand => action_config, :as_admin => true, :quiet => quiet }) do |op, data|
942
958
  yield(op, data) if block_given?
943
959
  end
944
960
 
945
961
  # Update local network configuration so we capture any updates
946
- if result.status == code.success && ! network.load({ :remote => config[:net_remote], :pull => true })
947
- result.status = code.network_load_error
962
+ unless action_agent
963
+ if result.status == code.success && ! network.load({ :remote => config[:net_remote], :pull => true })
964
+ result.status = code.network_load_error
965
+ end
948
966
  end
949
967
  result
950
968
  end
@@ -4,8 +4,6 @@ module CORL
4
4
  module Command
5
5
  class Launcher < ::Vagrant.plugin("2", :command)
6
6
 
7
- include ::CORL::Parallel # Mainly for auto locking of resources
8
-
9
7
  #-----------------------------------------------------------------------------
10
8
 
11
9
  def self.synopsis
@@ -375,8 +375,11 @@ module Config
375
375
 
376
376
  if use_nfs && bindfs_installed
377
377
  machine.vm.synced_folder ".", "/vagrant", disabled: true
378
- machine.vm.synced_folder ".", "/tmp/vagrant", :type => "nfs"
379
- machine.bindfs.bind_folder "/tmp/vagrant", "/vagrant"
378
+
379
+ unless ENV['CORL_NO_NETWORK_SHARE']
380
+ machine.vm.synced_folder ".", "/tmp/vagrant", :type => "nfs"
381
+ machine.bindfs.bind_folder "/tmp/vagrant", "/vagrant"
382
+ end
380
383
  end
381
384
 
382
385
  render("\n") unless already_processed
@@ -1,6 +1,6 @@
1
1
 
2
- if Vagrant::VERSION < "1.2.0"
3
- raise "The Vagrant CORL plugin is only compatible with Vagrant 1.2+"
2
+ if Vagrant::VERSION < "1.5.0"
3
+ raise "The Vagrant CORL plugin is only compatible with Vagrant 1.5+"
4
4
  end
5
5
 
6
6
  module VagrantPlugins
data/lib/corl.rb CHANGED
@@ -24,6 +24,81 @@ util_dir = File.join(core_dir, 'util')
24
24
  mod_dir = File.join(core_dir, 'mod')
25
25
  vagrant_dir = File.join(core_dir, 'vagrant')
26
26
 
27
+ vagrant_exists = defined?(Vagrant) == 'constant' && Vagrant.class == Module
28
+
29
+ #-------------------------------------------------------------------------------
30
+ # Daemonize if needed
31
+ #
32
+ # This must come before Nucleon is loaded due to a huge bug in Celluloid that
33
+ # prevents it from working in parallel mode if Celluloid actors are already
34
+ # initialized before daemonization.
35
+
36
+ # Must be an agent that is running locally
37
+
38
+ # For the record, this stinks, it's ugly, and I hate it, but the maintainer
39
+ # of Celluloid does not seem to regard it as important enough to fix.
40
+ #
41
+ # https://github.com/celluloid/celluloid/issues/97
42
+ #
43
+ # For agent options processed here, see lib/core/plugin/agent.rb
44
+ #
45
+ action_start_index = vagrant_exists ? 1 : 0
46
+
47
+ if ARGV[action_start_index].to_sym == :agent
48
+ remote_exec = false
49
+
50
+ log = true
51
+ truncate_log = true
52
+
53
+ log_file = nil
54
+ agent_provider = []
55
+ process_log_file_value = false
56
+
57
+ first_option_found = false
58
+
59
+ # Argument processing
60
+ ARGV[(action_start_index + 1)..-1].each do |arg|
61
+ first_option_found = true if arg[0] == '-'
62
+
63
+ if arg =~ /^\-\-nodes\=?/
64
+ remote_exec = true
65
+ elsif arg == "--no-log"
66
+ log = false
67
+ elsif arg == "--no-truncate_log"
68
+ truncate_log = false
69
+ elsif arg =~ /^\-\-log_file(?=\=(.*))?/
70
+ if $1
71
+ log_file = $1
72
+ else
73
+ process_log_file_value = true
74
+ end
75
+ elsif process_log_file_value
76
+ log_file = arg
77
+ process_log_file_value = false
78
+ elsif ! first_option_found
79
+ agent_provider << arg
80
+ end
81
+ end
82
+
83
+ # TODO: Need better way to share with base agent default log file. (mixin?)
84
+ log_file = "/var/log/corl/agent_#{agent_provider.join('_')}.log" unless log_file
85
+
86
+ unless remote_exec || vagrant_exists
87
+ # Daemonize process
88
+ Process.daemon
89
+
90
+ # Log all output, or not
91
+ if log
92
+ FileUtils.mkdir_p('/var/log/corl')
93
+ File.write(log_file, '') if truncate_log
94
+
95
+ $stderr.reopen(log_file, 'a')
96
+ $stdout.reopen($stderr)
97
+ $stdout.sync = $stderr.sync = true
98
+ end
99
+ end
100
+ end
101
+
27
102
  #-------------------------------------------------------------------------------
28
103
  # CORL requirements
29
104
 
@@ -103,9 +178,8 @@ nucleon_require(core_dir, :build)
103
178
  nucleon_require(core_dir, :plugin)
104
179
 
105
180
  # Include Vagrant plugins (only include if running inside Vagrant)
106
- if defined?(Vagrant) == 'constant' && Vagrant.class == Module
107
- nucleon_require(vagrant_dir, :plugins)
108
- end
181
+ nucleon_require(vagrant_dir, :plugins) if vagrant_exists
182
+
109
183
 
110
184
  #-------------------------------------------------------------------------------
111
185
  # CORL interface
@@ -35,10 +35,6 @@ class Config < Nucleon.plugin_class(:nucleon, :cloud_action)
35
35
 
36
36
  #---
37
37
 
38
- def ignore
39
- node_ignore
40
- end
41
-
42
38
  def arguments
43
39
  [ :name, :value ]
44
40
  end
@@ -0,0 +1,12 @@
1
+
2
+ module Nucleon
3
+ module Extension
4
+ class CorlExecutable < Nucleon.plugin_class(:nucleon, :extension)
5
+
6
+ def executable_load(config)
7
+ network_path = Nucleon.fact(:corl_network)
8
+ Nucleon.load_plugins(network_path) if Dir.pwd != network_path
9
+ end
10
+ end
11
+ end
12
+ end
data/locales/en.yml CHANGED
@@ -23,6 +23,14 @@ en:
23
23
  Node plugin provider %{value} is not loaded >> Pick from the following: %{choices}
24
24
  nodes: |-
25
25
  Node reference %{value} failed to parse or provider %{provider} isn't loaded (%{name})
26
+ agent:
27
+ options:
28
+ log: |-
29
+ Whether or not to render agent stdout and stderr to a log file (default %{default_value})
30
+ truncate_log: |-
31
+ Truncate log file before writing any more output (default %{default_value})
32
+ log_file: |-
33
+ Log file to route agent output (default %{default_value})
26
34
  node:
27
35
  bootstrap:
28
36
  status: |-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Webb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nucleon
@@ -304,6 +304,7 @@ files:
304
304
  - lib/nucleon/action/plugins.rb
305
305
  - lib/nucleon/event/puppet.rb
306
306
  - lib/nucleon/extension/corl_config.rb
307
+ - lib/nucleon/extension/corl_executable.rb
307
308
  - lib/nucleon/extension/vagrant.rb
308
309
  - lib/nucleon/template/environment.rb
309
310
  - lib/puppet/indirector/corl.rb