Class: Bcome::Stack::Environment
Constant Summary
Constants included
from Functions
Functions::CONFIGS_PATH
BecomeObject::CONFIGS_PATH
ContextFunctions::CONFIGS_PATH
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Functions
#F, #cmd_config_path, #cmd_for_ref, #cmd_functions, #functions, #has_cmd_functions?, #has_functions_config?, #load_cmd_functions
#bastion_ip_address, #bastion_server, #bootstrap_proxy_command, #execute_cmd, #execute_command, #execute_scp_download, #execute_scp_upload, #proxy, #proxy_command, #ssh_key_path, #ssh_mode_type, #ssh_mode_user, #ssh_nat_user, #ssh_user, #valid_ssh_modes
Methods included from FogHelper
#credentials_key, #ec2_tags, #filter_by_tags, #fog_client, #instance_matches_tags?, #servers, #unfiltered_servers
#add, #add!, #add_object, #clear!, #find_resource_by_identifier, #get, #in_resources?, #manage_object, #no_selections?, #no_selections_error, #object_in_selections?, #put, #remove, #remove_object, #run, #selections
#all_items, #become_identifier, #context_breadcrumb, #has_main_context?, #list, #local_download_path, #main_context, #main_context=, #namespace, #previous_workspace_object, #previous_workspace_object=, #resource_for_identifier, #resources, #responds_to_list?
Methods inherited from Base
#available_resources_options_string, #become, #become_identifier, #construct_node, #describe, #highlight?, #init, #machines, #menu, #method_missing, #node, #workon
#run_local
#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) ⇒ Environment
Returns a new instance of Environment.
22
23
24
25
26
|
# File 'lib/stack/environment.rb', line 22
def initialize(meta_data, parent)
@meta_data = meta_data
@identifier = meta_data[:environment]
@platform = parent
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Bcome::Stack::Base
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
20
21
22
|
# File 'lib/stack/environment.rb', line 20
def identifier
@identifier
end
|
Returns the value of attribute meta_data.
20
21
22
|
# File 'lib/stack/environment.rb', line 20
def meta_data
@meta_data
end
|
Returns the value of attribute platform.
20
21
22
|
# File 'lib/stack/environment.rb', line 20
def platform
@platform
end
|
Class Method Details
.collection_from_config(parent, configuration) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/stack/environment.rb', line 11
def collection_from_config(parent, configuration)
collection = []
configuration.each do |meta_data|
collection << new(meta_data, parent) if meta_data[:network].to_s == parent.identifier.to_s
end
return collection
end
|
Instance Method Details
#child_reference_key ⇒ Object
77
78
79
|
# File 'lib/stack/environment.rb', line 77
def child_reference_key
:environment
end
|
#collection_key ⇒ Object
81
82
83
|
# File 'lib/stack/environment.rb', line 81
def collection_key
:instances
end
|
#collection_klass ⇒ Object
69
70
71
|
# File 'lib/stack/environment.rb', line 69
def collection_klass
::INSTANCE_STACK_KLASS
end
|
#config_path ⇒ Object
58
59
60
|
# File 'lib/stack/environment.rb', line 58
def config_path
"#{CONFIGS_PATH}/static_instances/#{platform.identifier}_#{identifier}-instances.yml"
end
|
#do_describe ⇒ Object
62
63
64
65
66
67
|
# File 'lib/stack/environment.rb', line 62
def do_describe
desc = "\tNode Id:". + "\s#{node.identifier}". + "\n"
desc += "\tNet Lookup:". + "\s#{node.network_lookup_type}". + "\n"
desc += "\tSSH Mode:". + "\s#{node.ssh_mode_type}".
return desc + "\n\n"
end
|
#do_load_resources ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/stack/environment.rb', line 47
def do_load_resources
if dynamic_network_lookup?
return collection_klass.collection_from_fog_data(self, servers)
else
path = config_path
raise "Missing instances.yml configuration for your environment. You've selected a static network lookup, and yet I cannot find #{config_path}".failure unless File.exist?(config_path)
config = YAML.load_file(path)
return collection_klass.collection_from_config(self, config)
end
end
|
#dynamic_network_lookup? ⇒ Boolean
100
101
102
|
# File 'lib/stack/environment.rb', line 100
def dynamic_network_lookup?
return network_lookup_type == "dynamic"
end
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/stack/environment.rb', line 28
def
super + [
{ :command => "add", :description => "Add a resource you wish to work on.", :usage => "add 'identifier', OR add ['array', 'of', 'identifiers']" },
{ :command => "add!", :description => "Add all resources from the current context." },
{ :command => "remove", :description => "Remove a resource you no longer with to work on.", :usage => "remove 'identifier', OR remove ['array', 'of','identifiers']" },
{ :command => "clear!", :description => "Remove all selected resources." },
{ :command => "selections", :description => "Show all added resources." },
{ :command => "run", :description => "Execute a command on all selected resources", :usage => "run 'command'" },
{ :command => "get", :description => "Download from remote from all selected resources (recursive - uses rsync)", :usage => "get 'remote_path'" },
{ :command => "put", :description => "Copy files up to all selected resources (recursive - uses rsync)", :usage => "put 'local_path', 'remote_path'" },
{ :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
|
#network_lookup ⇒ Object
89
90
91
92
|
# File 'lib/stack/environment.rb', line 89
def network_lookup
raise "Missing network lookup in networks_environment configuration".failure unless @meta_data[:network_lookup]
return @meta_data[:network_lookup]
end
|
#network_lookup_type ⇒ Object
94
95
96
97
98
|
# File 'lib/stack/environment.rb', line 94
def network_lookup_type
type = network_lookup[:type]
raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
return type
end
|
#node_level_klass ⇒ Object
85
86
87
|
# File 'lib/stack/environment.rb', line 85
def node_level_klass
::Bcome::Node::Environment
end
|
#reference_key ⇒ Object
73
74
75
|
# File 'lib/stack/environment.rb', line 73
def reference_key
:environments
end
|
104
105
106
|
# File 'lib/stack/environment.rb', line 104
def sudo
toggle_sudo
end
|