Class: Bcome::Stack::Instance

Inherits:
Base show all
Includes:
BecomeObject, Functions, InstanceCommand
Defined in:
lib/stack/instance.rb

Constant Summary

Constants included from Functions

Functions::CONFIGS_PATH

Constants included from BecomeObject

BecomeObject::CONFIGS_PATH

Constants included from Orchestrator::Registry

Orchestrator::Registry::CONFIGS_PATH

Constants included from ContextFunctions

ContextFunctions::CONFIGS_PATH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstanceCommand

#direct_rsync, #direct_rsync_bootstrap, #execute_command, #jump_host_rsync, #jump_host_rsync_bootstrap, #rsync_is_sudo

Methods included from Functions

#F, #cmd_config_path, #cmd_for_ref, #cmd_functions, #functions, #has_cmd_functions?, #has_functions_config?, #load_cmd_functions

Methods included from BecomeObject

#all_items, #become_identifier, #context_breadcrumb, #has_main_context?, #has_potential_resources?, #identifier_for, #is_stack_level_resource?, #list, #local_download_path, #main_context, #main_context=, #mini_list, #namespace, #previous_workspace_object, #previous_workspace_object=, #resource_for_identifier, #resource_identifiers, #resources

Methods inherited from Base

#available_resources_options_string, #become, #become_identifier, const_missing, #construct_node, #describe, #init, #interactive, #machines, #menu, #method_missing, #node, #recipes, #respond_to_bcome_context_method?, #workon

Methods included from Orchestrator::Registry

#config_for_registry, #do_load_recipes, #has_registry_config?, #load_recipe_registry, #recipe_registry, #registry_configs_path

Methods included from CommandHelper

#run_local

Methods included from ContextFunctions

#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

Constructor Details

#initialize(meta_data, parent) ⇒ Instance

Returns a new instance of Instance.



36
37
38
39
# File 'lib/stack/instance.rb', line 36

def initialize(, parent)
  @meta_data = 
  @environment = parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bcome::Stack::Base

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



34
35
36
# File 'lib/stack/instance.rb', line 34

def environment
  @environment
end

#meta_dataObject (readonly)

Returns the value of attribute meta_data.



34
35
36
# File 'lib/stack/instance.rb', line 34

def 
  @meta_data
end

Class Method Details

.collection_from_config(parent, configuration) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/stack/instance.rb', line 24

def collection_from_config(parent, configuration)
  conf_for_env = configuration[:instances]
  collection = []
  conf_for_env.each do ||
    collection << new(, parent) 
  end
  return collection
end

.collection_from_fog_data(parent, fog_instances) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stack/instance.rb', line 9

def collection_from_fog_data(parent, fog_instances)
  collection = []
  fog_instances.each do |f_instance|

     = {
      :identifier => f_instance.tags["Name"],
      :external_network_interface_address => f_instance.private_ip_address,
      :public_ip_address => f_instance.public_ip_address,
      :role => f_instance.tags["function"]
    }
    collection << new(, parent)
  end
  return collection
end

Instance Method Details

#child_reference_keyObject



102
103
104
# File 'lib/stack/instance.rb', line 102

def child_reference_key
  :instance
end

#do_describeObject



110
111
112
113
114
115
116
117
118
# File 'lib/stack/instance.rb', line 110

def do_describe
  description = "\tNode Id:".menu_item_cyan + "\s\s#{node.identifier.menu_item_yellow}"
  description += "\n\tsudo: ".menu_item_cyan + (is_sudo? ? "on".danger : "off" ) 
  description += "\n\t" + "Internal IP: ".menu_item_cyan + "#{@meta_data[:external_network_interface_address]}".menu_item_white
  description += "\n\t" + "External IP: ".menu_item_cyan + "#{node.public_ip_address}".menu_item_white if node.public_ip_address
  description += "\n\t" + "Role: ".menu_item_cyan + "#{node.role}".menu_item_white if node.role 
  description += "\n\n"
  return description    
end

#do_load_resourcesObject



49
50
51
# File 'lib/stack/instance.rb', line 49

def do_load_resources
  [self]
end

#get(*params) ⇒ Object



67
68
69
# File 'lib/stack/instance.rb', line 67

def get(*params)
  node.get(*params)
end

#has_sub_nodes?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/stack/instance.rb', line 45

def has_sub_nodes?
  return false
end

#highlight?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/stack/instance.rb', line 106

def highlight?
  @environment.object_in_selections?(self)
end

#identifierObject



41
42
43
# File 'lib/stack/instance.rb', line 41

def identifier
  node.identifier
end

#is_sudo?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/stack/instance.rb', line 90

def is_sudo?
  super || @environment.is_sudo?
end


71
72
73
74
75
76
77
78
79
80
# File 'lib/stack/instance.rb', line 71

def menu_items
  super + [
    { :command => "run", :description => "Execute a command.", :usage => "run 'command'" },
    { :command => "put", :description => "Copy files to remote (recursive - uses rsync)", :usage => "put 'local_path', 'remote_path'" },
    { :command => "get", :description => "Download from remote (recursive - uses rsync).", :usage => "get 'remote_path'"},
    { :command => "ssh", :description => "Initiate an SSH connection." },
    { :command => "sudo", :description => "Run 'get' and 'put' in sudo mode (assumes you have passwordless sudo setup)" },
    { :command => 'functions', :description => "List all available custom functions" }
  ]
end

#node_level_klassObject



120
121
122
# File 'lib/stack/instance.rb', line 120

def node_level_klass
  ::Bcome::Node::Instance
end

#platformObject



82
83
84
# File 'lib/stack/instance.rb', line 82

def platform
  @environment.platform
end

#put(*params) ⇒ Object



58
59
60
# File 'lib/stack/instance.rb', line 58

def put(*params)
  node.put(*params)
end

#reference_keyObject



98
99
100
# File 'lib/stack/instance.rb', line 98

def reference_key
  :instances
end

#responds_to_list?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/stack/instance.rb', line 94

def responds_to_list?
  false
end

#run(*params) ⇒ Object



62
63
64
65
# File 'lib/stack/instance.rb', line 62

def run(*params)
  node.run(*params)
  return
end

#sshObject

Commands



54
55
56
# File 'lib/stack/instance.rb', line 54

def ssh
  node.ssh
end

#sudoObject



86
87
88
# File 'lib/stack/instance.rb', line 86

def sudo 
  toggle_sudo
end