Module: Stem::Util

Included in:
Family, Family::Member, Group, Image, Instance, Ip, KeyPair, Snapshot, Tag
Defined in:
lib/stem/util.rb

Instance Method Summary collapse

Instance Method Details

#get_filter_opts(filters) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stem/util.rb', line 35

def get_filter_opts(filters)
  opts = {}
  filters.keys.sort.each_with_index do |k, n|
    v = filters[k]
    opts["Filter.#{n}.Name"] = k.to_s
    v = [ v ] unless v.is_a? Array
    v.each_with_index do |v, i|
      opts["Filter.#{n}.Value.#{i}"] = v.to_s
    end
  end
  opts
end

#swirlObject



3
4
5
# File 'lib/stem/util.rb', line 3

def swirl
  @swirl ||= Swirl::AWS.new :ec2, load_config
end

#tags_to_filter(tags) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stem/util.rb', line 19

def tags_to_filter(tags)
  if tags.is_a? Hash
    tags = tags.inject({}) do |h, (k, v)|
      # this is really awful. how can i make this non-awful?
      k = "tag:#{k}" unless k.to_s == "architecture"
      h[k.to_s] = v
      h
    end
    get_filter_opts(tags)
  elsif tags.is_a? Array
    get_filter_opts( { "tag-key" => tags.map(&:to_s) })
  else
    get_filter_opts( { "tag-key" => [tags.to_s] })
  end
end

#tagset_to_hash(tagset) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stem/util.rb', line 7

def tagset_to_hash(tagset)
  if tagset.is_a?(Hash)
    {tagset["item"]["key"] => tagset["item"]["value"]}
  else
    tagset.inject({}) do |h,item|
      k, v = item["key"], item["value"]
      h[k] = v
      h
    end
  end
end