Class: Bcome::Node::Server::Base
- Inherits:
-
Base
- Object
- Base
- Bcome::Node::Server::Base
show all
- Defined in:
- lib/objects/node/server/base.rb
Constant Summary
Constants inherited
from Base
Base::DEFAULT_IDENTIFIER
LocalMetaDataFactory::META_DATA_FILE_PATH_PREFIX
Instance Attribute Summary collapse
Attributes inherited from Base
#params
Instance Method Summary
collapse
Methods inherited from Base
#close_ssh_connections, #collection?, const_missing, #data_print_from_hash, #execute_local, #has_parent?, #has_proxy?, #identifier=, #inventory?, #invoke, #is_top_level_node?, #keyed_namespace, #list_key, #namespace, #no_nodes?, #nodes_loaded?, #open_ssh_connections, #pack_metadata, #prompt_breadcrumb, #proxy, #recurse_resource_for_identifier, #resource_for_identifier, #resources, #scp, #unpack_metadata, #validate_attributes, #validate_identifier
#registry, #user_command_wrapper
#do_create_metadata, #meta, #metadata, #metadata_for_namespace, #raw_metadata
#item_spacing, #menu, #menu_item_spacing_length, #mode, #tab_spacing
Methods included from Attributes
#description, #filters, #identifier, #network_data, #network_driver, #recurse_hash_data_for_instance_var, #ssh_data, #ssh_driver
#back, #cd, #clear!, #disable, #disable!, #enable, #enable!, #interactive, #is_node_level_method?, #list_in_tree, #method_in_registry?, #method_is_available_on_node?, #method_missing, #new_line, #parents, #pretty_description, #print_tree_view_for_resource, #resource_identifiers, #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.
6
7
8
9
10
11
|
# File 'lib/objects/node/server/base.rb', line 6
def initialize(*params)
super
@origin_object_id = object_id
@bootstrap = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Bcome::WorkspaceCommands
Instance Attribute Details
#origin_object_id ⇒ Object
Returns the value of attribute origin_object_id.
4
5
6
|
# File 'lib/objects/node/server/base.rb', line 4
def origin_object_id
@origin_object_id
end
|
Instance Method Details
#bootstrap? ⇒ Boolean
24
25
26
|
# File 'lib/objects/node/server/base.rb', line 24
def bootstrap?
@bootstrap ? true : false
end
|
#cache_data ⇒ Object
208
209
210
211
212
213
214
215
|
# File 'lib/objects/node/server/base.rb', line 208
def cache_data
d = { identifier: identifier }
d[:internal_ip_address] = internal_ip_address if internal_ip_address
d[:public_ip_address] = public_ip_address if public_ip_address
d[:description] = description if description
d[:cloud_tags] = cloud_tags
d
end
|
#close_ssh_connection ⇒ Object
120
121
122
|
# File 'lib/objects/node/server/base.rb', line 120
def close_ssh_connection
ssh_driver.close_ssh_connection
end
|
47
48
49
|
# File 'lib/objects/node/server/base.rb', line 47
def cloud_tags
@generated_tags ||= do_generate_cloud_tags
end
|
60
61
62
|
# File 'lib/objects/node/server/base.rb', line 60
def do_generate_cloud_tags
raise "Should be overidden"
end
|
#do_run(raw_commands) ⇒ Object
217
218
219
220
221
222
223
224
|
# File 'lib/objects/node/server/base.rb', line 217
def do_run(raw_commands)
raw_commands = raw_commands.is_a?(String) ? [raw_commands] : raw_commands
commands = raw_commands.collect{|raw_command| ::Bcome::Ssh::Command.new({ :node => self, :raw => raw_command }) }
command_exec = ::Bcome::Ssh::CommandExec.new(commands)
command_exec.execute!
commands.each {|c| c.unset_node }
return commands
end
|
#dup_with_new_parent(new_parent) ⇒ Object
33
34
35
36
37
|
# File 'lib/objects/node/server/base.rb', line 33
def dup_with_new_parent(new_parent)
new_node = self.clone
new_node.update_parent(new_parent)
new_node
end
|
#dynamic_server? ⇒ Boolean
240
241
242
|
# File 'lib/objects/node/server/base.rb', line 240
def dynamic_server?
!static_server?
end
|
84
85
86
|
# File 'lib/objects/node/server/base.rb', line 84
def
(super + [:get, :ssh, :tags, :pseudo_tty]) - [:enable, :disable, :enable!, :disable!]
end
|
#execute_script(script_name) ⇒ Object
143
144
145
146
|
# File 'lib/objects/node/server/base.rb', line 143
def execute_script(script_name)
command_result = ::Bcome::Ssh::ScriptExec.execute(self, script_name)
return command_result
end
|
#get(remote_path, local_path) ⇒ Object
156
157
158
|
# File 'lib/objects/node/server/base.rb', line 156
def get(remote_path, local_path)
ssh_driver.get(remote_path, local_path)
end
|
#has_description? ⇒ Boolean
232
233
234
|
# File 'lib/objects/node/server/base.rb', line 232
def has_description?
!@description.nil?
end
|
#has_no_ssh_connection? ⇒ Boolean
128
129
130
|
# File 'lib/objects/node/server/base.rb', line 128
def has_no_ssh_connection?
!has_ssh_connection?
end
|
#has_ssh_connection? ⇒ Boolean
124
125
126
|
# File 'lib/objects/node/server/base.rb', line 124
def has_ssh_connection?
ssh_driver.has_open_ssh_con?
end
|
#has_tagged_value?(key, values) ⇒ Boolean
51
52
53
54
|
# File 'lib/objects/node/server/base.rb', line 51
def has_tagged_value?(key, values)
matchers = { :key => key, :values => values }
cloud_tags.has_key_and_value?(matchers)
end
|
#list_attributes ⇒ Object
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/objects/node/server/base.rb', line 197
def list_attributes
attribs = {
"identifier": :identifier,
"internal ip": :internal_ip_address,
"public ip": :public_ip_address,
}
attribs.merge!("description": :description ) if has_description?
attribs
end
|
#local_port_forward(start_port, end_port) ⇒ Object
112
113
114
|
# File 'lib/objects/node/server/base.rb', line 112
def local_port_forward(start_port, end_port)
ssh_driver.local_port_forward(start_port, end_port)
end
|
#ls ⇒ Object
Also known as:
lsa
160
161
162
163
|
# File 'lib/objects/node/server/base.rb', line 160
def ls
puts "\n" + visual_hierarchy.hierarchy + "\n"
puts pretty_description
end
|
#machines ⇒ Object
68
69
70
|
# File 'lib/objects/node/server/base.rb', line 68
def machines
[self]
end
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/objects/node/server/base.rb', line 88
def
base_items = super.dup
base_items[:tags] = {
description: "print out remote EC2 tags"
}
base_items[:ssh] = {
description: "initiate an ssh connection to this server",
}
base_items[:get] = {
description: "Download a file or directory",
console_only: false,
usage: "get \"/remote/path\", \"/local/path\"",
terminal_usage: "get \"/remote/path\" \"/local/path\""
}
base_items[:pseudo_tty] = {
description: "Invoke a pseudo-tty session",
console_only: false,
usage: "pseudo_tty \"your command\"",
terminal_usage: "pseudo_tty \"your command\""
}
base_items
end
|
#open_ssh_connection ⇒ Object
116
117
118
|
# File 'lib/objects/node/server/base.rb', line 116
def open_ssh_connection
ssh_driver.ssh_connection
end
|
#ping ⇒ Object
166
167
168
169
|
# File 'lib/objects/node/server/base.rb', line 166
def ping
ping_result = ssh_driver.ping
print_ping_result(ping_result)
end
|
#print_ping_result(ping_result = { success: true }) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/objects/node/server/base.rb', line 171
def print_ping_result(ping_result = { success: true })
result = {
namespace => {
"connection" => ping_result[:success] ? "success" : "failed",
"ssh_config" => ssh_driver.pretty_config_details
}
}
unless ping_result[:success]
result[namespace]["error"] = ping_result[:error].message
end
colour = ping_result[:success] ? :green : :red
ap result, {
:color => {
hash: colour,
symbol: colour,
string: colour,
keyword: colour,
variable: colour,
array: colour
}
}
end
|
#pseudo_tty(command) ⇒ Object
136
137
138
139
140
141
|
# File 'lib/objects/node/server/base.rb', line 136
def pseudo_tty(command)
as_pseudo_tty = true
ssh_cmd = ssh_driver.ssh_command(as_pseudo_tty)
tty_command = "#{ssh_cmd} '#{command}'"
execute_local(tty_command)
end
|
#put(local_path, remote_path) ⇒ Object
152
153
154
|
# File 'lib/objects/node/server/base.rb', line 152
def put(local_path, remote_path)
ssh_driver.put(local_path, remote_path)
end
|
#requires_description? ⇒ Boolean
76
77
78
|
# File 'lib/objects/node/server/base.rb', line 76
def requires_description?
false
end
|
#requires_type? ⇒ Boolean
80
81
82
|
# File 'lib/objects/node/server/base.rb', line 80
def requires_type?
false
end
|
#rsync(local_path, remote_path) ⇒ Object
148
149
150
|
# File 'lib/objects/node/server/base.rb', line 148
def rsync(local_path, remote_path)
ssh_driver.rsync(local_path, remote_path)
end
|
#run(*raw_commands) ⇒ Object
226
227
228
229
230
|
# File 'lib/objects/node/server/base.rb', line 226
def run(*raw_commands)
raise ::Bcome::Exception::MethodInvocationRequiresParameter.new "Please specify commands when invoking 'run'" if raw_commands.empty?
commands = do_run(raw_commands)
commands
end
|
#server? ⇒ Boolean
72
73
74
|
# File 'lib/objects/node/server/base.rb', line 72
def server?
true
end
|
#set_view_attributes ⇒ Object
override a server namespace’s parameters. This enables features such as specific SSH parameters for a specific server, e.g. my use case was a single debian box within an ubuntu network, where I needed to access the machine bootstrapping mode with the ‘admin’ rather ‘ubuntu’ username.
15
16
17
18
19
20
21
22
|
# File 'lib/objects/node/server/base.rb', line 15
def set_view_attributes
super
overridden_attributes = ::Bcome::Node::Factory.instance.machines_data_for_namespace(namespace.to_sym)
overridden_attributes.each do |override_key, override_value|
instance_variable_name = "@#{override_key}"
instance_variable_set(instance_variable_name, override_value)
end
end
|
#ssh ⇒ Object
132
133
134
|
# File 'lib/objects/node/server/base.rb', line 132
def ssh
ssh_driver.do_ssh
end
|
#static_server? ⇒ Boolean
236
237
238
|
# File 'lib/objects/node/server/base.rb', line 236
def static_server?
false
end
|
43
44
45
|
# File 'lib/objects/node/server/base.rb', line 43
def tags
data_print_from_hash(cloud_tags.data, "Tags")
end
|
#toggle_bootstrap(set_to = (@bootstrap ? false : true)) ⇒ Object
28
29
30
31
|
# File 'lib/objects/node/server/base.rb', line 28
def toggle_bootstrap(set_to = (@bootstrap ? false : true))
@bootstrap = set_to
puts "Bootstrap #{bootstrap? ? "on" : "off" } for #{namespace}".informational
end
|
#type ⇒ Object
64
65
66
|
# File 'lib/objects/node/server/base.rb', line 64
def type
"server"
end
|
#update_identifier(new_identifier) ⇒ Object
56
57
58
|
# File 'lib/objects/node/server/base.rb', line 56
def update_identifier(new_identifier)
@identifier = new_identifier
end
|
#update_parent(new_parent) ⇒ Object
39
40
41
|
# File 'lib/objects/node/server/base.rb', line 39
def update_parent(new_parent)
@parent = new_parent
end
|