Module: Management::Helper

Instance Method Summary collapse

Instance Method Details

#cloudObject



42
43
44
# File 'lib/management/helper.rb', line 42

def cloud
  @cloud ||= Fog::Compute.new(config[:cloud])
end

#configObject



38
39
40
# File 'lib/management/helper.rb', line 38

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

#get_address(name) ⇒ Object



28
29
30
31
32
# File 'lib/management/helper.rb', line 28

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



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

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



17
18
19
# File 'lib/management/helper.rb', line 17

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

#get_server(name) ⇒ Object



21
22
23
24
25
26
# File 'lib/management/helper.rb', line 21

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



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

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

#live_serversObject



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

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

#system_verbose(cmd) ⇒ Object



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

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