Class: Bcome::Stack::Base
Constant Summary
Orchestrator::Registry::CONFIGS_PATH
ContextFunctions::CONFIGS_PATH
Class Method Summary
collapse
Instance Method Summary
collapse
#config_for_registry, #do_load_recipes, #has_registry_config?, #load_recipe_registry, #recipe_registry, #registry_configs_path
#run_local
#command_for_context, #context_cmd_config_path, #context_cmd_functions, #context_commands, #execute_command_for_context, #has_context_cmd_functions?, #has_context_functions_config?, #load_context_cmd_functions
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/stack/base.rb', line 25
def method_missing(method_sym, *arguments, &block)
if command_for_context = command_for_context(method_sym)
execute_command_for_context(command_for_context, arguments)
elsif recipe = ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)
puts "Executing Command Recipe #{recipe.recipe_identifier}".informational
puts "Description: #{recipe.description}".command
recipe.execute!(machines)
return
else
return method_sym.to_s if is_stack_level_resource?(method_sym)
super
end
end
|
Class Method Details
.const_missing(constant_name) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/stack/base.rb', line 16
def self.const_missing(constant_name)
stack_level_instance = ::IRB.CurrentContext.workspace.main
return constant_name.to_s if stack_level_instance.is_stack_level_resource?(constant_name)
super
end
|
Instance Method Details
#available_resources_options_string ⇒ Object
127
128
129
|
# File 'lib/stack/base.rb', line 127
def available_resources_options_string
"Please select from one of: #{all_items.join(', ')}'"
end
|
#become(object) ⇒ Object
88
89
90
|
# File 'lib/stack/base.rb', line 88
def become(object)
BECOME.set(object, self)
end
|
#become_identifier ⇒ Object
84
85
86
|
# File 'lib/stack/base.rb', line 84
def become_identifier
::START_PROMPT
end
|
#construct_node ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/stack/base.rb', line 60
def construct_node
node_attributes = meta_data
node_attributes.merge!({
collection_key => resources.collect(&:node)
}) if respond_to?(:collection_key)
this_node = node_level_klass.new(node_attributes)
this_node.set_parent_reference(this_node, child_reference_key, collection_key) if respond_to?(:collection_key) && respond_to?(:child_reference_key)
return this_node
end
|
131
132
133
134
135
136
137
138
|
# File 'lib/stack/base.rb', line 131
def describe
if self.respond_to?(:do_describe)
message = "\n\tCollection Key:". + "\s#{reference_key}\n\n#{self.do_describe}"
else
message = "\nNothing to describe. Use 'ls' or 'list' to see namespace options".headsup unless self.respond_to?(:do_describe)
end
puts message
end
|
#has_sub_nodes? ⇒ Boolean
40
41
42
|
# File 'lib/stack/base.rb', line 40
def has_sub_nodes?
return true
end
|
#highlight? ⇒ Boolean
123
124
125
|
# File 'lib/stack/base.rb', line 123
def highlight?
false end
|
76
77
78
|
# File 'lib/stack/base.rb', line 76
def init
node
end
|
8
9
10
|
# File 'lib/stack/base.rb', line 8
def machines
node.machines
end
|
106
107
108
|
# File 'lib/stack/base.rb', line 106
def
::RENDER.(, self)
end
|
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/stack/base.rb', line 110
def
[
{ :command => "list / ls", :description => "List all available resources at the current context." },
{ :command => "describe", :description => "Describe the resource object at the current context." },
{ :command => "cd NodeName", :description => "Select a resource object, and switch to its context.", :usage => "cd YourServerName" },
{ :command => "exit", :description => "Return to the previous context" },
{ :command => "exit!", :description => "Close all contexts, and exit Become."},
{ :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'},
{ :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" },
{ :command => "interactive", :description => "Enter an interactive where you may transparently interact with all the machines in your selection at once" },
]
end
|
52
53
54
|
# File 'lib/stack/base.rb', line 52
def node
@node ||= construct_node
end
|
#node_level_klass ⇒ Object
72
73
74
|
# File 'lib/stack/base.rb', line 72
def node_level_klass
raise "Should be overidden in derived stack type"
end
|
Construction & Initialisation
48
49
50
|
# File 'lib/stack/base.rb', line 48
def recipes
@recipes ||= do_load_recipes
end
|
#respond_to_bcome_context_method?(method_sym) ⇒ Boolean
56
57
58
|
# File 'lib/stack/base.rb', line 56
def respond_to_bcome_context_method?(method_sym)
return (command_for_context(method_sym) || ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)) ? true : false
end
|
#workon(identifier) ⇒ Object
Also known as:
w, cd
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/stack/base.rb', line 92
def workon(identifier)
resource = resource_for_identifier(identifier)
unless resource
puts "\nNo matching #{collection_key} for identifier '#{identifier}'.".failure + "\n\n#{available_resources_options_string}" + "\n\n"
else
puts "\nFrom #{resource.reference_key}, working on '#{identifier}'.".informational + "\n\n"
puts "Hit 'menu' or 'ls' to see what you can do here.\n\n"
become(resource)
end
end
|