Module: CapEC2::Utils

Included in:
EC2Handler, StatusTable
Defined in:
lib/cap-ec2/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.contact_point(instance) ⇒ Object



24
25
26
27
28
29
# File 'lib/cap-ec2/utils.rb', line 24

def self.contact_point(instance)
  ec2_interface = contact_point_mapping[fetch(:ec2_contact_point)]
  return instance.send(ec2_interface) if ec2_interface

  instance.public_dns_name || instance.public_ip_address || instance.private_ip_address
end

.contact_point_mappingObject



16
17
18
19
20
21
22
# File 'lib/cap-ec2/utils.rb', line 16

def self.contact_point_mapping
  {
    :public_dns => :public_dns_name,
    :public_ip => :public_ip_address,
    :private_ip => :private_ip_address
  }
end

Instance Method Details

#get_regions(regions_array = nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/cap-ec2/utils.rb', line 47

def get_regions(regions_array=nil)
  unless regions_array.nil? || regions_array.empty?
    return regions_array
  else
    @ec2 = ec2_connect
    @ec2.regions.map(&:name)
  end
end

#load_configObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cap-ec2/utils.rb', line 31

def load_config
  config_location = File.expand_path(fetch(:ec2_config), Dir.pwd) if fetch(:ec2_config)
  if config_location && File.exists?(config_location)
    config = YAML.load_file fetch(:ec2_config)
    if config
      set :ec2_project_tag, config['project_tag'] if config['project_tag']
      set :ec2_roles_tag, config['roles_tag'] if config['roles_tag']
      set :ec2_stages_tag, config['stages_tag'] if config['stages_tag']

      set :ec2_access_key_id, config['access_key_id'] if config['access_key_id']
      set :ec2_secret_access_key, config['secret_access_key'] if config['secret_access_key']
      set :ec2_region, config['regions'] if config['regions']
    end
  end
end

#project_tagObject



4
5
6
# File 'lib/cap-ec2/utils.rb', line 4

def project_tag
  fetch(:ec2_project_tag)
end

#roles_tagObject



8
9
10
# File 'lib/cap-ec2/utils.rb', line 8

def roles_tag
  fetch(:ec2_roles_tag)
end

#stages_tagObject



12
13
14
# File 'lib/cap-ec2/utils.rb', line 12

def stages_tag
  fetch(:ec2_stages_tag)
end