broham 0.0.9 → 0.0.10
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 +7 -0
- data/VERSION +1 -1
- data/bin/broham +125 -6
- data/bin/broham-diss +127 -6
- data/bin/broham-fuck_all_yall +127 -6
- data/bin/broham-get +134 -0
- data/bin/broham-hosts +134 -0
- data/bin/broham-register +128 -8
- data/bin/broham-sup +128 -7
- data/bin/broham-unregister +127 -6
- data/bin/broham-unregister_like +134 -0
- data/bin/broham-word +134 -0
- data/bin/broham-yo +128 -8
- data/broham.gemspec +10 -8
- data/lib/broham.rb +5 -9
- data/lib/broham/script.rb +1 -20
- data/lib/broham/sdb.rb +3 -0
- data/lib/broham/sdb/active_sdb.rb +55 -0
- data/lib/broham/sdb/right_sdb_interface.rb +141 -0
- metadata +14 -13
- data/bin/broham-host +0 -13
- data/bin/broham-hosts_like +0 -12
- data/bin/broham-register_as_next +0 -13
- data/bin/broham-sup_yall +0 -12
- data/bin/broham-unregister-like +0 -13
data/bin/broham-hosts
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/bin/broham-register
CHANGED
@@ -2,13 +2,133 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'broham'
|
4
4
|
require 'broham/script'
|
5
|
-
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
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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 }
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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-sup
CHANGED
@@ -2,12 +2,133 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'broham'
|
4
4
|
require 'broham/script'
|
5
|
-
require 'json'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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 }
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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-unregister
CHANGED
@@ -3,11 +3,132 @@ require 'rubygems'
|
|
3
3
|
require 'broham'
|
4
4
|
require 'broham/script'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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 }
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
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
|