auser-poolparty 0.2.9 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/Manifest.txt +33 -4
  2. data/PostInstall.txt +3 -1
  3. data/bin/cloud-provision +8 -4
  4. data/bin/cloud-start +2 -0
  5. data/bin/server-get-load +29 -0
  6. data/bin/server-list-active +1 -1
  7. data/bin/server-rerun +24 -0
  8. data/config/requirements.rb +1 -1
  9. data/lib/erlang/messenger/Makefile +15 -0
  10. data/lib/erlang/messenger/README +5 -0
  11. data/lib/erlang/messenger/Rakefile +39 -0
  12. data/lib/erlang/messenger/control +11 -0
  13. data/lib/erlang/messenger/ebin/erl_crash.dump +12138 -0
  14. data/lib/erlang/messenger/ebin/load_app.beam +0 -0
  15. data/lib/erlang/messenger/ebin/pm_master.beam +0 -0
  16. data/lib/erlang/messenger/ebin/pm_master_supervisor.beam +0 -0
  17. data/lib/erlang/messenger/ebin/pm_node.beam +0 -0
  18. data/lib/erlang/messenger/ebin/pm_node_supervisor.beam +0 -0
  19. data/lib/erlang/messenger/lib/load_app.app +18 -0
  20. data/lib/erlang/messenger/src/load_app.erl +26 -0
  21. data/lib/erlang/messenger/src/pm_cluster.erl +31 -0
  22. data/lib/erlang/messenger/src/pm_master.erl +27 -0
  23. data/lib/erlang/messenger/src/pm_master_supervisor.erl +8 -0
  24. data/lib/erlang/messenger/src/pm_node.erl +79 -0
  25. data/lib/erlang/messenger/src/pm_node_supervisor.erl +33 -0
  26. data/lib/poolparty.rb +9 -6
  27. data/lib/poolparty/base_packages/haproxy.rb +9 -2
  28. data/lib/poolparty/base_packages/heartbeat.rb +31 -30
  29. data/lib/poolparty/base_packages/poolparty.rb +30 -17
  30. data/lib/poolparty/base_packages/ruby.rb +1 -2
  31. data/lib/poolparty/core/array.rb +2 -2
  32. data/lib/poolparty/core/hash.rb +16 -2
  33. data/lib/poolparty/core/string.rb +1 -1
  34. data/lib/poolparty/core/symbol.rb +2 -2
  35. data/lib/poolparty/dependency_resolutions/base.rb +12 -0
  36. data/lib/poolparty/dependency_resolutions/puppet.rb +49 -0
  37. data/lib/poolparty/helpers/display.rb +3 -3
  38. data/lib/poolparty/helpers/provisioner_base.rb +6 -6
  39. data/lib/poolparty/helpers/provisioners/master.rb +21 -21
  40. data/lib/poolparty/helpers/provisioners/slave.rb +4 -3
  41. data/lib/poolparty/modules/definable_resource.rb +1 -0
  42. data/lib/poolparty/modules/file_writer.rb +11 -18
  43. data/lib/poolparty/modules/method_missing_sugar.rb +1 -1
  44. data/lib/poolparty/modules/pretty_printer.rb +11 -11
  45. data/lib/poolparty/modules/resourcing_dsl.rb +57 -0
  46. data/lib/poolparty/monitors/base_monitor.rb +17 -3
  47. data/lib/poolparty/monitors/monitors/cpu_monitor.rb +15 -0
  48. data/lib/poolparty/monitors/monitors/memory_monitor.rb +23 -0
  49. data/lib/poolparty/net/remote_instance.rb +5 -0
  50. data/lib/poolparty/net/remoter.rb +12 -2
  51. data/lib/poolparty/net/remoter_base.rb +5 -1
  52. data/lib/poolparty/plugins/git.rb +24 -15
  53. data/lib/poolparty/pool/base.rb +1 -2
  54. data/lib/poolparty/pool/cloud.rb +14 -9
  55. data/lib/poolparty/pool/custom_resource.rb +6 -6
  56. data/lib/poolparty/pool/resource.rb +53 -104
  57. data/lib/poolparty/pool/resources/class_package.rb +4 -4
  58. data/lib/poolparty/pool/resources/conditional.rb +5 -1
  59. data/lib/poolparty/pool/resources/gem.rb +22 -8
  60. data/lib/poolparty/pool/resources/symlink.rb +10 -6
  61. data/lib/poolparty/pool/resources/variable.rb +1 -1
  62. data/lib/poolparty/templates/ha.cf +3 -3
  63. data/lib/poolparty/templates/haproxy.conf +3 -3
  64. data/lib/poolparty/templates/puppet.conf +1 -1
  65. data/lib/poolparty/version.rb +1 -1
  66. data/poolparty.gemspec +7 -5
  67. data/setup.rb +3 -3
  68. data/spec/poolparty/core/hash_spec.rb +19 -1
  69. data/spec/poolparty/dependency_resolutions/base_spec.rb +11 -0
  70. data/spec/poolparty/modules/file_writer_spec.rb +9 -0
  71. data/spec/poolparty/monitors/base_monitor_spec.rb +19 -0
  72. data/spec/poolparty/monitors/monitors/cpu_monitor_spec.rb +17 -0
  73. data/spec/poolparty/net/remote_instance_spec.rb +6 -1
  74. data/spec/poolparty/net/remoter_spec.rb +2 -1
  75. data/spec/poolparty/pool/cloud_spec.rb +15 -1
  76. data/spec/poolparty/pool/custom_resource_spec.rb +2 -2
  77. data/spec/poolparty/pool/plugin_spec.rb +4 -4
  78. data/spec/poolparty/pool/resource_spec.rb +39 -1
  79. data/spec/poolparty/pool/resources/gem_spec.rb +30 -3
  80. data/spec/poolparty/pool/resources/symlink_spec.rb +4 -1
  81. data/spec/poolparty/spec_helper.rb +1 -0
  82. data/website/index.html +1 -1
  83. metadata +40 -7
  84. data/lib/erlang/eb_server.erl +0 -27
  85. data/lib/poolparty/plugins/gem_package.rb +0 -30
  86. data/lib/poolparty/puppet_plugins/poolparty/plugins/puppet/parser/functions/activenodeips.rb +0 -11
  87. data/lib/poolparty/puppet_plugins/poolparty/plugins/puppet/parser/functions/activenodenames.rb +0 -11
@@ -6,11 +6,25 @@
6
6
  module PoolParty
7
7
  module Monitors
8
8
 
9
+ def self.register_monitor(*args)
10
+ args.each do |arg|
11
+ (available_monitors << "#{arg}".downcase.to_sym)
12
+ end
13
+ end
14
+
15
+ def self.available_monitors
16
+ $available_monitors ||= []
17
+ end
18
+
9
19
  class BaseMonitor
10
20
 
11
-
12
-
21
+ def self.run
22
+ new.run
23
+ end
24
+
13
25
  end
14
26
 
15
27
  end
16
- end
28
+ end
29
+
30
+ Dir["#{File.dirname(__FILE__)}/monitors/*.rb"].each {|f| require f}
@@ -0,0 +1,15 @@
1
+ module PoolParty
2
+ module Monitors
3
+
4
+ class CpuMonitor < BaseMonitor
5
+
6
+ def run
7
+ str = %x[uptime]
8
+ str.split(/\s+/)[-3].to_f rescue 0.0
9
+ end
10
+
11
+ end
12
+
13
+ register_monitor :cpu
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module PoolParty
2
+ module Monitors
3
+
4
+ class MemoryMonitor < BaseMonitor
5
+
6
+ def run
7
+ str = %x[free -m | grep -i mem]
8
+ begin
9
+ total_memory = str.split[1].to_f
10
+ used_memory = str.split[2].to_f
11
+
12
+ used_memory / total_memory
13
+ rescue Exception => e
14
+ 0.0
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ register_monitor :memory
22
+ end
23
+ end
@@ -63,6 +63,11 @@ module PoolParty
63
63
  def to_s
64
64
  "#{name}\t#{ip}"
65
65
  end
66
+
67
+ # Commands for the servers
68
+ def puppet_runner_command
69
+ ". /etc/profile && puppetd --onetime --no-daemonize --logdest syslog --server master > /dev/null 2>&1"
70
+ end
66
71
  end
67
72
 
68
73
  end
@@ -9,7 +9,7 @@ module PoolParty
9
9
  module Remoter
10
10
  def rsync_storage_files_to_command(remote_instance)
11
11
  if remote_instance
12
- "#{rsync_command} #{Base.storage_directory} #{remote_instance.ip}:#{Base.remote_storage_path}"
12
+ "#{rsync_command} #{Base.storage_directory}/ #{remote_instance.ip}:#{Base.remote_storage_path}"
13
13
  end
14
14
  end
15
15
  def run_command_on_command(cmd="ls -l", remote_instance=nil)
@@ -195,7 +195,7 @@ module PoolParty
195
195
  end
196
196
 
197
197
  # Rsync command to the instance
198
- def rsync_storage_files_to(instance=nil)
198
+ def rsync_storage_files_to(instance=nil)
199
199
  hide_output do
200
200
  Kernel.system "#{rsync_storage_files_to_command(instance)}" if instance
201
201
  end
@@ -215,6 +215,16 @@ module PoolParty
215
215
  def ssh_into_instance_number(num=0)
216
216
  ssh_into( get_instance_by_number( num || 0 ) )
217
217
  end
218
+
219
+ # Prepare reconfiguration on the master
220
+ # TODO: Fix the killall
221
+ def prepare_reconfiguration
222
+ unless @prepared
223
+ cmd = "killall ruby && rm -rf /etc/puppet/ssl/*; puppetmasterd --verbose; puppetd --test"
224
+ run_command_on(cmd, master)
225
+ @prepared = true
226
+ end
227
+ end
218
228
 
219
229
  def self.included(receiver)
220
230
  receiver.extend self
@@ -8,7 +8,7 @@ module PoolParty
8
8
 
9
9
  def remote_bases
10
10
  $remote_bases ||= []
11
- end
11
+ end
12
12
 
13
13
  module Remote
14
14
  # This class is the base class for all remote types
@@ -61,6 +61,10 @@ module PoolParty
61
61
  def list_of_nonterminated_instances(list = remote_instances_list)
62
62
  list.reject {|i| i.terminating? || i.terminated? }
63
63
  end
64
+ # get the master instance
65
+ def master
66
+ get_instance_by_number(0)
67
+ end
64
68
  # Get instance by number
65
69
  def get_instance_by_number(i=0, list = remote_instances_list)
66
70
  name = (i.zero? ? "master" : "node#{i}")
@@ -3,33 +3,42 @@ module PoolParty
3
3
 
4
4
  virtual_resource(:git) do
5
5
 
6
- def loaded(opts={})
6
+ def loaded(opts={}, parent=self)
7
7
  install_git
8
- has_git_repos
9
8
  end
10
9
 
11
10
  def install_git
12
- has_package(:name => "git-core")
11
+ has_package(:name => "git-core") do
12
+ has_git_repos
13
+ end
13
14
  end
14
15
 
15
16
  def has_git_repos
16
- with_options(:requires => 'Package["git-core"]') do
17
- # has_directory(:name => "#{path}")
18
-
19
- exec({:name => "git-#{name}"}) do
20
- command @parent.user ? "git clone #{@parent.user}@#{@parent.source} #{@parent.path}" : "git clone #{@parent.source} #{@parent.path}"
21
- cwd "#{::File.dirname(@parent.path) if @parent.path}"
22
- creates "#{@parent.path}/.git"
23
- end
24
-
25
- exec(:name => "git-update-#{name}", :cwd => "#{path}") do
17
+ exec({:name => "git-#{name}"}) do
18
+ command @parent.user ? "git clone #{@parent.user}@#{@parent.source} #{@parent.path}" : "git clone #{@parent.source} #{@parent.to ? @parent.to : ""}"
19
+ cwd "#{@parent.cwd if @parent.cwd}"
20
+ creates "#{::File.join( (@parent.cwd ? @parent.cwd : cwd), ::File.basename(@parent.source, ::File.extname(@parent.source)) )}/.git"
21
+
22
+ exec(:name => "update-#{name}") do
23
+ cwd ::File.dirname(@parent.creates)
26
24
  command "git pull"
27
- requires "Exec['git-#{@parent.name}']"
28
25
  end
29
-
26
+
30
27
  end
31
28
  end
32
29
 
30
+ # Since git is not a native type, we have to say which core resource
31
+ # it is using to be able to require it
32
+ def class_type_name
33
+ "exec"
34
+ end
35
+
36
+ # Because we are requiring an exec, instead of a built-in package of the git, we have to overload
37
+ # the to_s method and prepend it with the same name as above
38
+ def key
39
+ "git-#{name}"
40
+ end
41
+
33
42
  end
34
43
 
35
44
  end
@@ -17,8 +17,7 @@ module PoolParty
17
17
  :remote_storage_path => "/var/poolparty",
18
18
  :fileserver_base => "puppet:///files",
19
19
  :base_config_directory => "/etc/poolparty",
20
- :template_directory => "tmp/templates",
21
- :plugin_directory => "tmp/plugins",
20
+ :template_directory => "templates",
22
21
  :template_path => "/var/lib/puppet/templates",
23
22
  :module_path => "/etc/puppet/modules/poolparty",
24
23
  :default_specfile_name => "pool.spec",
@@ -47,7 +47,7 @@ module PoolParty
47
47
  # this can be overridden in the spec, but ec2 is the default
48
48
  self.using :ec2
49
49
  end
50
-
50
+
51
51
  # Keypairs
52
52
  # If the parent (pool) doesn't have a keypair defined on it, then generate one based on the
53
53
  # pool_name and the cloud_name
@@ -76,7 +76,6 @@ module PoolParty
76
76
  # clear_base_directory
77
77
  make_base_directory
78
78
  copy_misc_templates
79
- copy_puppet_functions
80
79
  Base.store_keys_in_file
81
80
  Script.save!
82
81
  copy_ssh_key # not my favorite...
@@ -108,13 +107,7 @@ module PoolParty
108
107
  copy_file_to_storage_directory(::File.join(::File.dirname(__FILE__), "..", "templates", f))
109
108
  end
110
109
  end
111
-
112
- # TODO: Fix for windowz
113
- def copy_puppet_functions
114
- cmd = "cp -R #{::File.join(::File.dirname(__FILE__), "..", "puppet_plugins/")} #{Base.storage_directory}/plugins"
115
- %x[#{cmd}]
116
- end
117
-
110
+
118
111
  # Configuration files
119
112
  def build_manifest
120
113
  @build_manifest ||= build_from_existing_file
@@ -168,6 +161,18 @@ module PoolParty
168
161
  ruby
169
162
  poolparty
170
163
  end
164
+
165
+ def provisioning?
166
+ @provisioning_in_progress == true
167
+ end
168
+
169
+ def provisioning_in_progress
170
+ @provisioning_in_progress = true
171
+ end
172
+
173
+ def provisioning_complete
174
+ @provisioning_in_progress = false
175
+ end
171
176
 
172
177
  # Add to the services pool for the manifest listing
173
178
  def add_service(serv)
@@ -22,11 +22,11 @@ module PoolParty
22
22
  class CallFunction < Resource
23
23
  def initialize(str="", opts={}, parent=self, &block)
24
24
  @str = str
25
- super(opts, parent, &block)
25
+ # super(opts, parent, &block)
26
26
  end
27
- def to_string(prev="")
27
+ def to_string(pre="")
28
28
  returning Array.new do |arr|
29
- arr << "#{prev}#{@str}"
29
+ arr << "#{pre}#{@str}"
30
30
  end.join("\n")
31
31
  end
32
32
  end
@@ -42,10 +42,10 @@ module PoolParty
42
42
  super(subclass)
43
43
  end
44
44
 
45
- def to_string(prev="")
45
+ def to_string(pre="")
46
46
  returning Array.new do |output|
47
- output << "#{prev} # Custom Functions\n"
48
- output << self.class.custom_functions_to_string(prev)
47
+ output << "#{pre} # Custom Functions\n"
48
+ output << self.class.custom_functions_to_string(pre)
49
49
  end.join("\n")
50
50
  end
51
51
  end
@@ -17,10 +17,10 @@ module PoolParty
17
17
  resources[type] ||= []
18
18
  end
19
19
 
20
- def add_resource(type, opts={}, parent=self, &block)
21
- resource = get_resource(type, opts[:name])
20
+ def add_resource(type, opts={}, parent=self, &block)
21
+ resource = get_resource(type, opts[:name], parent)
22
22
  if resource
23
- return resource
23
+ resource
24
24
  else
25
25
  returning "PoolParty::Resources::#{type.to_s.camelize}".classify.constantize.new(opts, parent, &block) do |o|
26
26
  resource(type) << o
@@ -28,8 +28,8 @@ module PoolParty
28
28
  end
29
29
  end
30
30
 
31
- def get_resource(type, name)
32
- resource(type).select {|resource| resource.name == name }.first
31
+ def get_resource(type, key, parent=self)
32
+ resource(type).select {|resource| resource.key == key }.first
33
33
  end
34
34
 
35
35
  #:nodoc:
@@ -37,11 +37,11 @@ module PoolParty
37
37
  @resources = nil
38
38
  end
39
39
 
40
- def resources_string(prev="")
41
- returning Array.new do |output|
42
- output << resources_string_from_resources(resources)
43
- end.join("\n")
44
- end
40
+ # def resources_string(pre="")
41
+ # returning Array.new do |output|
42
+ # output << resources_string_from_resources(resources)
43
+ # end.join("\n")
44
+ # end
45
45
 
46
46
  def custom_file(path, str)
47
47
  write_to_file_in_storage_directory(path, str)
@@ -61,11 +61,11 @@ module PoolParty
61
61
  lowercase_class_name = subclass.to_s.downcase
62
62
 
63
63
  # Add add resource method to the Resources module
64
- unless PoolParty::Resources.respond_to?(lowercase_class_name.to_sym)
64
+ unless PoolParty::Resources.respond_to?(lowercase_class_name.to_sym)
65
65
  method =<<-EOE
66
66
  def #{lowercase_class_name}(opts={}, parent=self, &blk)
67
67
  add_resource(:#{lowercase_class_name}, opts, parent, &blk)
68
- end
68
+ end
69
69
  EOE
70
70
  PoolParty::Resources.module_eval method
71
71
  PoolParty::Resources.add_has_and_does_not_have_methods_for(lowercase_class_name.to_sym)
@@ -90,70 +90,39 @@ module PoolParty
90
90
  # Finally, it uses the parent's options as the lowest priority
91
91
  def initialize(opts={}, parent=self, &block)
92
92
  # Take the options of the parents
93
- @parent = parent
93
+ set_resource_parent(parent)
94
94
  set_vars_from_options(opts) unless opts.empty?
95
95
  self.instance_eval &block if block
96
- loaded(opts)
96
+ loaded(opts, @parent)
97
+ end
98
+
99
+ def set_resource_parent(parent=nil)
100
+ if parent && parent != self
101
+ @parent = parent
102
+ requires parent.to_s if @parent.is_a?(PoolParty::Resources::Resource) && printable? && @parent.printable?
103
+ end
97
104
  end
98
105
 
106
+ # def requirement_tree
107
+ # p = @parent
108
+ # returning Array.new do |arr|
109
+ # arr << p.to_s
110
+ # while p && p != self && p.is_a?(PoolParty::Resources::Resource) && p.requires
111
+ # arr << p.requires
112
+ # p = p.parent
113
+ # end
114
+ # end.flatten.uniq
115
+ # end
116
+
99
117
  # Stub, so you can create virtual resources
100
- def loaded(opts={})
118
+ # This is called after the resource is initialized
119
+ # with the options given to it in the init-block
120
+ def loaded(opts={}, parent=self)
101
121
  end
102
122
 
103
123
  # DSL Overriders
104
- # Overrides for syntax
105
- # Allows us to send require to require a resource
106
- def require(str="")
107
- options[:require]
108
- end
109
- def requires(str="")
110
- options.merge!(:require => str)
111
- end
112
- def ensures(str="running")
113
- if %w(absent running).map {|a| self.send a.to_sym}.include?(str)
114
- str == "absent" ? is_absent : is_present
115
- else
116
- options.merge!(:ensure => str)
117
- end
118
- end
119
- # Allows us to send an ensure to ensure the presence of a resource
120
- def is_present(*args)
121
- options.merge!(:ensure => present)
122
- end
123
- # Ensures that what we are sending is absent
124
- def is_absent(*args)
125
- options.merge!(:ensure => absent)
126
- end
127
- # Alias for unless
128
- def ifnot(str="")
129
- options.merge!(:unless => str)
130
- end
131
- def present
132
- "present"
133
- end
134
- def absent
135
- "absent"
136
- end
137
- def cancel(*args)
138
- options[:cancelled] = args.empty? ? true : args[0]
139
- end
140
- def cancelled?
141
- options[:cancelled] || false
142
- end
124
+ include PoolParty::ResourcingDsl
143
125
 
144
- # Give us a template to work with on the resource
145
- # Make sure this template is moved to the tmp directory as well
146
- def template(file, opts={})
147
- raise TemplateNotFound.new("no template given") unless file
148
- raise TemplateNotFound.new("template cannot be found #{file}") unless ::File.file?(file)
149
- unless opts[:just_copy]
150
- options.merge!({:content => "template(\"#{::File.basename(file)}\")"})
151
- options.delete(:source) if options.has_key?(:source)
152
- copy_template_to_storage_directory(file)
153
- else
154
- copy_file_to_storage_directory(file)
155
- end
156
- end
157
126
  # This way we can subclass resources without worry
158
127
  def class_type_name
159
128
  self.class.to_s.top_level_class
@@ -172,11 +141,11 @@ module PoolParty
172
141
  self.class.custom_functions << str
173
142
  end
174
143
 
175
- def self.custom_functions_to_string(prev="")
144
+ def self.custom_functions_to_string(pre="")
176
145
  returning Array.new do |output|
177
146
  PoolParty::Resources.available_custom_resources.each do |resource|
178
147
  resource.custom_functions.each do |func|
179
- output << "#{prev*2}#{func}"
148
+ output << "#{pre*2}#{func}"
180
149
  end
181
150
  end
182
151
  end.join("\n")
@@ -191,51 +160,31 @@ module PoolParty
191
160
  def virtual_resource?
192
161
  false
193
162
  end
163
+ def printable?
164
+ true
165
+ end
194
166
  # We want to gather the options, but if the option sent is nil
195
167
  # then we want to override the option value by sending the key as
196
168
  # a method so that we can override this if necessary.
197
169
  # Only runs on objects that have options defined, otherwise
198
170
  # it returns an empty hash
199
171
  def get_modified_options
200
- if options
201
- opts = options.inject({}) do |sum,h|
202
- sum.merge!({h[0].to_sym => ((h[1].nil?) ? self.send(h[0].to_sym) : h[1]) })
203
- end
204
- else
205
- opts = {}
206
- end
207
- opts.reject {|k,v| disallowed_options.include?(k) }
208
- end
209
-
210
- # Generic to_s
211
- # Most Resources won't need to extend this
212
- def to_string(prev="")
213
- opts = get_modified_options
214
- returning Array.new do |output|
215
- unless cancelled?
216
- output << @prestring || ""
217
-
218
- if resources && !resources.empty?
219
- @cp = classpackage_with_self(self)
220
- output << @cp.to_string
221
- output << "include #{@cp.name.sanitize}"
222
- end
223
-
224
- unless virtual_resource?
225
- output << "#{prev}#{class_type_name} {"
226
- output << "#{prev}\"#{self.key}\":"
227
- output << opts.flush_out("#{prev*2}").join(",\n")
228
- output << "#{prev}}"
172
+ unless @modified_options
173
+ if options
174
+ opts = options.inject({}) do |sum,h|
175
+ sum.merge!({h[0].to_sym => ((h[1].nil?) ? self.send(h[0].to_sym) : h[1]) })
229
176
  end
230
-
231
- output << @poststring || ""
177
+ else
178
+ opts = {}
232
179
  end
233
- end.join("\n")
180
+ @modified_options = opts.reject {|k,v| disallowed_options.include?(k) }
181
+ end
182
+ @modified_options
234
183
  end
235
184
 
236
- def to_s
237
- "#{class_type_name.capitalize}['#{key}']"
238
- end
185
+ # For the time being, we'll make puppet the only available dependency resolution
186
+ # base, but in the future, we can rip this out and make it an option
187
+ include PoolParty::DependencyResolutions::Puppet
239
188
  end
240
189
 
241
190
  # Adds two methods to the module