Class: Hugo::Balancer

Inherits:
Object
  • Object
show all
Includes:
Mixin::ParamsValidate, Singleton
Defined in:
lib/hugo/balancer.rb

Constant Summary collapse

DEFAULT_ZONE =
'us-east-1c'
DEFAULT_PORT =
'8080'
DEFAULT_WEB =
'80'
DEFAULT_TYPE =
'http'
DEFAULT_SSL_PORT =
'8443'
DEFAULT_SSL_WEB =
'443'

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Constructor Details

#initializeBalancer

Returns a new instance of Balancer.



14
15
16
17
18
19
20
21
# File 'lib/hugo/balancer.rb', line 14

def initialize
  zone DEFAULT_ZONE
  port DEFAULT_PORT
  web DEFAULT_WEB
  ssl_port DEFAULT_SSL_PORT
  ssl_web DEFAULT_SSL_WEB
  type DEFAULT_TYPE
end

Instance Method Details

#aws_access_key_id(arg = nil) ⇒ Object

Aws Access Key for EC2 Deployment



97
98
99
# File 'lib/hugo/balancer.rb', line 97

def aws_access_key_id(arg=nil)
  set_or_return(:aws_access_key_id, arg, :kind_of => [String]) 
end

#aws_secret_access_key(arg = nil) ⇒ Object

Aws Access Secret Key for EC2 Deployment



102
103
104
# File 'lib/hugo/balancer.rb', line 102

def aws_secret_access_key(arg=nil)
  set_or_return(:aws_secret_access_key, arg, :kind_of => [String]) 
end

#deployObject

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hugo/balancer.rb', line 23

def deploy
  raise ArgumentError, "app.aws_access_key_id Required" unless aws_access_key_id
  raise ArgumentError, "app.aws_secret_access_key Required" unless aws_secret_access_key
  
  Hugo::Aws::Elb.find_or_create(:name => name,
                          :zones => zone,
                          :listeners => [{ :instance_port => port, :protocol =>"HTTP", :load_balancer_port => web}, 
                            { :instance_port => ssl_port, :protocol =>"TCP", :load_balancer_port => ssl_web}],
                            :aws_access_key_id => aws_access_key_id,
                            :aws_secret_access_key => aws_secret_access_key
  )
end

#helpObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hugo/balancer.rb', line 36

def help
  x = <<HELP

Hugo balancer 
-----------------

optional attributes
-----------------
zone - zone
port - app server port 
web - balancer port
ssl_port - ssl app server port
ssl_web - ssl balancer port
type - port type


defaults
-----------------
DEFAULT_ZONE = 'us-east-1c'
DEFAULT_PORT = '8080'
DEFAULT_WEB = '80'
DEFAULT_TYPE = 'http'
DEFAULT_SSL_PORT = '8443'
DEFAULT_SSL_WEB = '443'



HELP
  puts x
  x
end

#name(arg = nil) ⇒ Object



68
69
70
# File 'lib/hugo/balancer.rb', line 68

def name(arg=nil)
  set_or_return(:name, arg, :kind_of => [String])     
end

#port(arg = nil) ⇒ Object



76
77
78
# File 'lib/hugo/balancer.rb', line 76

def port(arg=nil)
  set_or_return(:port, arg, :kind_of => [String])     
end

#ssl_port(arg = nil) ⇒ Object



88
89
90
# File 'lib/hugo/balancer.rb', line 88

def ssl_port(arg=nil)
  set_or_return(:ssl_port, arg, :kind_of => [String])     
end

#ssl_web(arg = nil) ⇒ Object



92
93
94
# File 'lib/hugo/balancer.rb', line 92

def ssl_web(arg=nil)
  set_or_return(:ssl_web, arg, :kind_of => [String])     
end

#type(arg = nil) ⇒ Object



84
85
86
# File 'lib/hugo/balancer.rb', line 84

def type(arg=nil)
  set_or_return(:type, arg, :kind_of => [String])     
end

#web(arg = nil) ⇒ Object



80
81
82
# File 'lib/hugo/balancer.rb', line 80

def web(arg=nil)
  set_or_return(:web, arg, :kind_of => [String])     
end

#zone(arg = nil) ⇒ Object



72
73
74
# File 'lib/hugo/balancer.rb', line 72

def zone(arg=nil)
  set_or_return(:zone, arg, :kind_of => [String])     
end