Class: DRbQS::ProcessDefinition::Register
- Inherits:
-
Object
- Object
- DRbQS::ProcessDefinition::Register
- Defined in:
- lib/drbqs/execute/register.rb
Instance Attribute Summary collapse
-
#__default__ ⇒ Array
readonly
A hash of key and value.
-
#__node__ ⇒ Array
readonly
Keys of the hash are :type, :template, :ssh, :setting, and :args.
-
#__server__ ⇒ Array
readonly
Keys of the hash are :type, :template, :ssh, :setting, and :args.
-
#__usage__ ⇒ Array
readonly
A hash of key and value.
Instance Method Summary collapse
- #__load__(path) ⇒ Object
- #clear_node(*args) ⇒ Object
- #clear_server(*args) ⇒ Object
-
#default(val = {}) ⇒ Object
We can set default server, default port, and default directory to output log.
- #default_clear(*keys) ⇒ Object
-
#initialize ⇒ Register
constructor
A new instance of Register.
-
#node(name, opts = {}, &block) ⇒ Object
To set properties of nodes we can use the similar options to the command 'drbqs-node'.
-
#server(name, *args, &block) ⇒ Object
To set properties of server we can use the similar options to the command 'drbqs-server'.
-
#usage(opts = {}) ⇒ Object
We can set some messages shown by drbqs-execute -h.
Constructor Details
#initialize ⇒ Register
Returns a new instance of Register.
11 12 13 14 15 16 |
# File 'lib/drbqs/execute/register.rb', line 11 def initialize @__server__ = [] @__node__ = [] @__default__ = {} @__usage__ = {} end |
Instance Attribute Details
#__default__ ⇒ Array (readonly)
Returns a hash of key and value.
9 10 11 |
# File 'lib/drbqs/execute/register.rb', line 9 def __default__ @__default__ end |
#__node__ ⇒ Array (readonly)
Keys of the hash are :type, :template, :ssh, :setting, and :args.
6 7 8 |
# File 'lib/drbqs/execute/register.rb', line 6 def __node__ @__node__ end |
#__server__ ⇒ Array (readonly)
Keys of the hash are :type, :template, :ssh, :setting, and :args.
6 7 8 |
# File 'lib/drbqs/execute/register.rb', line 6 def __server__ @__server__ end |
#__usage__ ⇒ Array (readonly)
Returns a hash of key and value.
9 10 11 |
# File 'lib/drbqs/execute/register.rb', line 9 def __usage__ @__usage__ end |
Instance Method Details
#__load__(path) ⇒ Object
304 305 306 |
# File 'lib/drbqs/execute/register.rb', line 304 def __load__(path) instance_eval(File.read(path), path) end |
#clear_node(*args) ⇒ Object
255 256 257 258 259 260 261 |
# File 'lib/drbqs/execute/register.rb', line 255 def clear_node(*args) args.each do |arg| @__node__.delete_if do |name, data| name == arg.intern end end end |
#clear_server(*args) ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/drbqs/execute/register.rb', line 244 def clear_server(*args) args.each do |arg| @__server__.delete_if do |name, data| name == arg.intern end end end |
#default(val = {}) ⇒ Object
We can set default server, default port, and default directory to output log.
271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/drbqs/execute/register.rb', line 271 def default(val = {}) val.assert_valid_keys(:port, :server, :node, :log) val.delete_if { |key, v| !v } if val[:server] val[:server] = val[:server].intern end if val[:port] val[:port] = val[:port].to_i end raise "Invalid default value for :node." if val.has_key?(:node) && !(Array === val[:node]) raise "Invalid default value for :log." if val.has_key?(:log) && !(String === val[:log]) @__default__.merge!(val) end |
#default_clear(*keys) ⇒ Object
287 288 289 290 291 |
# File 'lib/drbqs/execute/register.rb', line 287 def default_clear(*keys) keys.each do |key| @__default__.delete(key) end end |
#node(name, opts = {}, &block) ⇒ Object
To set properties of nodes we can use the similar options to the command 'drbqs-node'. When we execute a server over ssh, we can use the similar options to the command 'drbqs-ssh' Exceptionally, we can set a ssh server by 'connect' method. If we omit the 'connect' method then the program tries to connect the name specified as first argument.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/drbqs/execute/register.rb', line 209 def node(name, opts = {}, &block) opts.assert_valid_keys(:template, :load, :group) name = name.intern load_def = opts[:load] if ind = @__node__.index { |n, data| name == n } old_data = @__node__.delete_at(ind) if (opts[:group] && old_data[1][:type] != :group) || (!opts[:group] && old_data[1][:type] == :group) raise ArgumentError, "Change type of definition on reconfiguring." elsif (!opts[:group] && load_def) raise ArgumentError, "Can not set both reconfiguring and loading." end load_def = old_data[1][:setting] else old_data = nil end if opts[:group] unless Array === opts[:group] raise ":group must be an array of node names." end data = { :type => :group, :template => true, :ssh => nil, :setting => nil, :args => opts[:group].map(&:intern) } @__node__ << [name, data] elsif block_given? __register_node__(opts[:template], name, load_def, &block) else raise ArgumentError, "Block to define settings is not given." end end |
#server(name, hostname, opts = {}) ⇒ Object #server(name, opts = {}) ⇒ Object
To set properties of server we can use the similar options to the command 'drbqs-server'. When we execute a server over ssh, we can use the similar options to the command 'drbqs-ssh' Exceptionally, we can set files to load by 'load' method and set a ssh server by 'connect' method. If we omit the 'connect' method then the program tries to connect the name specified as first argument.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/drbqs/execute/register.rb', line 144 def server(name, *args, &block) unless block_given? raise ArgumentError, "Block to define settings is not given." end name = name.intern if ind = @__server__.index { |n, data| name == n } old_data = @__server__.delete_at(ind) else old_data = nil end opts = args. opts.assert_valid_keys(:template, :load) if args.size > 1 raise ArgumentError, "Invalid number of arguments." end hostname = args[0] if old_data if opts[:load] raise ArgumentError, "Can not set both reconfiguring and loading." end load_def = old_data[1][:setting] hostname = old_data[1][:args][0] if !hostname else load_def = opts[:load] end __register_server__(opts[:template], name, load_def, hostname, &block) end |
#usage(opts = {}) ⇒ Object
We can set some messages shown by drbqs-execute -h.
299 300 301 302 |
# File 'lib/drbqs/execute/register.rb', line 299 def usage(opts = {}) opts.assert_valid_keys(:message, :server) @__usage__.merge!(opts) end |