Class: Bcome::Stack::Environment

Inherits:
Object
  • Object
show all
Includes:
BecomeObject, EnvironmentSSH, FogHelper, Bcome::Selections
Defined in:
lib/stack/environment.rb

Constant Summary

Constants included from BecomeObject

BecomeObject::CONFIGS_PATH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnvironmentSSH

#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

Methods included from Bcome::Selections

#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

Methods included from BecomeObject

#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(, parent)
   = 
  @identifier = [:environment]
  @platform = parent
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



19
20
21
# File 'lib/stack/environment.rb', line 19

def identifier
  @identifier
end

#meta_dataObject (readonly)

Returns the value of attribute meta_data.



19
20
21
# File 'lib/stack/environment.rb', line 19

def 
  
end

#platformObject (readonly)

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 ||
    collection << new(, parent) if [:network].to_s == parent.identifier.to_s 
  end
  return collection
end

Instance Method Details

#bastion_ip_addressObject



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 = [: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_serverObject



40
41
42
# File 'lib/stack/environment.rb', line 40

def bastion_server
  resources.select{|resource| resource.identifier == [:ssh_mode][:jump_host_identifier] }.first
end

#collection_keyObject



112
113
114
# File 'lib/stack/environment.rb', line 112

def collection_key
  :instances
end

#collection_klassObject



104
105
106
# File 'lib/stack/environment.rb', line 104

def collection_klass
  ::INSTANCE_STACK_KLASS
end

#config_pathObject



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

def config_path
  "#{CONFIGS_PATH}/static_instances/#{platform.identifier}_#{identifier}-instances.yml"
end

#do_describeObject



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_resourcesObject



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

Returns:

  • (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 menu_items
  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_lookupObject



68
69
70
71
# File 'lib/stack/environment.rb', line 68

def network_lookup
  raise "Missing network lookup in networks_environment configuration".failure unless [:network_lookup]
  return [:network_lookup]
end

#network_lookup_typeObject



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_keyObject



108
109
110
# File 'lib/stack/environment.rb', line 108

def reference_key
  :environments
end

#ssh_mode_typeObject



44
45
46
47
48
# File 'lib/stack/environment.rb', line 44

def ssh_mode_type
  ssh_mode_type = [: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 [:ssh_mode][:type]
end

#ssh_mode_userObject



50
51
52
# File 'lib/stack/environment.rb', line 50

def ssh_mode_user
  return [:ssh_mode][:ssh_user]
end

#valid_ssh_modesObject



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

def valid_ssh_modes
  [::SSH_JUMP_MODE_IDENTIFIER, ::SSH_DIRECT_MODE_IDENTIFIER]
end