lib/helpers/data.rb in gaptool-server-0.6.4 vs lib/helpers/data.rb in gaptool-server-0.6.6
- old
+ new
@@ -47,10 +47,15 @@
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.set_server_data_attributes(instance, attrs)
+ return if attrs.values.any? {|v| v.nil? || (v.is_a?(String) && v.empty?) || !!v == v}
+ $redis.hmset("instance:#{instance}", *attrs.flatten)
+ 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
@@ -149,20 +154,25 @@
if opts[:force_runlist] && rs['chef_runlist'].nil?
rs['chef_runlist'] = default_runlist
end
- rs['apps'] = apps_in_role(rs['role'])
rs.delete_if {|k,v| v.nil? || (!!v != v && v.empty?)}
+ rs['apps'] = apps_in_role(rs['role'])
+ rs
end
def self.save_role_data(role, data)
return if role.nil? || data.nil?
if data['amis']
amis = data.delete("amis") || {}
overwrite_hash("role:#{role}:amis", amis)
end
+ if data['sg']
+ sgs = data.delete("sg") || {}
+ overwrite_hash("role:#{role}:sg", sgs)
+ end
if data['apps']
apps = data.delete("apps") || []
apps.each {|a| add_app(a, role)}
end
overwrite_hash("role:#{role}", data)
@@ -171,18 +181,22 @@
def self.get_role_data(role)
res = $redis.hgetall("role:#{role}")
res['apps'] = apps_in_role(role)
res['amis'] = $redis.hgetall("role:#{role}:amis")
+ res['sg'] = $redis.hgetall("role:#{role}:sg")
res
end
def self.get_ami_for_role(role, region=nil)
-
$redis.hget("role:#{role}:amis", region) || $redis.hget("amis", region)
end
+ def self.get_sg_for_role(role, environment)
+ $redis.hget("role:#{role}:sg", environment) || "#{role}-#{environment}"
+ end
+
def self.get_runlist_for_role(role)
rl = $redis.hget("role:#{role}", "chef_runlist")
return nil if rl.nil?
rl = JSON.parse rl
return nil if rl == default_runlist
@@ -255,10 +269,10 @@
def self.apps_in_role(role)
$redis.smembers("role:#{role}:apps")
end
def self.stringify_apps(rs)
- unless rs['apps'].nil?
+ if !rs.nil? && !rs['apps'].nil?
rs['apps'] = rs['apps'].to_json
end
rs
end