Class: GV::Addons::Postgresql

Inherits:
Valley::Addon show all
Defined in:
lib/gv/addons/postgresql.rb

Constant Summary collapse

PORT =
5432
CONTAINER_DIR =
"/var/lib/postgresql/9.3/main"

Instance Attribute Summary

Attributes inherited from Valley::Addon

#cmd

Instance Method Summary collapse

Methods inherited from Valley::Addon

#info, #initialize, #port

Constructor Details

This class inherits a constructor from GV::Valley::Addon

Instance Method Details

#create(app_name) ⇒ Object



27
28
29
30
31
# File 'lib/gv/addons/postgresql.rb', line 27

def create app_name
  if super(app_name)
    self.class.space.write([@name.to_sym,@app_name,"postgres://#{@app_name}:#{@pass}@#{self.external_ip}:#{port(app_name)}/#{@app_name}",self.external_ip])    
  end
end

#destroy(app_name) ⇒ Object



33
34
35
36
37
# File 'lib/gv/addons/postgresql.rb', line 33

def destroy app_name
  super app_name
  tuple = [@name.to_sym,@app_name,nil,nil]
  (self.class.space.take(tuple,0) rescue nil) while (self.class.space.read(tuple,0) rescue nil)
end

#imageObject



12
# File 'lib/gv/addons/postgresql.rb', line 12

def image; "valley/postgresql" end

#paramsObject



14
15
16
17
18
19
20
# File 'lib/gv/addons/postgresql.rb', line 14

def params 
  ["-v #{@home}/#{@name}/#{@app_name}:#{CONTAINER_DIR} -w #{CONTAINER_DIR}",
    "-e POSTGRESQL_USER=#{@app_name}", 
    "-e POSTGRESQL_PASS=#{@pass=rand(2**64).to_s(36)}", 
    "-e POSTGRESQL_DB=#{@app_name}"
  ].join(" ")
end

#url(app_name) ⇒ Object



22
23
24
25
# File 'lib/gv/addons/postgresql.rb', line 22

def url app_name
  @app_name = app_name
  self.class.space.read([@name.to_sym,@app_name,nil,nil],0)[2] rescue nil
end