stem 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,5 +40,5 @@ You can, of course, delete the produced userdata.sh once the instance is launche
40
40
 
41
41
  ##Inspiration and Thanks
42
42
 
43
- Stem is almost entirely based on Orion Henry's Judo gem, and Blake Mizerany's work on variously patton, carealot, napkin, and several other experiments. Thanks also for feedback, testing and patches from Adam Wiggins, Mark McGranahan, Noah Zoschke, and Jason Dusek.
43
+ Stem is almost entirely based on Orion Henry's Judo gem, and Blake Mizerany's work on variously patton, carealot, napkin, and several other experiments. Thanks also for feedback, testing and patches from Adam Wiggins, Mark McGranahan, Noah Zoschke, Jason Dusek, and Blake Gentry.
44
44
 
data/lib/stem/image.rb CHANGED
@@ -3,7 +3,7 @@ module Stem
3
3
  include Util
4
4
  extend self
5
5
 
6
- def create name, instance, *tags
6
+ def create name, instance, tags
7
7
  raise "You already have an image named '#{name}'" if named(name)
8
8
  image_id = swirl.call("CreateImage", "Name" => name, "InstanceId" => instance)["imageId"]
9
9
  Tag::create(image_id, tags) unless tags.empty?
@@ -19,10 +19,9 @@ module Stem
19
19
  ami = i["imagesSet"].select {|m| m["name"] == name }.map { |m| m["imageId"] }.first
20
20
  end
21
21
 
22
- def tagged *tags
22
+ def tagged tags
23
23
  return if tags.empty?
24
- opts = { "tag-key" => tags.map {|t| t.to_s } }
25
- opts = get_filter_opts(opts).merge("Owner" => "self")
24
+ opts = tags_to_filter(tags).merge("Owner" => "self")
26
25
  swirl.call("DescribeImages", opts)['imagesSet'].map {|image| image['imageId'] }
27
26
  end
28
27
 
data/lib/stem/instance.rb CHANGED
@@ -14,7 +14,7 @@ module Stem
14
14
  throw "AMI named #{config["ami-name"]} was not found. (Does it need creating?)" unless ami
15
15
  elsif config["ami-tags"]
16
16
  ami = Image::tagged(config['ami-tags'])
17
- throw "AMI tagged with #{config['ami-tags'].join(', ')} was not found. (Does it need creating?)" unless ami
17
+ throw "AMI tagged with #{config['ami-tags'].inspect} was not found. (Does it need creating?)" unless ami
18
18
  end
19
19
  throw "No AMI specified." unless ami
20
20
 
data/lib/stem/tag.rb CHANGED
@@ -14,9 +14,12 @@ module Stem
14
14
  end
15
15
 
16
16
  def tag_opts(tags)
17
- if tags.is_a? Array
17
+ if tags.is_a? Hash
18
+ { "Tag.#.Key" => tags.keys.map(&:to_s),
19
+ "Tag.#.Value" => tags.values }
20
+ elsif tags.is_a? Array
18
21
  {
19
- "Tag.#.Key" => tags,
22
+ "Tag.#.Key" => tags.map(&:to_s),
20
23
  "Tag.#.Value" => (1..tags.size).map { '' }
21
24
  }
22
25
  else
@@ -25,4 +28,4 @@ module Stem
25
28
  end
26
29
 
27
30
  end
28
- end
31
+ end
data/lib/stem/util.rb CHANGED
@@ -7,7 +7,8 @@ module Stem
7
7
  if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
8
8
  {
9
9
  :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
10
- :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
10
+ :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
11
+ :version => "2010-08-31"
11
12
  }
12
13
  else
13
14
  account = account.to_sym
@@ -22,13 +23,23 @@ module Stem
22
23
  @swirl = Swirl::EC2.new config
23
24
  end
24
25
 
26
+ def tags_to_filter(tags)
27
+ if tags.is_a? Hash
28
+ get_filter_opts( tags.inject({}) {|h, (k, v)| h["tag:#{k}"] = v; h })
29
+ elsif tags.is_a? Array
30
+ get_filter_opts( { "tag-key" => tags.map(&:to_s) })
31
+ else
32
+ get_filter_opts( { "tag-key" => [tags.to_s] })
33
+ end
34
+ end
35
+
25
36
  def get_filter_opts(filters)
26
37
  opts = {}
27
- filters.each do |k, v|
28
- opts["Filter.1.Name"] = k
38
+ filters.each_with_index do |(k, v), n|
39
+ opts["Filter.#{n}.Name"] = k.to_s
29
40
  v = [ v ] unless v.is_a? Array
30
41
  v.each_with_index do |v, i|
31
- opts["Filter.1.Value.#{i}"] = v.to_s
42
+ opts["Filter.#{n}.Value.#{i}"] = v.to_s
32
43
  end
33
44
  end
34
45
  opts
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter van Hardenberg