ktheory-right_aws 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,7 @@ lib/ec2/right_ec2_security_groups.rb
12
12
  lib/ec2/right_ec2_spot_instances.rb
13
13
  lib/ec2/right_ec2_ebs.rb
14
14
  lib/ec2/right_ec2_reserved_instances.rb
15
+ lib/ec2/right_ec2_tags.rb
15
16
  lib/ec2/right_ec2_vpc.rb
16
17
  lib/ec2/right_ec2_monitoring.rb
17
18
  lib/right_aws.rb
@@ -0,0 +1,132 @@
1
+ #
2
+ # Copyright (c) 2007-2009 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ module RightAws
25
+ class Ec2
26
+
27
+ #-----------------------------------------------------------------
28
+ # Tags
29
+ #-----------------------------------------------------------------
30
+
31
+ # Describe tags.
32
+ #
33
+ # ec2.describe_tags #=> [{:resource_id=>"i-12345678",
34
+ # :value=>"foo",
35
+ # :resource_type=>"instance",
36
+ # :key=>"myKey"}]
37
+ #
38
+ def describe_tags
39
+ link = generate_request("DescribeTags")
40
+ request_cache_or_info :describe_tags, link, QEc2DescribeTagsParser, @@bench
41
+ rescue Exception
42
+ on_exception
43
+ end
44
+
45
+ # Create tags.
46
+ #
47
+ # Add a single tag with no value to a resource:
48
+ # ec2.create_tags("i-12345678", "myKey") => true
49
+ #
50
+ # Add multiple keys and values to a resource:
51
+ # ec2.create_tags("i-12345678", [{"myKey1" => "foo",
52
+ # "myKey2" => "bar",
53
+ # "myKeyWithoutVal" => nil
54
+ # }]) #=> true
55
+ #
56
+ # Add a key and value to multiple resources:
57
+ # ec2.create_tags(["i-12345678","i-86fb3eec","i-86fb3eed"],
58
+ # {"myKey" => "foo"}) #=> true
59
+ #
60
+ def create_tags(resources, tags)
61
+ params = amazonize_list("ResourceId", resources)
62
+ params.merge! amazonize_tags(tags)
63
+ link = generate_request("CreateTags", params)
64
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
65
+ rescue Exception
66
+ on_exception
67
+ end
68
+
69
+ # Delete tags.
70
+ #
71
+ # Delete a tag from a resource regardless of value:
72
+ # ec2.delete_tags("i-12345678", "myKey") => true
73
+ #
74
+ # Delete multiple keys and values to a resource:
75
+ # ec2.delete_tags("i-12345678", [{"myKey1" => "foo",
76
+ # "myKey2" => "bar",
77
+ # "myKeyForAnyVal" => nil
78
+ # }]) #=> true
79
+ #
80
+ # Delete a key and value on multiple resources:
81
+ # ec2.delete_tags(["i-12345678","i-a1234567","i-b1234567"],
82
+ # {"myKey" => "foo"}) #=> true
83
+ #
84
+
85
+ def delete_tags(resources, tags)
86
+ params = amazonize_list("ResourceId", resources)
87
+ params.merge! amazonize_tags(tags, false)
88
+ link = generate_request("DeleteTags", params)
89
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
90
+ rescue Exception
91
+ on_exception
92
+ end
93
+
94
+ def amazonize_tags(tags,require_value=true) # :nodoc:
95
+ # NB: CreateTags requires Tag.n.Value, DeleteTags does not.
96
+ result = {}
97
+ Array(tags).each_with_index do |ary, idx|
98
+ key, value = ary
99
+ result["Tag.#{idx+1}.Key"] = key
100
+ result["Tag.#{idx+1}.Value"] = value.to_s if value || require_value
101
+ end
102
+ result
103
+ end
104
+
105
+
106
+ #-----------------------------------------------------------------
107
+ # PARSERS: Tags
108
+ #-----------------------------------------------------------------
109
+
110
+ class QEc2DescribeTagsParser < RightAWSParser #:nodoc:
111
+ def tagstart(name, attributes)
112
+ @resource_tag = {} if name == 'item'
113
+ end
114
+
115
+ def tagend(name)
116
+ case name
117
+ when 'resourceId' then @resource_tag[:resource_id] = @text
118
+ when 'resourceType' then @resource_tag[:resource_type] = @text
119
+ when 'key' then @resource_tag[:key] = @text
120
+ when 'value' then @resource_tag[:value] = @text
121
+ when 'item' then @result << @resource_tag
122
+ end
123
+ end
124
+
125
+ def reset
126
+ @result = []
127
+ end
128
+ end
129
+
130
+ end
131
+
132
+ end
@@ -68,7 +68,7 @@ module RightAws #:nodoc:
68
68
  module VERSION #:nodoc:
69
69
  MAJOR = 2 unless defined?(MAJOR)
70
70
  MINOR = 0 unless defined?(MINOR)
71
- TINY = 2 unless defined?(TINY)
71
+ TINY = 3 unless defined?(TINY)
72
72
 
73
73
  STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
74
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ktheory-right_aws
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 2
10
- version: 2.0.2
9
+ - 3
10
+ version: 2.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - RightScale, Inc.
@@ -109,6 +109,7 @@ files:
109
109
  - lib/ec2/right_ec2_spot_instances.rb
110
110
  - lib/ec2/right_ec2_ebs.rb
111
111
  - lib/ec2/right_ec2_reserved_instances.rb
112
+ - lib/ec2/right_ec2_tags.rb
112
113
  - lib/ec2/right_ec2_vpc.rb
113
114
  - lib/ec2/right_ec2_monitoring.rb
114
115
  - lib/right_aws.rb