class Bcome::Node::Server::Base

Attributes

origin_object_id[R]

Public Class Methods

new(*params) click to toggle source
Calls superclass method Bcome::Node::Base::new
# File lib/objects/node/server/base.rb, line 6
def initialize(*params)
  super
  # Set the object_id - sub inventories dup servers into new collections. This allows us to spot duplicates when interacting with collections
  @origin_object_id = object_id
end

Public Instance Methods

add_list_attributes(attrs) click to toggle source
# File lib/objects/node/server/base.rb, line 215
def add_list_attributes(attrs)
  @attribs = list_attributes.merge(attrs)
end
cache_data() click to toggle source
# File lib/objects/node/server/base.rb, line 238
def cache_data
  d = { identifier: @original_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() click to toggle source
# File lib/objects/node/server/base.rb, line 150
def close_ssh_connection
  ssh_driver.close_ssh_connection
end
cloud_tags() click to toggle source
# File lib/objects/node/server/base.rb, line 59
def cloud_tags
  @generated_tags ||= do_generate_cloud_tags
end
do_generate_cloud_tags() click to toggle source
# File lib/objects/node/server/base.rb, line 72
def do_generate_cloud_tags
  raise 'Should be overidden'
end
do_run(raw_commands) click to toggle source
# File lib/objects/node/server/base.rb, line 247
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(&:unset_node)
  commands
end
dup_with_new_parent(new_parent) click to toggle source
# File lib/objects/node/server/base.rb, line 41
def dup_with_new_parent(new_parent)
  new_node = clone
  new_node.update_parent(new_parent)
  new_node
end
dynamic_server?() click to toggle source
# File lib/objects/node/server/base.rb, line 280
def dynamic_server?
  !static_server?
end
enabled_menu_items() click to toggle source
Calls superclass method Bcome::Node::Base#enabled_menu_items
# File lib/objects/node/server/base.rb, line 96
def enabled_menu_items
  (super + %i[get ssh tags pseudo_tty tunnel]) - %i[workon enable disable enable! disable!]
end
execute_script(script_name) click to toggle source
# File lib/objects/node/server/base.rb, line 173
def execute_script(script_name)
  command_result = ::Bcome::Ssh::ScriptExec.execute(self, script_name)
  command_result
end
get(remote_path, local_path) click to toggle source
# File lib/objects/node/server/base.rb, line 190
def get(remote_path, local_path)
  ssh_driver.get(remote_path, local_path)
end
has_description?() click to toggle source
# File lib/objects/node/server/base.rb, line 272
def has_description?
  !description.nil?
end
has_no_ssh_connection?() click to toggle source
# File lib/objects/node/server/base.rb, line 158
def has_no_ssh_connection?
  !has_ssh_connection?
end
has_ssh_connection?() click to toggle source
# File lib/objects/node/server/base.rb, line 154
def has_ssh_connection?
  ssh_driver.has_open_ssh_con?
end
has_tagged_value?(key, values) click to toggle source
# File lib/objects/node/server/base.rb, line 63
def has_tagged_value?(key, values)
  matchers = { key: key, values: values }
  cloud_tags.has_key_and_value?(matchers)
end
host() click to toggle source
# File lib/objects/node/server/base.rb, line 16
def host
  raise 'Should be overidden'
end
is_same_machine?(other) click to toggle source
# File lib/objects/node/server/base.rb, line 12
def is_same_machine?(other)
  origin_object_id == other.origin_object_id
end
list_attributes() click to toggle source
# File lib/objects/node/server/base.rb, line 223
def list_attributes
  @attribs ||= set_list_attributes
end
local_network?() click to toggle source
# File lib/objects/node/server/base.rb, line 37
def local_network?
  defined?(local_network) && local_network
end
local_port_forward(start_port, end_port) click to toggle source
# File lib/objects/node/server/base.rb, line 135
def local_port_forward(start_port, end_port)
  ssh_driver.local_port_forward(start_port, end_port)
end
Also aliased as: tunnel
ls() click to toggle source
# File lib/objects/node/server/base.rb, line 194
def ls
  puts "\n" + visual_hierarchy.hierarchy + "\n"
  puts pretty_description
end
Also aliased as: lsa
lsa()
Alias for: ls
machines() click to toggle source
# File lib/objects/node/server/base.rb, line 80
def machines
  [self]
end
menu_items() click to toggle source
Calls superclass method Bcome::WorkspaceMenu#menu_items
open_ssh_connection(ping = false) click to toggle source
# File lib/objects/node/server/base.rb, line 146
def open_ssh_connection(ping = false)
  ssh_driver.ssh_connection(ping)
end
origin_namespace() click to toggle source
# File lib/objects/node/server/base.rb, line 219
def origin_namespace
  parent.namespace
end
ping() click to toggle source
# File lib/objects/node/server/base.rb, line 200
def ping
  ping_result = ssh_driver.ping
  print_ping_result(ping_result)
end
print_ping_result(ping_result = { success: true }) click to toggle source
pseudo_tty(command) click to toggle source
# File lib/objects/node/server/base.rb, line 166
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, *_params) click to toggle source
# File lib/objects/node/server/base.rb, line 182
def put(local_path, remote_path, *_params)
  ssh_driver.put(local_path, remote_path)
end
put_str(string, remote_path, *_params) click to toggle source
# File lib/objects/node/server/base.rb, line 186
def put_str(string, remote_path, *_params)
  ssh_driver.put_str(string, remote_path)
end
reopen_ssh_connection() click to toggle source
# File lib/objects/node/server/base.rb, line 140
def reopen_ssh_connection
  puts "Connecting\s".informational + identifier
  close_ssh_connection
  open_ssh_connection
end
requires_description?() click to toggle source
# File lib/objects/node/server/base.rb, line 88
def requires_description?
  false
end
requires_type?() click to toggle source
# File lib/objects/node/server/base.rb, line 92
def requires_type?
  false
end
rsync(local_path, remote_path) click to toggle source
# File lib/objects/node/server/base.rb, line 178
def rsync(local_path, remote_path)
  ssh_driver.rsync(local_path, remote_path)
end
run(*raw_commands) click to toggle source
# File lib/objects/node/server/base.rb, line 256
def run(*raw_commands)
  raise ::Bcome::Exception::MethodInvocationRequiresParameter, "Please specify commands when invoking 'run'" if raw_commands.empty?

  do_run(raw_commands)
rescue IOError, Errno::EBADF
  reopen_ssh_connection
  do_run(raw_commands)
rescue Exception => e
  if e.message == 'Unexpected spurious read wakeup'
    reopen_ssh_connection
    do_run(raw_commands)
  else
    raise e
  end
end
server?() click to toggle source
# File lib/objects/node/server/base.rb, line 84
def server?
  true
end
set_list_attributes() click to toggle source
# File lib/objects/node/server/base.rb, line 227
def set_list_attributes
  attribs = {
    "identifier": :identifier,
    "internal ip": :internal_ip_address,
    "public ip": :public_ip_address,
    "host": :host
  }

  attribs
end
set_network_configuration_overrides() click to toggle source

Override a server's namespace parameters. Enabled features such as specific SSH config for a particular server, i.e. overidding that of it's parent  inventory namespace.

# File lib/objects/node/server/base.rb, line 26
def set_network_configuration_overrides
  overridden_attributes = ::Bcome::Node::Factory.instance.machines_data_for_namespace(namespace.to_sym)
  overridden_attributes.each do |override_key, override_value|
    singleton_class.class_eval do
      define_method(override_key) do
        override_value
      end
    end
  end
end
set_view_attributes() click to toggle source
Calls superclass method Bcome::Node::Base#set_view_attributes
# File lib/objects/node/server/base.rb, line 20
def set_view_attributes
  super
end
ssh() click to toggle source
# File lib/objects/node/server/base.rb, line 162
def ssh
  ssh_driver.do_ssh
end
static_server?() click to toggle source
# File lib/objects/node/server/base.rb, line 276
def static_server?
  false
end
tags() click to toggle source
# File lib/objects/node/server/base.rb, line 51
def tags
  data_print_from_hash(cloud_tags.data, 'Tags')
end
tags_h() click to toggle source
# File lib/objects/node/server/base.rb, line 55
def tags_h
  cloud_tags.data
end
tunnel(start_port, end_port)
Alias for: local_port_forward
type() click to toggle source
# File lib/objects/node/server/base.rb, line 76
def type
  'server'
end
update_identifier(new_identifier) click to toggle source
# File lib/objects/node/server/base.rb, line 68
def update_identifier(new_identifier)
  @identifier = new_identifier
end
update_parent(new_parent) click to toggle source
# File lib/objects/node/server/base.rb, line 47
def update_parent(new_parent)
  @parent = new_parent
end