lib/vmpooler/api/helpers.rb in vmpooler-0.18.0 vs lib/vmpooler/api/helpers.rb in vmpooler-0.18.1

- old
+ new

@@ -11,16 +11,16 @@ end def valid_token?(backend) return false unless has_token? - backend.exists?('vmpooler__token__' + request.env['HTTP_X_AUTH_TOKEN']) ? true : false + backend.exists?("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}") ? true : false end def validate_token(backend) if valid_token?(backend) - backend.hset('vmpooler__token__' + request.env['HTTP_X_AUTH_TOKEN'], 'last', Time.now) + backend.hset("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'last', Time.now) return true end content_type :json @@ -116,12 +116,12 @@ def export_tags(backend, hostname, tags) backend.pipelined do tags.each_pair do |tag, value| next if value.nil? or value.empty? - backend.hset('vmpooler__vm__' + hostname, 'tag:' + tag, value) - backend.hset('vmpooler__tag__' + Date.today.to_s, hostname + ':' + tag, value) + backend.hset("vmpooler__vm__#{hostname}", "tag:#{tag}", value) + backend.hset("vmpooler__tag__#{Date.today}", "#{hostname}:#{tag}", value) end end end def filter_tags(tags) @@ -145,11 +145,11 @@ /^\d{4}-\d{2}-\d{2}$/ === date_str end def hostname_shorten(hostname, domain=nil) if domain && hostname =~ /^[\w-]+\.#{domain}$/ - hostname = hostname[/[^\.]+/] + hostname = hostname[/[^.]+/] end hostname end @@ -251,21 +251,19 @@ def get_tag_metrics(backend, date_str, opts = {}) opts = {:only => false}.merge(opts) tags = {} - backend.hgetall('vmpooler__tag__' + date_str).each do |key, value| + backend.hgetall("vmpooler__tag__#{date_str}").each do |key, value| hostname = 'unknown' tag = 'unknown' - if key =~ /\:/ + if key =~ /:/ hostname, tag = key.split(':', 2) end - if opts[:only] - next unless tag == opts[:only] - end + next if opts[:only] && tag != opts[:only] tags[tag] ||= {} tags[tag][value] ||= 0 tags[tag][value] += 1 @@ -319,23 +317,23 @@ count: { total: 0 } } - task[:count][:total] = backend.hlen('vmpooler__' + task_str + '__' + date_str).to_i + task[:count][:total] = backend.hlen("vmpooler__#{task_str}__#{date_str}").to_i if task[:count][:total] > 0 if opts[:bypool] == true task_times_bypool = {} task[:count][:pool] = {} task[:duration][:pool] = {} - backend.hgetall('vmpooler__' + task_str + '__' + date_str).each do |key, value| + backend.hgetall("vmpooler__#{task_str}__#{date_str}").each do |key, value| pool = 'unknown' hostname = 'unknown' - if key =~ /\:/ + if key =~ /:/ pool, hostname = key.split(':') else hostname = key end