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



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hugo/cloud.rb', line 36

def app(name, &block)
  app_info = Hugo::App.instance
  app_info.name name
  app_info.aws_access_key_id(aws_access_key_id) if aws_access_key_id 
  app_info.aws_secret_access_key(aws_secret_access_key) if aws_secret_access_key

  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

#aws_access_key_id(arg = nil) ⇒ Object

Aws Access Key for EC2 Deployment



136
137
138
# File 'lib/hugo/cloud.rb', line 136

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



141
142
143
# File 'lib/hugo/cloud.rb', line 141

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

#balancer(&block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/hugo/cloud.rb', line 26

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

#clearObject



65
66
67
68
69
# File 'lib/hugo/cloud.rb', line 65

def clear
  aws_access_key_id(nil) 
  aws_secret_access_key(nil)

end

#cloud_app(arg = nil) ⇒ Object



130
131
132
# File 'lib/hugo/cloud.rb', line 130

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
23
24
# 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.aws_access_key_id(aws_access_key_id) if aws_access_key_id 
  database.aws_secret_access_key(aws_secret_access_key) if aws_secret_access_key
  
  database.instance_eval(&block) if block_given? 
  db database.deploy 

end

#db(arg = nil) ⇒ Object



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

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

#deleteObject



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

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

#deployObject



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

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

#lb(arg = nil) ⇒ Object



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

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

#name(arg = nil) ⇒ Object



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

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


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
112
113
114
115
116
# File 'lib/hugo/cloud.rb', line 71

def print
  if db
    puts <<REPORT
------------------------    
DATABASE: #{db.info[:name]}
User: #{db.info[:user]}
Password: #{db.info[:password]}
Uri: #{db.info[: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, @aws_access_key_id, @aws_secret_access_key)
      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, @aws_access_key_id, @aws_secret_access_key)
    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