module Nucleon::Facade
Public Instance Methods
action(provider, options)
click to toggle source
# File lib/core/facade.rb 355 def action(provider, options) 356 plugin(:nucleon, :action, provider, options) 357 end
action_cli(provider, args = [], quiet = false, name = :nucleon, display_errors = true, state = nil)
click to toggle source
# File lib/core/facade.rb 375 def action_cli(provider, args = [], quiet = false, name = :nucleon, display_errors = true, state = nil) 376 Plugin::Action.exec_cli(provider, args, quiet, name, display_errors, state) 377 end
action_config(provider)
click to toggle source
# File lib/core/facade.rb 363 def action_config(provider) 364 action = action(provider, { :settings => {}, :quiet => true }) 365 return {} unless action 366 367 action.configure 368 action.config 369 end
action_help(action = nil, extended_help = false)
click to toggle source
# File lib/core/facade.rb 392 def action_help(action = nil, extended_help = false) 393 Plugin::Action.action_help(action, extended_help) 394 end
action_run(provider, options = {}, quiet = true, display_errors = true, state = nil)
click to toggle source
# File lib/core/facade.rb 371 def action_run(provider, options = {}, quiet = true, display_errors = true, state = nil) 372 Plugin::Action.exec(provider, options, quiet, display_errors, state) 373 end
actions(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 359 def actions(data, build_hash = false, keep_array = false) 360 plugins(:nucleon, :action, data, build_hash, keep_array) 361 end
active_plugins(namespace = nil, plugin_type = nil, provider = nil)
click to toggle source
# File lib/core/facade.rb 298 def active_plugins(namespace = nil, plugin_type = nil, provider = nil) 299 Manager.connection.active_plugins(namespace, plugin_type, provider) 300 end
admin?()
click to toggle source
# File lib/core/facade.rb 172 def admin? 173 is_admin = ( ENV['USER'] == 'root' ) 174 unless is_admin 175 ext_admin = exec(:check_admin) do |op, results| 176 if op == :reduce 177 results.values.include?(true) 178 else 179 results ? true : false 180 end 181 end 182 end 183 is_admin || ext_admin ? true : false 184 end
check(method, options = {})
click to toggle source
# File lib/core/facade.rb 462 def check(method, options = {}) 463 Manager.connection.check(method, options) 464 end
class_const(name, separator = '::')
click to toggle source
# File lib/core/facade.rb 601 def class_const(name, separator = '::') 602 Manager.connection.class_const(name, separator) 603 end
class_name(name, separator = '::', want_array = false)
click to toggle source
# File lib/core/facade.rb 595 def class_name(name, separator = '::', want_array = false) 596 Manager.connection.class_name(name, separator, want_array) 597 end
cli_run(command, options = {}, &code)
click to toggle source
# File lib/core/facade.rb 499 def cli_run(command, options = {}, &code) 500 command = command.join(' ') if command.is_a?(Array) 501 config = Config.ensure(options) 502 503 logger.info("Executing command #{command}") 504 505 result = Util::Shell.connection.exec(command, config, &code) 506 507 unless config.get(:quiet, false) || result.status == Nucleon.code.success 508 ui.error("Command #{command} failed to execute") 509 end 510 result 511 end
code()
click to toggle source
# File lib/core/facade.rb 230 def code 231 Codes.new 232 end
codes(*codes)
click to toggle source
# File lib/core/facade.rb 234 def codes(*codes) 235 Codes.codes(*codes) 236 end
collect(method, options = {})
click to toggle source
# File lib/core/facade.rb 474 def collect(method, options = {}) 475 Manager.connection.collect(method, options) 476 end
command(options, provider = nil)
click to toggle source
# File lib/core/facade.rb 409 def command(options, provider = nil) 410 plugin(:nucleon, :command, provider, options) 411 end
commands(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 413 def commands(data, build_hash = false, keep_array = false) 414 plugins(:nucleon, :command, data, build_hash, keep_array) 415 end
config(type, options = {})
click to toggle source
# File lib/core/facade.rb 456 def config(type, options = {}) 457 Manager.connection.config(type, options) 458 end
create_plugin(namespace, plugin_type, provider, options = {})
click to toggle source
# File lib/core/facade.rb 316 def create_plugin(namespace, plugin_type, provider, options = {}) 317 Manager.connection.create(namespace, plugin_type, provider, options) 318 end
define_types(namespace, type_info)
click to toggle source
# File lib/core/facade.rb 257 def define_types(namespace, type_info) 258 Manager.connection.define_types(namespace, type_info) 259 end
event(options, provider = nil)
click to toggle source
# File lib/core/facade.rb 419 def event(options, provider = nil) 420 plugin(:nucleon, :event, provider, options) 421 end
events(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 423 def events(data, build_hash = false, keep_array = false) 424 plugins(:nucleon, :event, data, build_hash, keep_array) 425 end
exec(method, options = {}, &code)
click to toggle source
# File lib/core/facade.rb 450 def exec(method, options = {}, &code) 451 Manager.connection.exec(method, options, &code) 452 end
executable(args, name = 'nucleon')
click to toggle source
# File lib/core/facade.rb 522 def executable(args, name = 'nucleon') #ARGV 523 $0 = name.to_s # Set process name 524 525 $stdout.sync = true 526 $stderr.sync = true 527 528 @@exec_state = executable_state 529 exit_status = code.unknown_status 530 531 # We need to catch this early. 532 Util::Console.use_colors = ! args.include?("--no-color") 533 args = args - [ "--no-color", "--color" ] 534 535 begin 536 arg_components = Util::CLI::Parser.split(args, cyan(name) + yellow(" <action components> [<arg> ...]")) 537 main_command = arg_components.shift 538 539 logger.info("Beginning #{name} execution run with arguments: #{args.inspect}") 540 541 exec(:executable_load) 542 load_plugins 543 544 exec(:executable_init, { :name => name, :args => args }) 545 546 action, action_components, args = search_actions(args) 547 548 if main_command.processed && action.is_a?(Hash) 549 action_cli(action[:provider], args, false, name, false, @@exec_state) 550 551 action_error = @@exec_state.error 552 exit_status = @@exec_state.status 553 else 554 puts I18n.t('nucleon.core.exec.help.usage') + ': ' + main_command.help + "\n" 555 puts I18n.t('nucleon.core.exec.help.header') + ":\n" 556 557 action = main_command.processed ? action : nil 558 puts action_help(action, args.include?("--help")) 559 560 puts "\n" + I18n.t('nucleon.core.exec.help.footer', { :command => cyan(name) + yellow(" <action> -h") }) + "\n\n" 561 exit_status = code.help_wanted 562 end 563 564 rescue => error 565 action_error = error 566 exit_status = code.unknown_status 567 end 568 569 if action_error && ! action_error.is_a?(SystemExit) 570 logger.error("Nucleon executable experienced an error:") 571 logger.error(action_error.inspect) 572 logger.error(action_error.message) 573 logger.error(Util::Data.to_yaml(action_error.backtrace)) 574 575 ui.error(action_error.message, { :prefix => false }) if action_error.message 576 end 577 exec(:executable_exit, { :status => exit_status }) 578 exit_status 579 end
executable_state()
click to toggle source
# File lib/core/facade.rb 518 def executable_state 519 Plugin::Action::State.new(code.unknown_status) 520 end
extension(provider)
click to toggle source
# File lib/core/facade.rb 349 def extension(provider) 350 plugin(:nucleon, :extension, provider, {}) 351 end
get_plugin(namespace, plugin_type, plugin_name)
click to toggle source
# File lib/core/facade.rb 322 def get_plugin(namespace, plugin_type, plugin_name) 323 Manager.connection.get(namespace, plugin_type, plugin_name) 324 end
handle(klass)
click to toggle source
# File lib/core/facade.rb 128 def handle(klass) 129 if parallel? && klass.respond_to?(:current_actor) 130 myself = klass.current_actor 131 else 132 myself = klass 133 end 134 myself 135 end
interrupt_handler()
click to toggle source
# File lib/core/facade.rb 583 def interrupt_handler 584 logger.warn("Nucleon executable interrupted, shutting down") 585 if @@exec_state.action 586 @@exec_state.action.status = code.action_interrupted 587 @@exec_state.action.finalize_execution(false) 588 end 589 code.action_interrupted 590 end
ip_address(reset = false)
click to toggle source
# File lib/core/facade.rb 190 def ip_address(reset = false) 191 external_ip = nil 192 cached_ip_file = File.join(Dir.tmpdir(), 'nucleon_ip.json') 193 194 unless @@ip_cache 195 json_text = Util::Data.ensure_value(Util::Disk.read(cached_ip_file), '') 196 @@ip_cache = Util::Data.parse_json(json_text) unless json_text.empty? 197 end 198 199 fetch_ip = lambda do 200 ip_command = value(:external_address_command, 'dig +short myip.opendns.com @resolver1.opendns.com') 201 ip_address = `#{ip_command}`.strip 202 203 unless ip_address.empty? 204 @@ip_cache = { 205 'ip' => ip_address, 206 'updated' => Time.new.to_s 207 } 208 Util::Disk.write(cached_ip_file, Util::Data.to_json(@@ip_cache)) 209 end 210 ip_address 211 end 212 213 if reset || (! @@ip_cache || @@ip_cache.empty? || ! @@ip_cache.has_key?('ip')) 214 external_ip = fetch_ip.call 215 else 216 external_ip = @@ip_cache['ip'] 217 updated_time = Time.parse(@@ip_cache['updated']) 218 cache_duration = (Time.new - updated_time) / 60 # Seconds to minutes 219 220 if cache_duration >= value(:external_address_lifetime, 360) 221 external_ip = fetch_ip.call 222 end 223 end 224 external_ip 225 end
load_plugins(base_dir = nil, search_parents = true)
click to toggle source
# File lib/core/facade.rb 267 def load_plugins(base_dir = nil, search_parents = true) 268 base_dir = base_dir.nil? ? Dir.pwd : base_dir 269 270 search_plugins = lambda do |search_dir| 271 lib_dir = File.join(search_dir, 'lib') 272 273 if File.directory?(lib_dir) 274 logger.debug("Registering plugins at #{lib_dir}") 275 register(lib_dir) 276 end 277 278 if search_parents 279 parent_search_dir = search_dir.sub(/#{File::SEPARATOR}[^#{File::SEPARATOR}]+$/, '') 280 search_plugins.call(parent_search_dir) unless parent_search_dir.split(File::SEPARATOR).empty? 281 end 282 end 283 284 search_plugins.call(base_dir) 285 end
loaded_plugins(namespace = nil, plugin_type = nil, provider = nil)
click to toggle source
# File lib/core/facade.rb 292 def loaded_plugins(namespace = nil, plugin_type = nil, provider = nil) 293 Manager.connection.loaded_plugins(namespace, plugin_type, provider) 294 end
log_level()
click to toggle source
# File lib/core/facade.rb 118 def log_level 119 Util::Logger.level 120 end
log_level=(log_level)
click to toggle source
# File lib/core/facade.rb 122 def log_level=log_level 123 Util::Logger.level = log_level 124 end
logger()
click to toggle source
# File lib/core/facade.rb 114 def logger 115 Core.logger 116 end
manager(collection, name, klass, reset = false)
click to toggle source
# File lib/core/facade.rb 139 def manager(collection, name, klass, reset = false) 140 name = name.to_sym 141 actor_id = "#{klass}::#{name}".to_sym 142 143 if collection.has_key?(actor_id) 144 manager = parallel? ? Celluloid::Actor[actor_id] : collection[actor_id] 145 else 146 if parallel? 147 klass.supervise({ :as => actor_id, :args => [actor_id, reset] }) 148 manager = Celluloid::Actor[actor_id] 149 else 150 manager = klass.new(actor_id, reset) # Managers should have standardized initialization parameters 151 end 152 collection[actor_id] = manager 153 end 154 test_connection(actor_id, manager) 155 end
namespaces()
click to toggle source
# File lib/core/facade.rb 247 def namespaces 248 Manager.connection.namespaces 249 end
plugin(namespace, plugin_type, provider, options = {})
click to toggle source
# File lib/core/facade.rb 304 def plugin(namespace, plugin_type, provider, options = {}) 305 Manager.connection.load(namespace, plugin_type, provider, options) 306 end
plugin_class(namespace, plugin_type)
click to toggle source
# File lib/core/facade.rb 338 def plugin_class(namespace, plugin_type) 339 Manager.connection.plugin_class(namespace, plugin_type) 340 end
plugins(namespace, plugin_type, data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 310 def plugins(namespace, plugin_type, data, build_hash = false, keep_array = false) 311 Manager.connection.load_multiple(namespace, plugin_type, data, build_hash, keep_array) 312 end
project(options, provider = nil)
click to toggle source
# File lib/core/facade.rb 398 def project(options, provider = nil) 399 plugin(:nucleon, :project, provider, options) 400 end
projects(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 402 def projects(data, build_hash = false, keep_array = false) 403 plugins(:nucleon, :project, data, build_hash, keep_array) 404 end
provider_class(namespace, plugin_type, provider)
click to toggle source
# File lib/core/facade.rb 342 def provider_class(namespace, plugin_type, provider) 343 Manager.connection.provider_class(namespace, plugin_type, provider) 344 end
quiet=(quiet)
click to toggle source
# File lib/core/facade.rb 108 def quiet=quiet 109 Util::Console.quiet = quiet 110 end
register(base_path, &code)
click to toggle source
# File lib/core/facade.rb 287 def register(base_path, &code) 288 Manager.connection.register(base_path, &code) 289 Manager.connection.autoload 290 end
reload(core = false, loaded = [], &code)
click to toggle source
# File lib/core/facade.rb 241 def reload(core = false, loaded = [], &code) 242 Manager.connection.reload(core, loaded, &code) 243 end
remove_plugin(plugin)
click to toggle source
# File lib/core/facade.rb 332 def remove_plugin(plugin) 333 Manager.connection.remove(plugin) 334 end
remove_plugin_by_name(namespace, plugin_type, plugin_instance_name)
click to toggle source
# File lib/core/facade.rb 328 def remove_plugin_by_name(namespace, plugin_type, plugin_instance_name) 329 Manager.connection.remove_by_name(namespace, plugin_type, plugin_instance_name) 330 end
render_object(data)
click to toggle source
# File lib/core/facade.rb 637 def render_object(data) 638 require 'pp' 639 PP.pp(data, "").strip 640 end
render_tree(data, logger, state = :debug, padding = '')
click to toggle source
# File lib/core/facade.rb 644 def render_tree(data, logger, state = :debug, padding = '') 645 if data.is_a?(Hash) || data.is_a?(Nucleon::Config) 646 data = data.export if data.is_a?(Nucleon::Config) 647 data.each do |key, value| 648 logger.send(state, "#{padding}#{key}") 649 if value.is_a?(Hash) || value.is_a?(Nucleon::Config) 650 render_tree(value, logger, state, "#{padding} ") 651 end 652 end 653 end 654 end
run() { || ... }
click to toggle source
# File lib/core/facade.rb 481 def run 482 begin 483 logger.debug("Running contained process at #{Time.now}") 484 yield 485 486 rescue Exception => error 487 logger.error("Nucleon run experienced an error! Details:") 488 logger.error(error.inspect) 489 logger.error(error.message) 490 logger.error(Util::Data.to_yaml(error.backtrace)) 491 492 ui.error(error.message) if error.message 493 raise 494 end 495 end
search_actions(args)
click to toggle source
# File lib/core/facade.rb 379 def search_actions(args) 380 action_info = Plugin::Action.search_actions(args) 381 382 action_components = action_info[:components] 383 action = action_info[:actions] 384 385 action_components.each do |component| 386 args.shift 387 end 388 389 [ action, action_components, args ] 390 end
sha1(data)
click to toggle source
# File lib/core/facade.rb 607 def sha1(data) 608 Digest::SHA1.hexdigest(Util::Data.to_json(data, false)) 609 end
silence() { || ... }
click to toggle source
# File lib/core/facade.rb 613 def silence 614 result = nil 615 616 begin 617 orig_stderr = $stderr.clone 618 orig_stdout = $stdout.clone 619 $stderr.reopen File.new('/dev/null', 'w') 620 $stdout.reopen File.new('/dev/null', 'w') 621 622 result = yield 623 624 rescue Exception => error 625 $stdout.reopen orig_stdout 626 $stderr.reopen orig_stderr 627 raise error 628 ensure 629 $stdout.reopen orig_stdout 630 $stderr.reopen orig_stderr 631 end 632 result 633 end
template(options, provider = nil)
click to toggle source
# File lib/core/facade.rb 429 def template(options, provider = nil) 430 plugin(:nucleon, :template, provider, options) 431 end
templates(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 433 def templates(data, build_hash = false, keep_array = false) 434 plugins(:nucleon, :template, data, build_hash, keep_array) 435 end
test_connection(actor_id, manager)
click to toggle source
# File lib/core/facade.rb 157 def test_connection(actor_id, manager) 158 if parallel? 159 begin 160 # Raise error if no test method found but retry for dead actors 161 manager.test_connection 162 163 rescue NoMethodError, Celluloid::DeadActorError 164 retry 165 end 166 end 167 manager 168 end
translator(options, provider = nil)
click to toggle source
# File lib/core/facade.rb 439 def translator(options, provider = nil) 440 plugin(:nucleon, :translator, provider, options) 441 end
translators(data, build_hash = false, keep_array = false)
click to toggle source
# File lib/core/facade.rb 443 def translators(data, build_hash = false, keep_array = false) 444 plugins(:nucleon, :translator, data, build_hash, keep_array) 445 end
type_default(namespace, plugin_type)
click to toggle source
# File lib/core/facade.rb 261 def type_default(namespace, plugin_type) 262 Manager.connection.type_default(namespace, plugin_type) 263 end
types(namespace)
click to toggle source
# File lib/core/facade.rb 253 def types(namespace) 254 Manager.connection.types(namespace) 255 end
ui()
click to toggle source
# File lib/core/facade.rb 100 def ui 101 Core.ui 102 end
ui_group(resource, color = :cyan, &code)
click to toggle source
# File lib/core/facade.rb 104 def ui_group(resource, color = :cyan, &code) 105 Core.ui_group(resource, color, &code) 106 end
value(method, value, options = {})
click to toggle source
# File lib/core/facade.rb 468 def value(method, value, options = {}) 469 Manager.connection.value(method, value, options) 470 end