Module: RelevanceRails::Provision

Defined in:
lib/relevance_rails/provision.rb

Constant Summary collapse

CONFIG_FILE =
'config/ec2_instance.txt'

Class Method Summary collapse

Class Method Details

.create_ec2(name = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/relevance_rails/provision.rb', line 11

def self.create_ec2(name = nil)
  abort "Please provide a $NAME" unless name
  slushy = provision_ec2_instances(name)
  slushy.bootstrap
  tmpdir = Elzar.merge_and_create_temp_directory Rails.root.join('provision')
  slushy.converge tmpdir
  server = slushy.server
  puts "Server Instance: #{server.id}"
  puts "Server IP: #{server.public_ip_address}"
  server
end

.current_dnsObject



41
42
43
# File 'lib/relevance_rails/provision.rb', line 41

def self.current_dns
  puts current_server.reload.dns_name
end

.current_serverObject



45
46
47
# File 'lib/relevance_rails/provision.rb', line 45

def self.current_server
  fog_connection.servers.get(instance_id)
end

.destroy_ec2Object



31
32
33
34
35
36
37
38
39
# File 'lib/relevance_rails/provision.rb', line 31

def self.destroy_ec2
  return unless (ENV["FORCE"] == "true") || Thor::Shell::Basic.new.yes?("Are you sure you want to destroy EC2 instance #{instance_id}?")
  puts "Destroying EC2 instance #{instance_id}..."
  slushy = Slushy::Instance.new(fog_connection, instance_id)
  slushy.terminate
  puts "Removing #{CONFIG_FILE}..."
  File.delete(CONFIG_FILE)
  puts "Done!"
end

.private_keyObject



49
50
51
# File 'lib/relevance_rails/provision.rb', line 49

def self.private_key
  config['server']['private_key']
end

.stop_ec2Object



23
24
25
26
27
28
29
# File 'lib/relevance_rails/provision.rb', line 23

def self.stop_ec2
  return unless (ENV["FORCE"] == "true") || Thor::Shell::Basic.new.yes?("Are you sure you want to shut down EC2 instance #{instance_id}?")
  puts "Shutting down EC2 instance #{instance_id}..."
  slushy = Slushy::Instance.new(fog_connection, instance_id)
  slushy.stop
  puts "Done!"
end