Class: BigBang::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/bigbang/provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Provider

Returns a new instance of Provider.



3
4
5
# File 'lib/bigbang/provider.rb', line 3

def initialize(config)
	@config = config
end

Instance Method Details

#aws_server_configObject



7
8
9
10
11
12
# File 'lib/bigbang/provider.rb', line 7

def aws_server_config
	{
		:access_key_id => @config.access_key_id, 
		:secret_access_key => @config.secret_key,
	}
end

#configured_zoneObject



39
40
41
# File 'lib/bigbang/provider.rb', line 39

def configured_zone
	dns.zones.find { |z| z.domain == @config.domain }
end

#create_dns(domain, value, type) ⇒ Object



43
44
45
46
47
48
# File 'lib/bigbang/provider.rb', line 43

def create_dns(domain, value, type)
		configured_zone.records.create(
				:value => value,
				:name => domain,
				:type => type)
end

#dnsObject



34
35
36
37
# File 'lib/bigbang/provider.rb', line 34

def dns
	return @dns unless @dns.nil?
	@dns = Fog::DNS.new(@config.dns_opts)
end

#ec2Object



24
25
26
27
# File 'lib/bigbang/provider.rb', line 24

def ec2
	return @ec2 unless @ec2.nil?
	@ec2 = AWS::EC2::Base.new(ec2_server_config)
end

#ec2_server_configObject



19
20
21
22
# File 'lib/bigbang/provider.rb', line 19

def ec2_server_config
	aws_server_config.merge(
		:server => "ec2.#{@config.region}.amazonaws.com")
end

#eipsObject



50
51
52
53
54
55
56
57
# File 'lib/bigbang/provider.rb', line 50

def eips
	aset = ec2.describe_addresses.addressesSet
	if aset.nil?
		return []
	else
		return aset.item
	end
end

#elbObject



29
30
31
32
# File 'lib/bigbang/provider.rb', line 29

def elb
	return @elb unless @elb.nil?
	@elb = AWS::ELB::Base.new(elb_server_config)
end

#elb_server_configObject



14
15
16
17
# File 'lib/bigbang/provider.rb', line 14

def elb_server_config
	aws_server_config.merge(
		:server => "elasticloadbalancing.#{@config.region}.amazonaws.com")
end

#free_eipsObject



59
60
61
# File 'lib/bigbang/provider.rb', line 59

def free_eips
	eips.find_all { |eip| eip.instanceId.nil? }
end