lib/helpers/data.rb in gaptool-server-0.6.0.beta1 vs lib/helpers/data.rb in gaptool-server-0.6.0
- old
+ new
@@ -42,10 +42,15 @@
$redis.hmset(key, *data.select{ |k,v| !v.nil? && ((v.is_a?(String) && !v.empty?) || !!v == v)}.flatten)
end
end
end
+ def self.set_server_data_attr(instance, attr, value)
+ return if value.nil? || (value.is_a?(String) && value.empty?) || !!value == value
+ $redis.hset("instance:#{instance}", attr, value)
+ end
+
def self.save_server_data(instance, data)
unless data['chef_runlist'].nil?
data['chef_runlist'] = [*data['chef_runlist']]
unless data['chef_runlist'].include? init_recipe
@@ -95,14 +100,29 @@
def self.get_config(key)
$redis.hget('config', key)
end
+ def self.ensure_config(key, default)
+ cur = get_config(key)
+ cur = set_config(key, default) if cur.nil? || cur.empty?
+ cur
+ end
+
def self.set_config(key, value)
$redis.hset('config', key, value)
+ value
end
+ def self.del_config(key)
+ $redis.hdel('config', key)
+ end
+
+ def self.get_all_configs
+ $redis.hgetall('config')
+ end
+
def self.get_server_data(instance, opts={})
rs = $redis.hgetall("instance:#{instance}")
return nil if rs.nil? || rs.empty?
rs['instance'] = instance
if !rs['chef_runlist'].nil? && !rs['chef_runlist'].empty?
@@ -231,9 +251,16 @@
$redis.smembers("apps")
end
def self.apps_in_role(role)
$redis.smembers("role:#{role}:apps")
+ end
+
+ def self.stringify_apps(rs)
+ unless rs['apps'].nil?
+ rs['apps'] = rs['apps'].to_json
+ end
+ rs
end
def self.useradd(user, key=nil)
key = SecureRandom.hex(64) unless key
$redis.hset('users', user, key)