auser-poolparty 1.2.4 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/VERSION.yml +1 -1
  2. data/bin/cloud +8 -1
  3. data/bin/cloud-contract +1 -1
  4. data/bin/cloud-provision +0 -1
  5. data/bin/server-cloud-elections +9 -9
  6. data/bin/server-list-active +10 -17
  7. data/bin/server-manage-election +4 -5
  8. data/examples/basic.rb +5 -4
  9. data/examples/fairchild.rb +1 -1
  10. data/lib/poolparty.rb +1 -1
  11. data/lib/poolparty/core/hash.rb +10 -2
  12. data/lib/poolparty/helpers/optioner.rb +5 -5
  13. data/lib/poolparty/lite.rb +5 -2
  14. data/lib/poolparty/modules/cloud_resourcer.rb +12 -5
  15. data/lib/poolparty/modules/pretty_printer.rb +1 -1
  16. data/lib/poolparty/monitors/monitor_rack.rb +2 -2
  17. data/lib/poolparty/monitors/monitors/{time_monitor.rb → clock_monitor.rb} +2 -2
  18. data/lib/poolparty/monitors/monitors/neighborhood_monitor.rb +8 -5
  19. data/lib/poolparty/monitors/monitors/stats_monitor.rb +45 -29
  20. data/lib/poolparty/net/remoter/connections.rb +0 -1
  21. data/lib/poolparty/net/remoter/interactive.rb +6 -6
  22. data/lib/poolparty/net/remoter_base.rb +10 -2
  23. data/lib/poolparty/net/remoter_bases/ec2/ec2.rb +14 -6
  24. data/lib/poolparty/net/remoter_bases/metavirt/metavirt.rb +1 -1
  25. data/lib/poolparty/plugins/apache2/apache.rb +16 -8
  26. data/lib/poolparty/poolparty/cloud.rb +22 -5
  27. data/lib/poolparty/poolparty/default.rb +21 -15
  28. data/lib/poolparty/poolparty/key.rb +1 -1
  29. data/lib/poolparty/poolparty/neighborhoods.rb +15 -4
  30. data/lib/poolparty/poolparty/pool.rb +1 -1
  31. data/lib/poolparty/poolparty/resource.rb +1 -0
  32. data/lib/poolparty/provision/boot_strapper.rb +10 -4
  33. data/lib/poolparty/provision/dr_configure.rb +9 -9
  34. data/lib/poolparty/schema.rb +5 -6
  35. data/lib/poolparty/templates/monitor.ru +1 -0
  36. data/spec/poolparty/core/ordered_hash_spec.rb +7 -7
  37. data/spec/poolparty/net/remote_instance_spec.rb +1 -1
  38. data/spec/poolparty/poolparty/cloud_spec.rb +18 -0
  39. data/spec/poolparty/poolparty/example_spec.rb +29 -9
  40. data/spec/poolparty/poolparty/key_spec.rb +1 -1
  41. data/spec/poolparty/poolparty/neighborhoods_spec.rb +1 -1
  42. data/tasks/poolparty.rake +2 -0
  43. data/vendor/gems/dslify/VERSION.yml +4 -0
  44. data/vendor/gems/dslify/dslify.gemspec +29 -0
  45. data/vendor/gems/dslify/lib/dslify.rb +1 -1
  46. data/vendor/gems/dslify/test/dslify_test.rb +82 -13
  47. data/vendor/gems/git-style-binaries/VERSION.yml +1 -1
  48. data/vendor/gems/git-style-binaries/doc/poolparty-binaries.screenplay +389 -20
  49. data/vendor/gems/git-style-binaries/git-style-binaries.gemspec +2 -2
  50. data/vendor/gems/git-style-binaries/lib/git-style-binary/helpers/name_resolver.rb +2 -2
  51. data/vendor/gems/git-style-binaries/lib/git-style-binary/parser.rb +2 -2
  52. metadata +5 -3
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 4
3
+ :patch: 7
4
4
  :major: 1
data/bin/cloud CHANGED
@@ -36,6 +36,13 @@ EOS
36
36
  end
37
37
 
38
38
  run do |command|
39
- puts "Primary Options: #{command.opts.inspect}"
39
+ subcommands = GitStyleBinary.list_subcommands
40
+
41
+ puts "Usage: cloud COMMAND [ARGS]
42
+
43
+ The cloud subcommands commands are:
44
+ #{subcommands}
45
+
46
+ See 'cloud help COMMAND' for more information on a specific command."
40
47
  end
41
48
  end
@@ -23,7 +23,7 @@ EOS
23
23
 
24
24
  if cld.minimum_instances < cld.nodes(:status => "running").size
25
25
  last_instance_id = cld.nodes(:status => "running").last[:instance_id]
26
- cld.remote_base.terminate_instance! cld.options.merge(:instance_id => last_instance_id)
26
+ cld.remote_base.terminate_instance! cld.dsl_options.merge(:instance_id => last_instance_id)
27
27
  else
28
28
  puts "The cloud #{cld.name} is running minimum instances (#{cld.nodes(:status => "running").size})"
29
29
  end
@@ -31,7 +31,6 @@ EOS
31
31
  cld.vputs "\nConfiguring: #{address[:ip]}\n--------------------"
32
32
  ::PoolParty::Provision::BootStrapper.new( address[:ip], :cloud => cld )
33
33
  ::PoolParty::Provision::DrConfigure.new( address[:ip], :cloud => cld )
34
-
35
34
  end
36
35
  end
37
36
  end
@@ -11,27 +11,27 @@ end
11
11
  vote_for = o.unflagged_args.shift || "none"
12
12
 
13
13
  schema = ::PoolParty.load_cloud_from_json(o.unflagged_args.shift) #TODO: smarter option parser
14
- remote_base_name = schema.options.remote_base.split('::')[-1].camelcase
15
- remoter_base = PoolParty::Remote.module_eval(remote_base_name)
14
+ remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
16
15
 
17
16
  o.loaded_clouds.each do |cld|
18
17
  cld.update_from_schema(schema)
19
-
20
18
  case vote_for
21
19
  when "expand"
22
- vputs "Launching new instance"
20
+ puts "Launching new instance"
21
+ `rm /etc/poolparty/neighborhood.json`
23
22
  cld.send :launch_instance!, schema.options.merge(:cloud_name => cld.name) do |node|
24
23
  dputs "Started node at #{node[:ip]}"
25
-
26
24
  ::PoolParty::Provision::BootStrapper.new( node[:ip], :cloud => cld )
27
25
  ::PoolParty::Provision::DrConfigure.new( node[:ip], :cloud => cld )
28
- end
29
-
26
+ end
27
+
30
28
  when "contract"
31
- last_instance_id = %x[/usr/bin/server-list-active instance_id].split("\t").last
32
- remoter_base.terminate_instance! schema.options.merge(:instance_id => last_instance_id)
29
+ `rm /etc/poolparty/neighborhood.json`
30
+ last_instance_id = %x[server-list-active instance_id].split("\t").last
31
+ remote_base.terminate_instance! schema.options.merge(:instance_id => last_instance_id)
33
32
  else
34
33
  puts "Unknown action: #{vote_for}"
34
+ remote_base.describe_instances
35
35
  end
36
36
 
37
37
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "poolparty/lite"
4
+ require "poolparty/core/array"
4
5
 
5
6
  list_type = ARGV.shift || "ip"
6
7
 
@@ -8,24 +9,16 @@ json_file = ARGV[0] || PoolParty::Default.properties_hash_file
8
9
  raise "ERROR: no json_file given" if !json_file
9
10
  schema = PoolParty::Schema.new( ::File.read(json_file) )
10
11
 
11
- inst_array = PoolParty::Neighborhoods.load_default.instances.instances
12
+ inst_array = PoolParty::Neighborhoods.load_default.instances
12
13
 
13
14
  if !inst_array || inst_array.empty?
14
- remoter_base = schema.options.remote_base
15
- remote_base = remoter_base.top_level_class.constantize(PoolParty::Remote)
16
-
15
+ remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
17
16
  instances = remote_base.send :describe_instances, schema.options
18
- inst_array = instances.map {|inst| inst.send list_type.to_sym }
19
- end
20
-
21
- print_array =
22
- case list_type
23
- when "ip"
24
- inst_array.compact.map {|i| i.ip }
25
- when "internal_ip"
26
- inst_array.compact.map {|i| i.internal_ip || i.ip }
17
+ inst_array = instances.map {|inst| inst.send list_type.to_sym }.compact
18
+ if ['ip', 'public_id', 'internal_ip'].include? list_type
19
+ inst_array.delete_if{|n| !n.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) }
20
+ end
21
+ print inst_array.compact.join("\t")
27
22
  else
28
- inst_array
29
- end
30
-
31
- print print_array.compact.join("\t")
23
+ print inst_array.map {|inst| inst.send list_type.to_sym }.compact.join("\t")
24
+ end
@@ -7,6 +7,7 @@
7
7
  # Error codes
8
8
  # 1 -> clouds.json was not loaded
9
9
  # 2 -> server-list-active didn't run
10
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
10
11
  require "rubygems"
11
12
  require 'net/http'
12
13
  require 'json'
@@ -19,20 +20,18 @@ def get_json_stats_from(ip, port)
19
20
  Net::HTTP.start(ip, port) {|http| http.get('/stats.json') }.body rescue "{}"
20
21
  end
21
22
 
22
- ips = %x[/usr/bin/server-list-active internal_ip].split("\t")
23
-
24
- exit(2) unless ips
23
+ ips = %x[server-list-active internal_ip].split("\t")
25
24
 
26
25
  minimum_instances = schema.options.minimum_instances
27
26
  maximum_instances = schema.options.maximum_instances
28
27
 
29
28
  if ips.size < minimum_instances
30
- %x[/usr/bin/server-cloud-elections expand]
31
29
  puts "Cloud is too small, need to expand"
30
+ %x[server-cloud-elections expand]
32
31
  exit(0)
33
32
  elsif ips.size > maximum_instances
34
- %x[/usr/bin/server-cloud-elections contract]
35
33
  puts "Cloud is too big, need to contract"
34
+ %x[n/server-cloud-elections contract]
36
35
  exit(0)
37
36
  end
38
37
 
@@ -1,19 +1,20 @@
1
1
  # Basic pool spec
2
2
  # Shows global settings for the clouds
3
3
  pool :application do
4
- instances 3..50
4
+ instances 1..5
5
5
 
6
6
  cloud :basic_app do
7
- minimum_instances 12
7
+ minimum_instances 3
8
+ keypair 'front'
8
9
  image_id "ami-abc123"
9
10
  has_file :name => "/etc/motd", :content => "Welcome to your PoolParty instance"
10
11
  end
11
12
 
12
13
  cloud :basic_db do
13
14
  using :vmrun do
14
- vmx_hash "file" => "192.168.248.122"
15
+ vmx_hash "/path/to/vmx_file" => "192.168.248.122"
15
16
  end
16
- minimum_instances 19
17
+ minimum_instances 1
17
18
  image_id "ami-1234bc"
18
19
  end
19
20
 
@@ -5,7 +5,7 @@ pool :application do
5
5
  ami 'ami-7cfd1a15'
6
6
 
7
7
  cloud :example_one do
8
-
8
+ keypair 'front'
9
9
  has_directory "/var/www"
10
10
 
11
11
  has_file "/etc/motd",
@@ -64,12 +64,12 @@ $_poolparty_load_directories = [
64
64
  "dependencies.rb",
65
65
  "modules/searchable_paths.rb",
66
66
  "modules/pinger.rb",
67
+ "modules",
67
68
  "poolparty/key.rb",
68
69
  "dependency_resolver/dependency_resolver_cloud_extensions.rb",
69
70
  "dependency_resolver/dependency_resolver.rb",
70
71
  "poolparty/poolparty_base_class.rb",
71
72
  "poolparty/default.rb",
72
- "modules",
73
73
  "exceptions",
74
74
  'poolparty/key.rb',
75
75
  "dependency_resolver",
@@ -112,13 +112,21 @@ class Hash
112
112
  self
113
113
  end
114
114
 
115
+ def to_cloud
116
+ $:.unshift("#{::File.dirname(__FILE__)}/../../poolparty")
117
+ require "poolparty"
118
+ cld = Cloud.new((fetch(:name) rescue "hashed_cloud"))
119
+ cld.set_vars_from_options(self)
120
+ cld
121
+ end
122
+
115
123
  def method_missing(sym, *args, &block)
116
- if has_key?(sym)
124
+ if has_key?(sym.to_sym)
117
125
  fetch(sym)
118
126
  elsif has_key?(sym.to_s)
119
127
  fetch(sym.to_s)
120
128
  else
121
129
  super
122
130
  end
123
- end
131
+ end
124
132
  end
@@ -114,17 +114,17 @@ module PoolParty
114
114
  output_options if verbose? && verbose
115
115
 
116
116
  if @load_pools
117
- @loaded_pool = load_pool( spec? ? spec : Binary.get_existing_spec_location)
117
+ @loaded_pool = load_pool( spec ? spec : Binary.get_existing_spec_location)
118
118
  @loaded_clouds = extract_cloud_from_options(self)
119
119
  @loaded_pools = extract_pool_from_options(self)
120
120
 
121
121
  reject_junk_options!
122
122
  raise CloudNotFoundException.new("Please specify your cloud with -s, move it to ./clouds.rb or in your POOL_SPEC environment variable") unless loaded_clouds && !loaded_clouds.empty?
123
123
  loaded_pools.each do |pl|
124
- pl.dsl_options.merge!(self.options)
124
+ pl.dsl_options.merge!(self.dsl_options)
125
125
  end
126
126
  loaded_clouds.each do |cl|
127
- cl.dsl_options.merge!(self.options)
127
+ cl.dsl_options.merge!(self.dsl_options)
128
128
  end
129
129
  end
130
130
  end
@@ -152,10 +152,10 @@ module PoolParty
152
152
  end
153
153
 
154
154
  def extract_cloud_from_options(o)
155
- o.cloudname? ? [cloud(o.cloudname.downcase.to_sym)] : clouds.collect {|n,cl| cl}
155
+ o.cloudname ? [cloud(o.cloudname.downcase.to_sym)] : clouds.collect {|n,cl| cl}
156
156
  end
157
157
 
158
158
  def extract_pool_from_options(o)
159
- o.poolname? ? [pool(o.poolname.downcase.to_sym)] : pools.collect {|n,pl| pl}
159
+ o.poolname ? [pool(o.poolname.downcase.to_sym)] : pools.collect {|n,pl| pl}
160
160
  end
161
161
  end
@@ -5,12 +5,15 @@ begin
5
5
  rescue Exception => e
6
6
  require "dslify"
7
7
  end
8
+ require "#{::File.dirname(__FILE__)}/core/string"
9
+ require "#{::File.dirname(__FILE__)}/core/hash"
10
+ require "#{::File.dirname(__FILE__)}/core/object"
8
11
  require "#{::File.dirname(__FILE__)}/poolparty/default"
9
12
  require "#{::File.dirname(__FILE__)}/modules/user_helpers"
13
+ require "#{::File.dirname(__FILE__)}/modules/cloud_resourcer"
14
+ require "#{::File.dirname(__FILE__)}/modules/pinger"
10
15
  require "#{::File.dirname(__FILE__)}/schema"
11
- require "#{::File.dirname(__FILE__)}/core/string"
12
16
  require "#{::File.dirname(__FILE__)}/net/init"
13
- require "#{::File.dirname(__FILE__)}/core/hash"
14
17
  require "#{::File.dirname(__FILE__)}/poolparty/neighborhoods"
15
18
  require "#{::File.dirname(__FILE__)}/exceptions/RemoteException.rb"
16
19
 
@@ -74,11 +74,18 @@ module PoolParty
74
74
  end
75
75
 
76
76
  def update_from_schema(schema)
77
- keypairs = schema.options.delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) }
78
- options.merge! schema.options
79
- dsl_options[:keypairs] = keypairs
80
-
81
- dsl_options[:dependency_resolver] = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
77
+ self.dsl_options.merge! schema.options.to_hash
78
+ self.dependency_resolver = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
79
+ keypair schema.options.keypair_name
80
+ remote_base_class = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
81
+ self.remote_base = remote_base_class.new schema.options.remote_base.to_hash
82
+
83
+ # self.keypair = PoolParty::Key.new schema.options.keypair.basename
84
+ # keypair = schema.options.delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) }
85
+ # options.merge! schema.options.to_hash
86
+ # dsl_options[:keypairs] = keypairs
87
+ #
88
+ # dsl_options[:dependency_resolver] = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
82
89
 
83
90
  end
84
91
 
@@ -26,7 +26,7 @@ module PoolParty
26
26
  def pretty_options(pre, o)
27
27
  return "" unless o.respond_to?(:options)
28
28
  print_options = (o.respond_to?(:parent) && o.parent && o.parent.respond_to?(:options)) ?
29
- (o.dsl_options.delete_if {|k,v| o.parent.dsl_options.has_key?(k) && o.parent.options[k] == o.options[k] && !o.options[k].nil? } ) :
29
+ (o.dsl_options.delete_if {|k,v| o.parent.dsl_options.has_key?(k) && o.parent.dsl_options[k] == o.dsl_options[k] && !o.dsl_options[k].nil? } ) :
30
30
  o.options
31
31
  print_options = print_options.map {|k,v| [k, o.send(k.to_sym).to_s] }.inject({}) { |r,e| r[e[0]] = e[1] unless o.class.default_options[e[0]] == e[1] || e[1].nil? || e[1].empty?; r }
32
32
  print_options.flush_out("#{pre}\t")
@@ -61,6 +61,7 @@ module Monitors
61
61
 
62
62
  private
63
63
  def instance
64
+ return nil if path_map.nil?
64
65
  @instance ||= constantize( path_map.first ).new(env)
65
66
  end
66
67
 
@@ -95,7 +96,7 @@ module Monitors
95
96
  when 1 # example: /stats
96
97
  instance.send(verb.to_sym, @data)
97
98
  when 2 # example: /stats/load
98
- instance.send("#{verb}_#{path[1]}".to_sym, @data)
99
+ instance.send("#{verb}_#{path[1]}".to_sym, @data) rescue instance.send("#{path[1]}".to_sym, @data)
99
100
  else # example: /stats/load/average/5/minutes
100
101
  instance.send("#{verb}_#{path[1]}".to_sym, env['rack.input'].read, *path[2..-1])
101
102
  end
@@ -119,5 +120,4 @@ module Monitors
119
120
 
120
121
  end
121
122
 
122
-
123
123
  end
@@ -1,8 +1,8 @@
1
1
  # An example monitor
2
- # access it at /monitor_time/ or /monitor_time/now
2
+ # access it at /monitor_clock/ or /monitor_clock/now
3
3
  module Monitors
4
4
 
5
- class Time < BaseMonitor
5
+ class Clock < BaseMonitor
6
6
  def get(data=nil)
7
7
  Time.now
8
8
  end
@@ -8,7 +8,8 @@ module Monitors
8
8
  class Neighborhood < BaseMonitor
9
9
 
10
10
  def get(data=nil)
11
- neighborhood
11
+ reset!
12
+ neighborhood
12
13
  end
13
14
 
14
15
  def put(data, from=nil)
@@ -66,12 +67,14 @@ module Monitors
66
67
  end
67
68
 
68
69
  # HELPERS
69
- def instances
70
- @instances ||= ::PoolParty::Neighborhoods.load_default.instances.to_hash[:instances]
70
+ def instances(_n=nil)
71
+ @instances ||= ::PoolParty::Neighborhoods.load_default.instances #.to_hash #[:instances]
71
72
  end
72
- def stats
73
+ def stats(_n=nil)
73
74
  @stats ||= ::PoolParty::Neighborhoods.load_default.stats rescue Stats.new(@env).get
74
75
  end
75
-
76
+ def reset!
77
+ @neighborhood = @stats = nil
78
+ end
76
79
  end
77
80
  end
@@ -16,26 +16,19 @@ module Monitors
16
16
 
17
17
  begin
18
18
  @cloud = JSON.parse( open('/etc/poolparty/clouds.json' ).read )
19
+ # @cloud = ::PoolParty::Cloud::Cloud.load_from_json(open('/etc/poolparty/clouds.json' ).read)
19
20
  rescue
20
- @cloud = ::PoolParty::Default.options.merge({"options" =>
21
+ @cloud = ::PoolParty::Default.dsl_options.merge({"options" =>
21
22
  {"rules" => {"expand" => PoolParty::Default.expand_when,
22
23
  "contract" => PoolParty::Default.contract_when
23
24
  }
24
25
  }
25
- })
26
+ })
26
27
  end
27
- # Our cloud.options.rules looks like
28
- # {"expand_when" => "load > 0.9", "contract_when" => "load < 0.4"}
29
- # We set these as rules on ourselves so we can use aska to parse the rules.
30
- # Later, we can call vote_rules on ourself and we'll get back Aska::Rule(s)
31
- # which we'll call valid_rule? for each Rule and return the result
32
- @cloud["options"]["rules"].each do |name, rul|
33
- r = Aska::Rule.new(rul)
34
- rule(name) << r
35
- end
36
- # log << "#{::Time.now.strftime("%Y-%m-%d-%H-%M")}, #{stats.to_json}\n"
28
+ make_aska_rules(@cloud["options"]["rules"])
29
+ log << "#{::Time.now.strftime("%Y-%m-%d-%H-%M")}, #{stats.to_json}\n"
37
30
  end
38
-
31
+
39
32
  def get(data=nil)
40
33
  begin
41
34
  if !request.params || request.params.empty?
@@ -43,10 +36,11 @@ module Monitors
43
36
  else
44
37
  stats[request.params[0].to_sym] ||= self.send(request.params[0])
45
38
  stats[request.params[0].to_sym]
39
+ log << "#{::Time.now.strftime("%Y-%m-%d-%H-%M")}, #{stats.to_json}\n"
46
40
  stats.to_json
47
41
  end
48
42
  rescue Exception => e
49
- "Error: #{e}"
43
+ "Error: #{e}".to_json
50
44
  end
51
45
  end
52
46
 
@@ -86,11 +80,12 @@ module Monitors
86
80
  # TODO: Move?
87
81
  # Expand the cloud if 50+% of the votes are for expansion
88
82
  # Contract the cloud if 51+% of the votes are for contraction
83
+ # Check to make sure an elected action is not already in progress
89
84
  if (candidates[:expand] - candidates[:contract])/stats.keys.size > 0.5
90
- %x[/usr/bin/server-cloud-elections expand] unless elected_action == "expand"
85
+ %x[server-cloud-elections expand] unless elected_action == "expand"
91
86
  @elected_action = "expand"
92
87
  elsif (candidates[:contract] - candidates[:expand])/stats.keys.size > 0.5
93
- %x[/usr/bin/server-cloud-elections contract] unless elected_action == "contract"
88
+ %x[server-cloud-elections contract] unless elected_action == "contract"
94
89
  @elected_action = "contract"
95
90
  end
96
91
 
@@ -100,12 +95,11 @@ module Monitors
100
95
  stats.to_json
101
96
  end
102
97
 
103
-
104
- def elected_action
98
+ def elected_action(_n=nil)
105
99
  @elected_action ||= nil
106
100
  end
107
101
 
108
- def rules
102
+ def rules(_n=nil)
109
103
  @rules ||= {}
110
104
  end
111
105
 
@@ -120,37 +114,38 @@ module Monitors
120
114
  stats
121
115
  end
122
116
 
123
- def stats
117
+ def stats(_n=nil)
124
118
  @stats ||= {my_ip => {}}
125
119
  end
126
120
 
127
- def load
121
+ def load(_n=nil)
128
122
  %x{"uptime"}.split[-3].to_f
129
123
  end
130
124
 
131
- def instances
125
+ def instances(_n=nil)
132
126
  # res = PoolParty::Neighborhoods.load_default.instances
133
- res ||= %x[/usr/bin/server-list-active internal_ip].split("\t")
127
+ res ||= %x[server-list-active internal_ip].split("\t")
134
128
  res
135
129
  end
136
130
 
137
- def can_expand?
131
+ def can_expand?(_n=nil)
138
132
  instances.size < max_instances
139
133
  end
140
134
 
141
- def can_contract?
135
+ def can_contract?(_n=nil)
142
136
  instances.size > min_instances
143
137
  end
144
138
 
145
- def min_instances
139
+ def min_instances(_n=nil)
146
140
  (@cloud["options"]["minimum_instances"] || PoolParty::Default.minimum_instances).to_i
147
141
  end
148
142
 
149
- def max_instances
143
+ def max_instances(_n=nil)
150
144
  (@cloud["options"]["maximum_instances"] || PoolParty::Default.maximum_instances).to_i
151
145
  end
152
146
 
153
- def nominations
147
+ def nominations(_n=nil)
148
+ # return ['expand'] if instances.size<min_instances
154
149
  load = stats[my_ip]["load"] ||= self.send(:load)
155
150
  stats[my_ip]["nominations"] ||= rules.collect do |k,cld_rules|
156
151
  t = cld_rules.collect do |r|
@@ -170,17 +165,38 @@ module Monitors
170
165
  end.flatten.compact
171
166
  end
172
167
 
168
+ #alias to allow access thru http route GET /stats/nominations
169
+ def get_nominations(_nodes=[])
170
+ nominations.to_json
171
+ end
172
+
173
+ def get_hello(_n=nil)
174
+ 'hi there'
175
+ end
176
+
173
177
  def my_ip
174
178
  @my_ip ||= ohai["ipaddress"]
175
179
  end
176
180
 
177
- def ohai
181
+ def ohai(_n=nil)
178
182
  @ohai ||= JSON.parse(%x[ohai])
179
183
  end
180
184
 
181
185
  def reload_data!
182
186
  @stats[my_ip] = {}
183
187
  instances.each {|inst| @stats[inst] = {} }
188
+ end
189
+
190
+ # Our cloud.dsl_options.rules looks like
191
+ # {"expand_when" => "load > 0.9", "contract_when" => "load < 0.4"}
192
+ # We set these as rules on ourselves so we can use aska to parse the rules.
193
+ # Later, we can call vote_rules on ourself and we'll get back Aska::Rule(s)
194
+ # which we'll call valid_rule? for each Rule and return the result
195
+ def make_aska_rules(rules)
196
+ rules.each do |name, rul|
197
+ r = Aska::Rule.new(rul)
198
+ rule(name) << r
199
+ end
184
200
  end
185
201
 
186
202
  end