Module: Stem::Image

Extended by:
Image
Includes:
Util
Included in:
Image
Defined in:
lib/stem/image.rb

Instance Method Summary collapse

Methods included from Util

#get_filter_opts, #swirl, #tags_to_filter, #tagset_to_hash

Instance Method Details

#create(name, instance, tags = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/stem/image.rb', line 6

def create name, instance, tags = {}
  unless tags == {}
    raise Stem::Deprecated.new "Tags should be created separately due to AWS eventual consistency issues"
  end
  swirl.call("CreateImage", "Name" => name, "InstanceId" => instance)["imageId"]
end

#deregister(image) ⇒ Object



13
14
15
# File 'lib/stem/image.rb', line 13

def deregister image
  swirl.call("DeregisterImage", "ImageId" => image)["return"]
end

#describe(image) ⇒ Object



48
49
50
51
52
53
# File 'lib/stem/image.rb', line 48

def describe image
  swirl.call("DescribeImages", "ImageId" => image)["imagesSet"][0]
rescue Swirl::InvalidRequest => e
  raise e unless e.message =~ /does not exist/
  nil
end

#describe_tagged(tags) ⇒ Object



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

def describe_tagged tags
  opts = tags_to_filter(tags).merge("Owner" => "self")
  images = swirl.call("DescribeImages", opts)["imagesSet"]
  if images
    images.each {|image| image["tags"] = tagset_to_hash(image["tagSet"]) }
    images
  else
    []
  end
end

#listObject



17
18
19
20
21
22
# File 'lib/stem/image.rb', line 17

def list
  l = swirl.call("DescribeImages", "Owner" => "self")["imagesSet"] || []
  l.map do |i|
    i["imageId"]
  end
end

#named(name) ⇒ Object



24
25
26
27
28
# File 'lib/stem/image.rb', line 24

def named name
  opts = get_filter_opts("name" => name).merge("Owner" => "self")
  i = swirl.call("DescribeImages", opts)["imagesSet"].first
  i ? i["imageId"] : nil
end

#tagged(tags) ⇒ Object



30
31
32
33
34
35
# File 'lib/stem/image.rb', line 30

def tagged tags
  return if tags.empty?
  opts = tags_to_filter(tags).merge("Owner" => "self")
  res = swirl.call("DescribeImages", opts)['imagesSet']
  res ? res.map {|image| image['imageId'] } : []
end