Class: Hugo::Cloud

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

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Constructor Details

#initializeCloud

Returns a new instance of Cloud.



8
9
10
# File 'lib/hugo/cloud.rb', line 8

def initialize

end

Instance Method Details

#app(name, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/hugo/cloud.rb', line 31

def app(name, &block)
  app_info = Hugo::App.instance
  app_info.name name
  app_info.lb lb
  app_info.db db
  #app_info.cloud_name name
  app_info.instance_eval(&block) if block_given? 
  cloud_app app_info
  
end

#balancer(&block) ⇒ Object



24
25
26
27
28
29
# File 'lib/hugo/cloud.rb', line 24

def balancer(&block)
  balancer = Hugo::Balancer.instance
  balancer.name name
  balancer.instance_eval(&block) if block_given? 
  lb balancer.deploy 
end

#cloud_app(arg = nil) ⇒ Object



125
126
127
# File 'lib/hugo/cloud.rb', line 125

def cloud_app(arg=nil)
  set_or_return(:cloud_app, arg, :kind_of => [Hugo::App])    
end

#database(db_name, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hugo/cloud.rb', line 12

def database(db_name, &block)    
  database = Hugo::Database.instance
  
  database.db_security_group name
  database.server name
  database.name db_name
  
  database.instance_eval(&block) if block_given? 
  db database.deploy 

end

#db(arg = nil) ⇒ Object



117
118
119
# File 'lib/hugo/cloud.rb', line 117

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

#deleteObject



57
58
59
60
61
62
# File 'lib/hugo/cloud.rb', line 57

def delete
  [cloud_app, lb].each do |s|
    s.destroy if s
  end
  db.rds.destroy
end

#deployObject



49
50
51
52
53
54
55
# File 'lib/hugo/cloud.rb', line 49

def deploy
  if cloud_app
    cloud_app.setup
    cloud_app.deploy
  end
  
end

#dns(hostname, &block) ⇒ Object



42
43
44
45
46
47
# File 'lib/hugo/cloud.rb', line 42

def dns(hostname, &block)
  dns_info = Hugo::Dns.instance
  dns_info.hostname hostname
  dns_info.instance_eval(&block) if block_given? 
  dns_info.deploy
end

#lb(arg = nil) ⇒ Object



121
122
123
# File 'lib/hugo/cloud.rb', line 121

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

#name(arg = nil) ⇒ Object



113
114
115
# File 'lib/hugo/cloud.rb', line 113

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


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/hugo/cloud.rb', line 66

def print
  if db
    puts <<REPORT
------------------------    
DATABASE: #{db.db}
User: #{db.user}
Password: #{db.password}
Uri: #{db.uri}
REPORT
  end
  
  if lb
    puts <<REPORT
-----------------------  
Balancer: #{lb.name}
Uri: #{lb.uri}
Servers: #{lb.instances.length}
REPORT

    lb.instances.each do |i|
      ec2 = Hugo::Aws::Ec2.find(i)
      puts <<REPORT
-----------------------      
Id: #{ec2.name}
Uri: #{ec2.uri}
Type: #{ec2.type}
Zone: #{ec2.zone}

REPORT
    end
  else
    ec2 = Hugo::Aws::Ec2.find(cloud_app.instance)
    puts <<REPORT

Since you are not running a balancer
you need to remember to add #{ec2.name} as the instance method in your app
-----------------------      
Id: #{ec2.name}
Uri: #{ec2.uri}
Type: #{ec2.type}
Zone: #{ec2.zone}
    
REPORT
  end

end