Class: Bcome::Stack::Environment
Constant Summary
BecomeObject::CONFIGS_PATH
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#execute_cmd, #execute_command, #execute_scp_upload, #proxy, #proxy_command
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, #in_resources?, #manage_object, #no_selections_error, #object_in_selections?, #remove, #remove_object, #rsync, #run, #scp, #selections
#all_items, #become_identifier, #has_main_context?, #list, #main_context, #main_context=, #previous_workspace_object, #previous_workspace_object=, #resource_for_identifier, #resources, #responds_to_list?
Constructor Details
#initialize(meta_data, parent) ⇒ Environment
Returns a new instance of Environment.
21
22
23
24
25
|
# File 'lib/stack/environment.rb', line 21
def initialize(meta_data, parent)
@meta_data = meta_data
@identifier = meta_data[:environment]
@platform = parent
end
|
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
19
20
21
|
# File 'lib/stack/environment.rb', line 19
def identifier
@identifier
end
|
Returns the value of attribute meta_data.
19
20
21
|
# File 'lib/stack/environment.rb', line 19
def meta_data
@meta_data
end
|
Returns the value of attribute platform.
19
20
21
|
# File 'lib/stack/environment.rb', line 19
def platform
@platform
end
|
Class Method Details
.collection_from_config(parent, configuration) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/stack/environment.rb', line 10
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
#bastion_ip_address ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/stack/environment.rb', line 58
def bastion_ip_address
if dynamic_network_lookup?
return bastion_server.public_ip_address
else
bastion_ip_address = @meta_data[:ssh_mode][:jump_host_ip_address]
raise "No jump_host_ip_address specified in your configuration.".failure unless bastion_ip_address
return bastion_ip_address
end
end
|
#bastion_server ⇒ Object
40
41
42
|
# File 'lib/stack/environment.rb', line 40
def bastion_server
resources.select{|resource| resource.identifier == @meta_data[:ssh_mode][:jump_host_identifier] }.first
end
|
#collection_key ⇒ Object
112
113
114
|
# File 'lib/stack/environment.rb', line 112
def collection_key
:instances
end
|
#collection_klass ⇒ Object
104
105
106
|
# File 'lib/stack/environment.rb', line 104
def collection_klass
::INSTANCE_STACK_KLASS
end
|
#config_path ⇒ Object
94
95
96
|
# File 'lib/stack/environment.rb', line 94
def config_path
"#{CONFIGS_PATH}/static_instances/#{platform.identifier}_#{identifier}-instances.yml"
end
|
#do_describe ⇒ Object
98
99
100
101
102
|
# File 'lib/stack/environment.rb', line 98
def do_describe
desc = "#{identifier}"
desc += "\t[ Net lookup: #{network_lookup_type}"
desc += "\t * SSH Mode: #{ssh_mode_type} ]"
end
|
#do_load_resources ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/stack/environment.rb', line 83
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
79
80
81
|
# File 'lib/stack/environment.rb', line 79
def dynamic_network_lookup?
return network_lookup_type == "dynamic"
end
|
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/stack/environment.rb', line 27
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 => "rsync", :description => "Rsync files to all selected resources.", :usage => "rsync 'localpath', 'remotepath'" },
{ :command => "run", :description => "Execute a command on all selected resources", :usage => "run 'command'" },
{ :command => "scp", :description => "SCP files up to all selected resources", :usage => "scp ['array','of', 'file', 'paths'], 'remote_path'" },
]
end
|
#network_lookup ⇒ Object
68
69
70
71
|
# File 'lib/stack/environment.rb', line 68
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
73
74
75
76
77
|
# File 'lib/stack/environment.rb', line 73
def network_lookup_type
type = network_lookup[:type]
raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
return type
end
|
#reference_key ⇒ Object
108
109
110
|
# File 'lib/stack/environment.rb', line 108
def reference_key
:environments
end
|
#ssh_mode_type ⇒ Object
44
45
46
47
48
|
# File 'lib/stack/environment.rb', line 44
def ssh_mode_type
ssh_mode_type = @meta_data[:ssh_mode][:type]
raise "Invalid ssh mode type #{ssh_mode_type}. Should be one of #{valid_ssh_modes.join(", ")}".failure unless valid_ssh_modes.include?(ssh_mode_type)
return @meta_data[:ssh_mode][:type]
end
|
#ssh_mode_user ⇒ Object
50
51
52
|
# File 'lib/stack/environment.rb', line 50
def ssh_mode_user
return @meta_data[:ssh_mode][:ssh_user]
end
|
#valid_ssh_modes ⇒ Object
54
55
56
|
# File 'lib/stack/environment.rb', line 54
def valid_ssh_modes
[::SSH_JUMP_MODE_IDENTIFIER, ::SSH_DIRECT_MODE_IDENTIFIER]
end
|