Module: Management::Helper

Instance Method Summary collapse

Instance Method Details

#cloudObject



39
40
41
42
43
# File 'lib/management/helper.rb', line 39

def cloud
  require 'fog'
  require_relative '../ext/fog'
  @cloud ||= Fog::Compute.new(config[:cloud])
end

#configObject



35
36
37
# File 'lib/management/helper.rb', line 35

def config
  @config ||= symbolize_keys!(raw_yaml)
end

#get_address(name) ⇒ Object



25
26
27
28
29
# File 'lib/management/helper.rb', line 25

def get_address(name)
  addresses = cloud.addresses
  ip = config[:addresses][name.to_sym] or invalid_selection "Invalid address: #{name}", config[:addresses].map(&:first)
  addresses.find{|a| a.public_ip == ip} or abort "Could not find an address with the IP #{ip} (#{name})"
end

#get_env(name) ⇒ Object



5
6
7
8
# File 'lib/management/helper.rb', line 5

def get_env(name)
  return nil if name.nil?
  config[:envs].include?(name) and name or invalid_selection "Invalid environment: #{name}", config[:envs]
end

#get_script(name) ⇒ Object



14
15
16
# File 'lib/management/helper.rb', line 14

def get_script(name)
  config[:scripts][name.to_sym] or invalid_selection "Invalid script: #{name}", config[:scripts].map(&:first)
end

#get_server(name) ⇒ Object



18
19
20
21
22
23
# File 'lib/management/helper.rb', line 18

def get_server(name)
  servers = live_servers
  server = servers.find{|server| server.name == name} or invalid_selection "Invalid server: #{name}", servers.map(&:name)
  server.username = config[:root_user] if server && config[:root_user]
  server
end

#get_type(name) ⇒ Object



10
11
12
# File 'lib/management/helper.rb', line 10

def get_type(name)
  config[:types][name.to_sym] or invalid_selection "Invalid type: #{name}", config[:types].map(&:first)
end

#live_serversObject



31
32
33
# File 'lib/management/helper.rb', line 31

def live_servers
  cloud.servers.reject{ |s| s.state == 'terminated' || s.state == 'shutting-down' }
end

#system_verbose(cmd) ⇒ Object



45
46
47
48
# File 'lib/management/helper.rb', line 45

def system_verbose(cmd)
  puts "############ Running: #{cmd}"
  system cmd
end