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
218
219
220
221
222
223
|
# File 'lib/objects/node/base.rb', line 218
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
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/objects/node/base.rb', line 237
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
232
233
234
235
|
# File 'lib/objects/node/base.rb', line 232
def execute_local(command)
puts "(local) > #{command}"
system(command)
end
|
#execute_script(script_name) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/objects/node/base.rb', line 97
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
202
203
204
|
# File 'lib/objects/node/base.rb', line 202
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
|
#identifier=(new_identifier) ⇒ Object
60
61
62
|
# File 'lib/objects/node/base.rb', line 60
def identifier=(new_identifier)
@identifier = new_identifier
end
|
#inventory? ⇒ Boolean
44
45
46
|
# File 'lib/objects/node/base.rb', line 44
def inventory?
false
end
|
#invoke(method_name, arguments = []) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/objects/node/base.rb', line 156
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
206
207
208
|
# File 'lib/objects/node/base.rb', line 206
def is_top_level_node?
!has_parent?
end
|
#keyed_namespace ⇒ Object
197
198
199
200
|
# File 'lib/objects/node/base.rb', line 197
def keyed_namespace
splits = namespace.split(":") ;
splits[1..splits.size].join(":")
end
|
#list_attributes ⇒ Object
210
211
212
213
214
215
216
|
# File 'lib/objects/node/base.rb', line 210
def list_attributes
{
"Identifier": :identifier,
"Description": :description,
"Type": :type
}
end
|
#list_key ⇒ Object
152
153
154
|
# File 'lib/objects/node/base.rb', line 152
def list_key
:view
end
|
#namespace ⇒ Object
193
194
195
|
# File 'lib/objects/node/base.rb', line 193
def namespace
"#{ parent ? "#{parent.namespace}:" : "" }#{identifier}"
end
|
#no_nodes? ⇒ Boolean
140
141
142
|
# File 'lib/objects/node/base.rb', line 140
def no_nodes?
!resources || resources.empty?
end
|
#nodes_loaded? ⇒ Boolean
144
145
146
|
# File 'lib/objects/node/base.rb', line 144
def nodes_loaded?
resources.any?
end
|
#open_ssh_connections ⇒ Object
225
226
227
228
229
230
|
# File 'lib/objects/node/base.rb', line 225
def open_ssh_connections
machines.pmap do |machine|
machine.open_ssh_connection unless machine.has_ssh_connection?
end
return
end
|
106
107
108
|
# File 'lib/objects/node/base.rb', line 106
def pack_metadata
::Bcome::Encryptor.instance.pack
end
|
#prompt_breadcrumb ⇒ Object
189
190
191
|
# File 'lib/objects/node/base.rb', line 189
def prompt_breadcrumb
"#{has_parent? ? "#{parent.prompt_breadcrumb}> " : "" }#{ is_current_context? ? (has_parent? ? identifier.terminal_prompt : identifier) : identifier}"
end
|
#proxy ⇒ Object
64
65
66
|
# File 'lib/objects/node/base.rb', line 64
def proxy
ssh_driver.proxy
end
|
#put(local_path, remote_path) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/objects/node/base.rb', line 83
def put(local_path, remote_path)
resources.active.each do |resource|
resource.put(local_path, remote_path)
end
return
end
|
#put_from_string(string, remote_path) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/objects/node/base.rb', line 90
def put_from_string(string, remote_path)
resources.active.each do |resource|
resource.put_from_string(local_path, remote_path)
end
return
end
|
#recurse_resource_for_identifier(identifier) ⇒ Object
184
185
186
187
|
# File 'lib/objects/node/base.rb', line 184
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
132
133
134
|
# File 'lib/objects/node/base.rb', line 132
def requires_description?
true
end
|
#requires_type? ⇒ Boolean
136
137
138
|
# File 'lib/objects/node/base.rb', line 136
def requires_type?
true
end
|
#resource_for_identifier(identifier) ⇒ Object
180
181
182
|
# File 'lib/objects/node/base.rb', line 180
def resource_for_identifier(identifier)
resources.for_identifier(identifier)
end
|
#rsync(local_path, remote_path) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/objects/node/base.rb', line 76
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?
69
70
71
72
73
74
|
# File 'lib/objects/node/base.rb', line 69
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
|
110
111
112
|
# File 'lib/objects/node/base.rb', line 110
def unpack_metadata
::Bcome::Encryptor.instance.unpack
end
|
#validate_attributes ⇒ Object
#validate_identifier ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/objects/node/base.rb', line 120
def validate_identifier
@identifier = DEFAULT_IDENTIFIER if is_top_level_node? && !@identifier && !is_a?(::Bcome::Node::Server::Base)
@identifier = "NO-ID_#{Time.now.to_i}" unless @identifier
@identifier.gsub!(/\s/, "_") @identifier.gsub!("-", "_")
end
|