Class: Rprov::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rprov/config.rb

Constant Summary collapse

STARTING_PORT =
10_000
DEFAULTS =
{
  :appendfsync   => "everysec",
  :host          => "127.0.0.1",
  :vm_enabled    => "no",
  :vm_max_memory => 0,
  :paranoid      => false
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Config

Returns a new instance of Config.



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

def initialize(key)
  @key = key

  @password, @port = redis.hmget(:password, :port)

  DEFAULTS.each do |key, value|
    send("%s=" % key, redis.hget(key) || value)
  end
rescue Errno::ECONNREFUSED
  raise Errno::ECONNREFUSED, "You need to setup a master redis server."
end

Instance Attribute Details

#appendfsyncObject

Returns the value of attribute appendfsync.



20
21
22
# File 'lib/rprov/config.rb', line 20

def appendfsync
  @appendfsync
end

#hostObject

Returns the value of attribute host.



19
20
21
# File 'lib/rprov/config.rb', line 19

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/rprov/config.rb', line 13

def key
  @key
end

#paranoidObject

Returns the value of attribute paranoid.



16
17
18
# File 'lib/rprov/config.rb', line 16

def paranoid
  @paranoid
end

#passwordObject (readonly)

Returns the value of attribute password.



14
15
16
# File 'lib/rprov/config.rb', line 14

def password
  @password
end

#pathObject

Returns the value of attribute path.



17
18
19
# File 'lib/rprov/config.rb', line 17

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/rprov/config.rb', line 15

def port
  @port
end

#vm_enabledObject

Returns the value of attribute vm_enabled.



21
22
23
# File 'lib/rprov/config.rb', line 21

def vm_enabled
  @vm_enabled
end

#vm_max_memoryObject

Returns the value of attribute vm_max_memory.



22
23
24
# File 'lib/rprov/config.rb', line 22

def vm_max_memory
  @vm_max_memory
end

Class Method Details

.generate(key = gen_key) ⇒ Object



65
66
67
68
69
# File 'lib/rprov/config.rb', line 65

def self.generate(key = gen_key)
  redis[key].hmset(:port, gen_port, :password, random_string)

  return new(key)
end

.random_stringObject



71
72
73
# File 'lib/rprov/config.rb', line 71

def self.random_string
  Digest::SHA1.hexdigest(uuid + Time.now.to_f.to_s)
end

.redisObject



75
76
77
# File 'lib/rprov/config.rb', line 75

def self.redis
  @redis ||= Nest.new(:rprov)[:config]
end

Instance Method Details

#config_cmdObject



58
# File 'lib/rprov/config.rb', line 58

def config_cmd()   redis.hget(:config_cmd) || :config end

#memory=(memory) ⇒ Object



36
37
38
39
# File 'lib/rprov/config.rb', line 36

def memory=(memory)
  self.vm_max_memory = memory
  self.vm_enabled = "yes"
end

#redis_confObject



61
62
63
# File 'lib/rprov/config.rb', line 61

def redis_conf
  redis_conf_erb.result(binding)
end

#shutdown_cmdObject



59
# File 'lib/rprov/config.rb', line 59

def shutdown_cmd() redis.hget(:shutdown_cmd) || :shutdown end

#urlObject



45
46
47
# File 'lib/rprov/config.rb', line 45

def url
  "redis://:#{password}@#{host}:#{port}"
end