broham 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/broham-register_as_next +134 -0
- data/bin/broham-yo_yo_yo +134 -0
- data/broham.gemspec +4 -2
- metadata +6 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'broham'
|
4
|
+
require 'broham/script'
|
5
|
+
|
6
|
+
[
|
7
|
+
# ['sup', '', '(alias for hosts)'],
|
8
|
+
# ['yo', '', '(alias for register)'],
|
9
|
+
# ['diss', '', '(alias for unregister)'],
|
10
|
+
# ['fuck_all_yall', '', '(alias for unregister_like)'],
|
11
|
+
# ['word', '', '(alias for get)'],
|
12
|
+
#
|
13
|
+
['hosts', 'role_pattern', 'Unregister all hosts prefixed by role_pattern'],
|
14
|
+
['register', 'role [--extra_param=val...]', 'Registers this machine for the given role; stuff in any leftover params'],
|
15
|
+
['unregister', 'role', 'Unregister that role'],
|
16
|
+
['unregister_like', 'role_pattern', 'Unregister all hosts prefixed by role_pattern'],
|
17
|
+
['get', 'role_pattern attr', 'show attr for all hosts prefixed by role_pattern']
|
18
|
+
].each{|cmd| Configliere::COMMANDS << cmd }
|
19
|
+
|
20
|
+
class BrohamScript
|
21
|
+
attr_accessor :role_name, :attr
|
22
|
+
def command() Settings.command ; end
|
23
|
+
def role_name() Settings[:role_name] ; end
|
24
|
+
def attr() Settings[:attr] ; end
|
25
|
+
|
26
|
+
def hosts_cmd
|
27
|
+
BrohamScript.get_commandline_predicates :role_name
|
28
|
+
$stderr.puts %Q{Listing hosts like #{role_name}}
|
29
|
+
dump_table Broham.hosts_like(role_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_cmd
|
33
|
+
# Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
|
34
|
+
broham_args = Settings[:set]||{}
|
35
|
+
BrohamScript.get_commandline_predicates :role_name
|
36
|
+
$stderr.puts %Q{Registering #{role_name} -- #{broham_args}}
|
37
|
+
new_bro = Broham.register(role_name)
|
38
|
+
dump_table [new_bro]
|
39
|
+
end
|
40
|
+
|
41
|
+
def register_as_next_cmd
|
42
|
+
# Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
|
43
|
+
broham_args = Settings[:set]||{}
|
44
|
+
BrohamScript.get_commandline_predicates :role_name
|
45
|
+
$stderr.puts %Q{Registering #{role_name} -- #{broham_args}}
|
46
|
+
new_bro = Broham.register_as_next(role_name)
|
47
|
+
dump_table [new_bro]
|
48
|
+
end
|
49
|
+
|
50
|
+
def unregister_cmd
|
51
|
+
BrohamScript.get_commandline_predicates :role_name
|
52
|
+
$stderr.puts %Q{Unregistering #{role_name}}
|
53
|
+
dead_bro = Broham.unregister(role_name)
|
54
|
+
dump_table [dead_bro]
|
55
|
+
end
|
56
|
+
|
57
|
+
def unregister_like_cmd
|
58
|
+
BrohamScript.get_commandline_predicates :role_name
|
59
|
+
$stderr.puts %Q{Unregistering all hosts like #{role_name}}
|
60
|
+
dump_table Broham.unregister_like role_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_cmd
|
64
|
+
BrohamScript.get_commandline_predicates :role_name, :attr
|
65
|
+
$stderr.puts %Q{Getting #{attr} for hosts like #{role_name}}
|
66
|
+
Broham.hosts_like(role_name).map do |bro|
|
67
|
+
$stdout.puts bro[attr]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def run
|
72
|
+
case Settings.command.to_s
|
73
|
+
when 'hosts', 'sup'
|
74
|
+
hosts_cmd
|
75
|
+
when 'register', 'yo'
|
76
|
+
register_cmd
|
77
|
+
when 'unregister', 'diss'
|
78
|
+
unregister_cmd
|
79
|
+
when 'unregister_like', 'fuck_all_yall'
|
80
|
+
unregister_like_cmd
|
81
|
+
when 'get', 'word'
|
82
|
+
get_cmd
|
83
|
+
when ''
|
84
|
+
Settings.die "Please use one of the commands listed above"
|
85
|
+
else
|
86
|
+
Settings.die "Don't know how to run command #{command}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
# Dump a list of hashes as a formatted, equally-spaced table
|
93
|
+
def dump_table hosts_list
|
94
|
+
attr_lens = {}
|
95
|
+
# find all used fields, and their width
|
96
|
+
hosts_list.each do |host|
|
97
|
+
host.to_hash.each{|k,v| attr_lens[k] = [v.to_s.length, attr_lens[k].to_i].max }
|
98
|
+
end
|
99
|
+
# account for length of attr titles
|
100
|
+
attr_lens.each{|attr,len| attr_lens[attr] = [len, attr.length].max }
|
101
|
+
# take attrs in order, putting role first (and excluding id)
|
102
|
+
attrs = ['role', (attr_lens.keys - ['role', 'id']).sort].flatten
|
103
|
+
$stderr.puts attrs.map{|attr| "%-#{attr_lens[attr]}s"%attr}.join("\t")
|
104
|
+
hosts_list.each do |host|
|
105
|
+
$stdout.puts attrs.map{|attr| "%-#{attr_lens[attr]}s"%host[attr]}.join("\t")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Loads defaults
|
110
|
+
def self.get_cluster_settings
|
111
|
+
Settings.read(ENV['HOME']+'/.poolparty/poolparty.yaml')
|
112
|
+
Settings.resolve!
|
113
|
+
Broham.establish_connection
|
114
|
+
end
|
115
|
+
|
116
|
+
# takes a list of attributes and pops each, in turn, from the commandline
|
117
|
+
# (the Settings.rest list)
|
118
|
+
def self.get_commandline_predicates *arg_names
|
119
|
+
arg_names.each do |arg_name|
|
120
|
+
Settings[arg_name] = Settings.rest.shift
|
121
|
+
end
|
122
|
+
check_args! *arg_names
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
def self.check_args! *arg_names
|
127
|
+
arg = arg_names.last
|
128
|
+
if Settings[arg].blank? then Settings.die "ERROR: Please supply #{arg_names.join(", ")} after the command." end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
BrohamScript.get_cluster_settings
|
134
|
+
BrohamScript.new.run
|
data/bin/broham-yo_yo_yo
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'broham'
|
4
|
+
require 'broham/script'
|
5
|
+
|
6
|
+
[
|
7
|
+
# ['sup', '', '(alias for hosts)'],
|
8
|
+
# ['yo', '', '(alias for register)'],
|
9
|
+
# ['diss', '', '(alias for unregister)'],
|
10
|
+
# ['fuck_all_yall', '', '(alias for unregister_like)'],
|
11
|
+
# ['word', '', '(alias for get)'],
|
12
|
+
#
|
13
|
+
['hosts', 'role_pattern', 'Unregister all hosts prefixed by role_pattern'],
|
14
|
+
['register', 'role [--extra_param=val...]', 'Registers this machine for the given role; stuff in any leftover params'],
|
15
|
+
['unregister', 'role', 'Unregister that role'],
|
16
|
+
['unregister_like', 'role_pattern', 'Unregister all hosts prefixed by role_pattern'],
|
17
|
+
['get', 'role_pattern attr', 'show attr for all hosts prefixed by role_pattern']
|
18
|
+
].each{|cmd| Configliere::COMMANDS << cmd }
|
19
|
+
|
20
|
+
class BrohamScript
|
21
|
+
attr_accessor :role_name, :attr
|
22
|
+
def command() Settings.command ; end
|
23
|
+
def role_name() Settings[:role_name] ; end
|
24
|
+
def attr() Settings[:attr] ; end
|
25
|
+
|
26
|
+
def hosts_cmd
|
27
|
+
BrohamScript.get_commandline_predicates :role_name
|
28
|
+
$stderr.puts %Q{Listing hosts like #{role_name}}
|
29
|
+
dump_table Broham.hosts_like(role_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_cmd
|
33
|
+
# Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
|
34
|
+
broham_args = Settings[:set]||{}
|
35
|
+
BrohamScript.get_commandline_predicates :role_name
|
36
|
+
$stderr.puts %Q{Registering #{role_name} -- #{broham_args}}
|
37
|
+
new_bro = Broham.register(role_name)
|
38
|
+
dump_table [new_bro]
|
39
|
+
end
|
40
|
+
|
41
|
+
def register_as_next_cmd
|
42
|
+
# Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
|
43
|
+
broham_args = Settings[:set]||{}
|
44
|
+
BrohamScript.get_commandline_predicates :role_name
|
45
|
+
$stderr.puts %Q{Registering #{role_name} -- #{broham_args}}
|
46
|
+
new_bro = Broham.register_as_next(role_name)
|
47
|
+
dump_table [new_bro]
|
48
|
+
end
|
49
|
+
|
50
|
+
def unregister_cmd
|
51
|
+
BrohamScript.get_commandline_predicates :role_name
|
52
|
+
$stderr.puts %Q{Unregistering #{role_name}}
|
53
|
+
dead_bro = Broham.unregister(role_name)
|
54
|
+
dump_table [dead_bro]
|
55
|
+
end
|
56
|
+
|
57
|
+
def unregister_like_cmd
|
58
|
+
BrohamScript.get_commandline_predicates :role_name
|
59
|
+
$stderr.puts %Q{Unregistering all hosts like #{role_name}}
|
60
|
+
dump_table Broham.unregister_like role_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_cmd
|
64
|
+
BrohamScript.get_commandline_predicates :role_name, :attr
|
65
|
+
$stderr.puts %Q{Getting #{attr} for hosts like #{role_name}}
|
66
|
+
Broham.hosts_like(role_name).map do |bro|
|
67
|
+
$stdout.puts bro[attr]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def run
|
72
|
+
case Settings.command.to_s
|
73
|
+
when 'hosts', 'sup'
|
74
|
+
hosts_cmd
|
75
|
+
when 'register', 'yo'
|
76
|
+
register_cmd
|
77
|
+
when 'unregister', 'diss'
|
78
|
+
unregister_cmd
|
79
|
+
when 'unregister_like', 'fuck_all_yall'
|
80
|
+
unregister_like_cmd
|
81
|
+
when 'get', 'word'
|
82
|
+
get_cmd
|
83
|
+
when ''
|
84
|
+
Settings.die "Please use one of the commands listed above"
|
85
|
+
else
|
86
|
+
Settings.die "Don't know how to run command #{command}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
# Dump a list of hashes as a formatted, equally-spaced table
|
93
|
+
def dump_table hosts_list
|
94
|
+
attr_lens = {}
|
95
|
+
# find all used fields, and their width
|
96
|
+
hosts_list.each do |host|
|
97
|
+
host.to_hash.each{|k,v| attr_lens[k] = [v.to_s.length, attr_lens[k].to_i].max }
|
98
|
+
end
|
99
|
+
# account for length of attr titles
|
100
|
+
attr_lens.each{|attr,len| attr_lens[attr] = [len, attr.length].max }
|
101
|
+
# take attrs in order, putting role first (and excluding id)
|
102
|
+
attrs = ['role', (attr_lens.keys - ['role', 'id']).sort].flatten
|
103
|
+
$stderr.puts attrs.map{|attr| "%-#{attr_lens[attr]}s"%attr}.join("\t")
|
104
|
+
hosts_list.each do |host|
|
105
|
+
$stdout.puts attrs.map{|attr| "%-#{attr_lens[attr]}s"%host[attr]}.join("\t")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Loads defaults
|
110
|
+
def self.get_cluster_settings
|
111
|
+
Settings.read(ENV['HOME']+'/.poolparty/poolparty.yaml')
|
112
|
+
Settings.resolve!
|
113
|
+
Broham.establish_connection
|
114
|
+
end
|
115
|
+
|
116
|
+
# takes a list of attributes and pops each, in turn, from the commandline
|
117
|
+
# (the Settings.rest list)
|
118
|
+
def self.get_commandline_predicates *arg_names
|
119
|
+
arg_names.each do |arg_name|
|
120
|
+
Settings[arg_name] = Settings.rest.shift
|
121
|
+
end
|
122
|
+
check_args! *arg_names
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
def self.check_args! *arg_names
|
127
|
+
arg = arg_names.last
|
128
|
+
if Settings[arg].blank? then Settings.die "ERROR: Please supply #{arg_names.join(", ")} after the command." end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
BrohamScript.get_cluster_settings
|
134
|
+
BrohamScript.new.run
|
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.
|
8
|
+
s.version = "0.0.12"
|
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
12
|
s.date = %q{2010-05-04}
|
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", "broham-diss", "broham-fuck_all_yall", "broham-get", "broham-hosts", "broham-register", "broham-sup", "broham-unregister", "broham-unregister_like", "broham-word", "broham-yo"]
|
15
|
+
s.executables = ["broham", "broham-diss", "broham-fuck_all_yall", "broham-get", "broham-hosts", "broham-register", "broham-register_as_next", "broham-sup", "broham-unregister", "broham-unregister_like", "broham-word", "broham-yo", "broham-yo_yo_yo"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
18
|
"README.textile"
|
@@ -30,11 +30,13 @@ Gem::Specification.new do |s|
|
|
30
30
|
"bin/broham-get",
|
31
31
|
"bin/broham-hosts",
|
32
32
|
"bin/broham-register",
|
33
|
+
"bin/broham-register_as_next",
|
33
34
|
"bin/broham-sup",
|
34
35
|
"bin/broham-unregister",
|
35
36
|
"bin/broham-unregister_like",
|
36
37
|
"bin/broham-word",
|
37
38
|
"bin/broham-yo",
|
39
|
+
"bin/broham-yo_yo_yo",
|
38
40
|
"broham.gemspec",
|
39
41
|
"lib/broham.rb",
|
40
42
|
"lib/broham/script.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 12
|
9
|
+
version: 0.0.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Philip (flip) Kromer
|
@@ -52,11 +52,13 @@ executables:
|
|
52
52
|
- broham-get
|
53
53
|
- broham-hosts
|
54
54
|
- broham-register
|
55
|
+
- broham-register_as_next
|
55
56
|
- broham-sup
|
56
57
|
- broham-unregister
|
57
58
|
- broham-unregister_like
|
58
59
|
- broham-word
|
59
60
|
- broham-yo
|
61
|
+
- broham-yo_yo_yo
|
60
62
|
extensions: []
|
61
63
|
|
62
64
|
extra_rdoc_files:
|
@@ -75,11 +77,13 @@ files:
|
|
75
77
|
- bin/broham-get
|
76
78
|
- bin/broham-hosts
|
77
79
|
- bin/broham-register
|
80
|
+
- bin/broham-register_as_next
|
78
81
|
- bin/broham-sup
|
79
82
|
- bin/broham-unregister
|
80
83
|
- bin/broham-unregister_like
|
81
84
|
- bin/broham-word
|
82
85
|
- bin/broham-yo
|
86
|
+
- bin/broham-yo_yo_yo
|
83
87
|
- broham.gemspec
|
84
88
|
- lib/broham.rb
|
85
89
|
- lib/broham/script.rb
|