Class: Hugo::App

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

Constant Summary collapse

AMI =
ENV['EC2_AMI_ID'] || 'ami-1515f67c'
ZONE =
"us-east-1c"
TYPE =
"m1.small"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Instance Attribute Details

#dnaObject

Returns the value of attribute dna.



12
13
14
# File 'lib/hugo/app.rb', line 12

def dna
  @dna
end

Instance Method Details

#add_recipe(name, options = nil) ⇒ Object

Dyanamically add recipes to your json



72
73
74
75
76
77
78
79
80
# File 'lib/hugo/app.rb', line 72

def add_recipe(name, options=nil)
  run_list [] if run_list.nil?
  run_list << "recipe[#{name}]"
  if options
    empty_hash = {}
    self.dna = {} if self.dna.nil?
    self.dna.merge!(options)
  end
end

#clearObject



63
64
65
66
67
68
# File 'lib/hugo/app.rb', line 63

def clear
  @key_name = nil
  @key_path = nil
  @cookbook = nil
  @run_list = nil
end

#cookbook(arg = nil) ⇒ Object



127
128
129
# File 'lib/hugo/app.rb', line 127

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

#db(arg = nil) ⇒ Object

Database Object



98
99
100
# File 'lib/hugo/app.rb', line 98

def db(arg=nil)
  set_or_return(:db, arg, :kind_of => [Hugo::Database]) 
end

#deployObject

deploy will run you json with chef-sole against your cookbooks

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
# File 'lib/hugo/app.rb', line 41

def deploy
  raise ArgumentError, "app.key_name Required" unless key_name
  raise ArgumentError, "app.key_path Required" unless key_path
  raise ArgumentError, "app.cookbook Required" unless cookbook
  raise ArgumentError, "app.run_list Required" unless run_list
  
  deploy_ec2
  #puts "Deploy Completed"    
end

#destroyObject

will kill all app servers



52
53
54
55
56
57
58
59
60
61
# File 'lib/hugo/app.rb', line 52

def destroy
  if lb
    lb.instances.each do |i|
      Hugo::Aws::Ec2.find(i).destroy
    end    
  else
    Hugo::Aws::Ec2.find(instance).destroy
  end
  
end

#helpObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/hugo/app.rb', line 140

def help
  x = <<HELP

Hugo app 
-----------------
There are two ways to run hugo app, a single instance mode, or 
with a balancer.  If you do not use a balancer, then after your 
initial run, which creates the server instance, you need to enter
the server instance into your config, so it will not create a new
ec2 everytime

Required attributes
-----------------
key_name
key_path
cookbook
run_list

Methods
------------------
servers

deploy

add_recipe

destroy

help

Optional Attributes
-----------------

instance
lb
db
uri
type
zone
image_id



HELP
  puts x
  x
end

#image_id(arg = nil) ⇒ Object



115
116
117
# File 'lib/hugo/app.rb', line 115

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

#instance(arg = nil) ⇒ Object

Set the instance if you only are deploying one server



83
84
85
# File 'lib/hugo/app.rb', line 83

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

#key_name(arg = nil) ⇒ Object



123
124
125
# File 'lib/hugo/app.rb', line 123

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

#key_path(arg = nil) ⇒ Object



131
132
133
# File 'lib/hugo/app.rb', line 131

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

#lb(arg = nil) ⇒ Object

Load Balancer Object



93
94
95
# File 'lib/hugo/app.rb', line 93

def lb(arg=nil)
  set_or_return(:lb, arg, :kind_of => [Hugo::Aws::Elb]) 
end

#name(arg = nil) ⇒ Object

Name of app - should relate to github repository



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

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

#run_list(arg = nil) ⇒ Object



135
136
137
# File 'lib/hugo/app.rb', line 135

def run_list(arg=nil)
  set_or_return(:run_list, arg, :kind_of => [Array])                
end

#security_group(arg = nil) ⇒ Object



119
120
121
# File 'lib/hugo/app.rb', line 119

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

#servers(instances = 1) ⇒ Object

How many servers do you want in your cloud This function will give and take away servers



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hugo/app.rb', line 16

def servers(instances=1)
  if lb
    if instances > lb.instances.length
      build_ec2(instances - lb.instances.length)
    elsif instances < lb.instances.length
      delete_ec2(lb.instances.length - instances)
    end    
  else
    instance(build_ec2(1)) unless instance
  end
end

#setupObject

Setup will install chef-solo on server instance



29
30
31
32
33
34
35
36
37
38
# File 'lib/hugo/app.rb', line 29

def setup
  if lb
    lb.instances.each do |i|
      setup_ec2(i)
    end
  else
    setup_ec2(instance)
  end
  # puts "Setup Completed"
end

#zone(arg = nil) ⇒ Object

def type(arg=nil)

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

end



111
112
113
# File 'lib/hugo/app.rb', line 111

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