broham 0.0.5 → 0.0.6

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.
data/README.textile CHANGED
@@ -66,6 +66,18 @@ h4. Commandline Interface
66
66
  {"timestamp":["20100405093238"],"fqdn":["nfs.infochimps.org"],"client_path":["/home"],"server_path":["/home"],"role":["nfs_server"],"private_ip":["10.123.156.231"],"default_ip":["10.123.156.231"],"public_ip":["104.136.251.50"]}
67
67
  </code></pre>
68
68
 
69
+ h4. IRB Usage
70
+
71
+ <pre><code>
72
+ require 'configliere'
73
+ Settings.read('broham.yaml')
74
+ require 'broham'
75
+ require 'broham/script'
76
+ Broham.establish_connection
77
+
78
+ Broham.unregister_like 'gibbon-slave'
79
+ </code></pre>
80
+
69
81
  h4. Setup
70
82
 
71
83
  For setup, we recommend configliere
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/bin/broham-diss CHANGED
@@ -3,11 +3,10 @@ require 'rubygems'
3
3
  require 'broham'
4
4
  require 'broham/script'
5
5
 
6
-
7
6
  Broham.get_cluster_settings
8
7
  role_name = Settings[:role_name]
9
8
 
10
- $stderr.puts %Q{Removing all #{role_name}}
11
- resps = Broham.unregister_all role_name
9
+ $stderr.puts %Q{Removing #{role_name}}
10
+ resps = Broham.unregister role_name
12
11
  $stderr.puts resps.map{|resp| resp.to_pretty_json }
13
12
 
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'broham'
4
+ require 'broham/script'
5
+
6
+
7
+ Broham.get_cluster_settings
8
+ role_name = Settings[:role_name]
9
+
10
+ $stderr.puts %Q{Removing all like #{role_name}}
11
+ resps = Broham.unregister_like role_name
12
+ $stderr.puts resps.map{|resp| resp.to_pretty_json }
13
+
@@ -3,11 +3,10 @@ require 'rubygems'
3
3
  require 'broham'
4
4
  require 'broham/script'
5
5
 
6
-
7
6
  Broham.get_cluster_settings
8
7
  role_name = Settings[:role_name]
9
8
 
10
- $stderr.puts %Q{Removing all #{role_name}}
11
- resps = Broham.unregister_all role_name
9
+ $stderr.puts %Q{Removing #{role_name}}
10
+ resps = Broham.unregister role_name
12
11
  $stderr.puts resps.map{|resp| resp.to_pretty_json }
13
12
 
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'broham'
4
+ require 'broham/script'
5
+
6
+
7
+ Broham.get_cluster_settings
8
+ role_name = Settings[:role_name]
9
+
10
+ $stderr.puts %Q{Removing all like #{role_name}}
11
+ resps = Broham.unregister_like role_name
12
+ $stderr.puts resps.map{|resp| resp.to_pretty_json }
13
+
data/broham.gemspec CHANGED
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{broham}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philip (flip) Kromer"]
12
- s.date = %q{2010-04-05}
12
+ s.date = %q{2010-04-08}
13
13
  s.description = %q{Bro! Broham always knows where his bros are, bro. Using broham, a newly-created cloud machine can annouce its availability for a certain role ("nfs_server" or "db_slave-2"), allowing any other interested nodes to discover its public_ip, private_ip, etc. See also: http://j.mp/amongbros}
14
14
  s.email = %q{flip@infochimps.org}
15
- s.executables = ["broham-diss", "broham-host", "broham-register", "broham-register_as_next", "broham-sup", "broham-unregister-all", "broham-yo"]
15
+ s.executables = ["broham-diss", "broham-fuck_all_yall", "broham-host", "broham-register", "broham-register_as_next", "broham-sup", "broham-unregister", "broham-unregister-like", "broham-yo"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
18
  "README.textile"
@@ -25,11 +25,13 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "bin/broham-diss",
28
+ "bin/broham-fuck_all_yall",
28
29
  "bin/broham-host",
29
30
  "bin/broham-register",
30
31
  "bin/broham-register_as_next",
31
32
  "bin/broham-sup",
32
- "bin/broham-unregister-all",
33
+ "bin/broham-unregister",
34
+ "bin/broham-unregister-like",
33
35
  "bin/broham-yo",
34
36
  "broham.gemspec",
35
37
  "lib/broham.rb",
data/lib/broham.rb CHANGED
@@ -28,9 +28,14 @@ class Broham < RightAws::ActiveSdb::Base
28
28
  select_by_role(role, :order => 'timestamp DESC')
29
29
  end
30
30
 
31
+ # # Returns all hosts in the given role
32
+ # def self.hosts role
33
+ # select_all_by_role(role, :order => 'timestamp DESC')
34
+ # end
35
+
31
36
  # Returns all hosts in the given role
32
- def self.hosts role
33
- select_all_by_role(role, :order => 'timestamp DESC')
37
+ def self.hosts_like role
38
+ select(:all, :order => 'timestamp DESC').select{|bro| bro[:role].to_s =~ /^#{role}/ }
34
39
  end
35
40
 
36
41
  def self.host_attrs(role)
@@ -45,6 +50,15 @@ class Broham < RightAws::ActiveSdb::Base
45
50
  success ? self.new(success) : false
46
51
  end
47
52
 
53
+ def self.roles ip=nil
54
+ ip ||= my_default_ip
55
+ select_all_by_default_ip(ip).map{|entry| entry['role'] }
56
+ end
57
+ def self.entry_for_role role, ip=nil
58
+ ip ||= my_default_ip
59
+ select_by_role_and_default_ip(role, ip)
60
+ end
61
+
48
62
  #
49
63
  # Enlists as the next among many machines filling the given role.
50
64
  #
@@ -56,16 +70,31 @@ class Broham < RightAws::ActiveSdb::Base
56
70
  #
57
71
  def self.register_as_next role, attrs={}
58
72
  my_idx = 0
73
+ if (registered_entry = entry_for_role(role)) then return registered_entry end
59
74
  100.times do
60
75
  ahost = host(role) || new
61
- current_max_idx = ahost[:idx] && ahost[:idx].first
62
- my_idx = (current_max_idx.to_i + 1)
76
+ current_max_idx = ahost[:idx] && ahost[:idx].first
77
+ my_idx = current_max_idx ? current_max_idx.to_i + 1 : 0
63
78
  ahost.attributes = host_attrs(role).merge({ :idx => my_idx.to_s }.merge(attrs))
64
- expected = current_max_idx ? {:idx => (current_max_idx.to_i + rand(5)).to_s} : {}
65
- success = ahost.save_if(expected)
66
- break if success
79
+ expected = current_max_idx ? {:idx => (current_max_idx.to_i).to_s} : {}
80
+ registered_entry = ahost.save_if(expected)
81
+ break if registered_entry
67
82
  end
68
83
  register role+'-'+my_idx.to_s, { :idx => my_idx }.merge(attrs)
84
+ new registered_entry
85
+ end
86
+
87
+ #
88
+ # Removes all registrations for the given role wildcard
89
+ #
90
+ def self.unregister_like role
91
+ hosts_like(role).each(&:unregister)
92
+ end
93
+ def self.unregister role
94
+ host(role).each(&:unregister)
95
+ end
96
+ def unregister
97
+ delete
69
98
  end
70
99
 
71
100
  # alternative syntax for #register
@@ -74,15 +103,12 @@ class Broham < RightAws::ActiveSdb::Base
74
103
  def self.yo_yo_yo!(*args) register_as_next *args ; end
75
104
  # alternative syntax for #host
76
105
  def self.sup?(*args) host *args ; end
77
- # alternative syntax for #hosts
78
- def self.sup_bros?(*args) hosts *args ; end
79
-
80
- #
81
- # Removes all registrations for the given role
82
- #
83
- def self.unregister_all role
84
- select_all_by_role(role).each(&:delete)
85
- end
106
+ # alternative syntax for #hosts_like
107
+ def self.sup_yall?(*args) hosts_like *args ; end
108
+ # alternative syntax for #unregister
109
+ def self.diss(*args) unregister *args ; end
110
+ # alternative syntax for #unregister_like
111
+ def self.fuck_all_yall(*arg) unregister_like *args ; end
86
112
 
87
113
  #
88
114
  # Registration attributes
@@ -134,13 +160,4 @@ class Broham < RightAws::ActiveSdb::Base
134
160
 
135
161
  end
136
162
 
137
-
138
- # #
139
- # # Metaprogramming
140
- # #
141
- # def self.new cluster
142
- # cluster_klass = '::'+Extlib::Inflection.classify(cluster.to_s)
143
- # module_eval(%Q{ class #{cluster_klass} < Broham::Cluster ; end })
144
- # cluster_klass.constantize rescue nil
145
- # end
146
-
163
+ Broham.establish_connection
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Philip (flip) Kromer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 -05:00
17
+ date: 2010-04-08 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,11 +47,13 @@ description: "Bro! Broham always knows where his bros are, bro. Using broham, a
47
47
  email: flip@infochimps.org
48
48
  executables:
49
49
  - broham-diss
50
+ - broham-fuck_all_yall
50
51
  - broham-host
51
52
  - broham-register
52
53
  - broham-register_as_next
53
54
  - broham-sup
54
- - broham-unregister-all
55
+ - broham-unregister
56
+ - broham-unregister-like
55
57
  - broham-yo
56
58
  extensions: []
57
59
 
@@ -66,11 +68,13 @@ files:
66
68
  - Rakefile
67
69
  - VERSION
68
70
  - bin/broham-diss
71
+ - bin/broham-fuck_all_yall
69
72
  - bin/broham-host
70
73
  - bin/broham-register
71
74
  - bin/broham-register_as_next
72
75
  - bin/broham-sup
73
- - bin/broham-unregister-all
76
+ - bin/broham-unregister
77
+ - bin/broham-unregister-like
74
78
  - bin/broham-yo
75
79
  - broham.gemspec
76
80
  - lib/broham.rb