Class: Bcome::Node::Base
Constant Summary
collapse
- DEFAULT_IDENTIFIER =
"bcome"
LocalMetaDataFactory::META_DATA_FILE_PATH_PREFIX
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#registry, #user_command_wrapper
#do_create_metadata, #meta, #metadata, #metadata_for_namespace, #raw_metadata
#item_spacing, #menu, #menu_item_spacing_length, #menu_items, #mode, #tab_spacing
Methods included from Attributes
#description, #filters, #identifier, #network_data, #network_driver, #recurse_hash_data_for_instance_var, #ssh_data, #ssh_driver, #type
#back, #cd, #clear!, #disable, #disable!, #enable, #enable!, #interactive, #is_node_level_method?, #list_in_tree, #ls, #lsa, #method_in_registry?, #method_is_available_on_node?, #method_missing, #new_line, #parents, #ping, #pretty_description, #print_tree_view_for_resource, #resource_identifiers, #run, #tree, #tree_descriptions, #visual_hierarchy, #workon
Methods included from Context
#irb_workspace=, #is_current_context?, #previous_irb_workspace=
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/objects/node/base.rb', line 22
def initialize(params)
@params = params
@identifier = nil
@description = nil
@views = params[:views]
@parent = params[:parent]
@type = params[:type]
@metadata = {}
set_view_attributes if @views
validate_attributes
::Bcome::Registry::Loader.instance.set_command_group_for_node(self)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Bcome::WorkspaceCommands
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
20
21
22
|
# File 'lib/objects/node/base.rb', line 20
def params
@params
end
|
Class Method Details
.const_missing(constant) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/objects/node/base.rb', line 13
def self.const_missing(constant)
set_context = ::IRB.CurrentContext.workspace.main
return (set_context.resource_for_identifier(constant.to_s)) ? constant.to_s : super
end
|
Instance Method Details
#bootstrap? ⇒ Boolean
36
37
38
|
# File 'lib/objects/node/base.rb', line 36
def bootstrap?
false
end
|
#close_ssh_connections ⇒ Object
201
202
203
204
205
206
|
# File 'lib/objects/node/base.rb', line 201
def close_ssh_connections
machines.pmap do |machine|
machine.close_ssh_connection
end
return
end
|
#collection? ⇒ Boolean
40
41
42
|
# File 'lib/objects/node/base.rb', line 40
def collection?
false
end
|
#data_print_from_hash(data, heading) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/objects/node/base.rb', line 220
def data_print_from_hash(data, heading)
puts "\n#{heading.title}"
puts ""
if data.keys.any?
data.each do |key, value|
puts "#{key.to_s.resource_key}: #{value.to_s.informational}"
end
else
puts "No values found".warning
end
puts ""
end
|
52
53
54
|
# File 'lib/objects/node/base.rb', line 52
def
[:ls, :lsa, :workon, :enable, :disable, :enable!, :disable!, :run, :tree, :ping, :put, :rsync, :cd, :meta, :pack_metadata, :unpack_metadata, :registry, :interactive, :execute_script]
end
|
#execute_local(command) ⇒ Object
215
216
217
218
|
# File 'lib/objects/node/base.rb', line 215
def execute_local(command)
puts "(local) > #{command}"
system(command)
end
|
#execute_script(script_name) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/objects/node/base.rb', line 86
def execute_script(script_name)
results = {}
machines.pmap do |machine|
command = machine.execute_script(script_name)
results[machine.namespace] = command
end
results
end
|
#has_parent? ⇒ Boolean
185
186
187
|
# File 'lib/objects/node/base.rb', line 185
def has_parent?
!@parent.nil?
end
|
#has_proxy? ⇒ Boolean
56
57
58
|
# File 'lib/objects/node/base.rb', line 56
def has_proxy?
ssh_driver.has_proxy?
end
|
#inventory? ⇒ Boolean
44
45
46
|
# File 'lib/objects/node/base.rb', line 44
def inventory?
false
end
|
#invoke(method_name, arguments = []) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/objects/node/base.rb', line 139
def invoke(method_name, arguments = [])
if method_is_available_on_node?(method_name)
if respond_to?(method_name)
begin
if arguments && arguments.any?
send(method_name, *arguments)
else
send(method_name)
end
rescue ArgumentError => e
raise ::Bcome::Exception::ArgumentErrorInvokingMethodFromCommmandLine.new method_name + "error message - #{e.message}"
end
else
command = user_command_wrapper.command_for_console_command_name(method_name.to_sym)
command.execute(self, arguments)
end
else
raise ::Bcome::Exception::InvalidBreadcrumb.new("Method '#{method_name}' is not available on bcome node of type #{self.class}, at namespace #{namespace}")
end
end
|
#is_top_level_node? ⇒ Boolean
189
190
191
|
# File 'lib/objects/node/base.rb', line 189
def is_top_level_node?
!has_parent?
end
|
#keyed_namespace ⇒ Object
180
181
182
183
|
# File 'lib/objects/node/base.rb', line 180
def keyed_namespace
splits = namespace.split(":") ;
splits[1..splits.size].join(":")
end
|
#list_attributes ⇒ Object
193
194
195
196
197
198
199
|
# File 'lib/objects/node/base.rb', line 193
def list_attributes
{
"Identifier": :identifier,
"Description": :description,
"Type": :type
}
end
|
#list_key ⇒ Object
135
136
137
|
# File 'lib/objects/node/base.rb', line 135
def list_key
:view
end
|
#namespace ⇒ Object
176
177
178
|
# File 'lib/objects/node/base.rb', line 176
def namespace
"#{ parent ? "#{parent.namespace}:" : "" }#{identifier}"
end
|
#no_nodes? ⇒ Boolean
123
124
125
|
# File 'lib/objects/node/base.rb', line 123
def no_nodes?
!resources || resources.empty?
end
|
#nodes_loaded? ⇒ Boolean
127
128
129
|
# File 'lib/objects/node/base.rb', line 127
def nodes_loaded?
resources.any?
end
|
#open_ssh_connections ⇒ Object
208
209
210
211
212
213
|
# File 'lib/objects/node/base.rb', line 208
def open_ssh_connections
machines.pmap do |machine|
machine.open_ssh_connection unless machine.has_ssh_connection?
end
return
end
|
95
96
97
|
# File 'lib/objects/node/base.rb', line 95
def pack_metadata
::Bcome::Encryptor.instance.pack
end
|
#prompt_breadcrumb ⇒ Object
172
173
174
|
# File 'lib/objects/node/base.rb', line 172
def prompt_breadcrumb
"#{has_parent? ? "#{parent.prompt_breadcrumb}> " : "" }#{ is_current_context? ? (has_parent? ? identifier.terminal_prompt : identifier) : identifier}"
end
|
#proxy ⇒ Object
60
61
62
|
# File 'lib/objects/node/base.rb', line 60
def proxy
ssh_driver.proxy
end
|
#put(local_path, remote_path) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/objects/node/base.rb', line 79
def put(local_path, remote_path)
resources.active.each do |resource|
resource.put(local_path, remote_path)
end
return
end
|
#recurse_resource_for_identifier(identifier) ⇒ Object
167
168
169
170
|
# File 'lib/objects/node/base.rb', line 167
def recurse_resource_for_identifier(identifier)
resource = resource_for_identifier(identifier)
return resource ? resource : (has_parent? ? parent.recurse_resource_for_identifier(identifier) : nil)
end
|
#requires_description? ⇒ Boolean
115
116
117
|
# File 'lib/objects/node/base.rb', line 115
def requires_description?
true
end
|
#requires_type? ⇒ Boolean
119
120
121
|
# File 'lib/objects/node/base.rb', line 119
def requires_type?
true
end
|
#resource_for_identifier(identifier) ⇒ Object
163
164
165
|
# File 'lib/objects/node/base.rb', line 163
def resource_for_identifier(identifier)
resources.for_identifier(identifier)
end
|
#rsync(local_path, remote_path) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/objects/node/base.rb', line 72
def rsync(local_path, remote_path)
resources.active.each do |resource|
resource.rsync(local_path, remote_path)
end
return
end
|
#scp(local_path, remote_path) ⇒ Object
TODO - why not do these in parallel?
65
66
67
68
69
70
|
# File 'lib/objects/node/base.rb', line 65
def scp(local_path, remote_path)
resources.active.each do |resource|
resource.put(local_path, remote_path)
end
return
end
|
#server? ⇒ Boolean
48
49
50
|
# File 'lib/objects/node/base.rb', line 48
def server?
false
end
|
99
100
101
|
# File 'lib/objects/node/base.rb', line 99
def unpack_metadata
::Bcome::Encryptor.instance.unpack
end
|
#validate_attributes ⇒ Object
#validate_identifier ⇒ Object