skeme 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +202 -0
- data/NOTICE +12 -0
- data/README.rdoc +22 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/cloud_providers/aws.rb +61 -0
- data/lib/managers/rightscale.rb +110 -0
- data/lib/skeme.rb +66 -0
- data/skeme.gemspec +93 -0
- data/test/helper.rb +18 -0
- data/test/test_skeme.rb +7 -0
- metadata +194 -0
data/.document
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
# Add dependencies required to use your gem here.
|
|
3
|
+
# Example:
|
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
|
5
|
+
|
|
6
|
+
gem "right_aws", ">= 2.1.0"
|
|
7
|
+
gem "rest_connection", ">= 0.0.21"
|
|
8
|
+
|
|
9
|
+
# Add dependencies to develop your gem here.
|
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
|
11
|
+
group :development do
|
|
12
|
+
gem "shoulda", ">= 0"
|
|
13
|
+
gem "bundler", "~> 1.0.0"
|
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
|
15
|
+
gem "rcov", ">= 0"
|
|
16
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2011 Ryan J. Geyer
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright 2011 Ryan J. Geyer
|
|
2
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
you may not use this file except in compliance with the License.
|
|
4
|
+
You may obtain a copy of the License at
|
|
5
|
+
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
See the License for the specific language governing permissions and
|
|
12
|
+
limitations under the License.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
= skeme
|
|
2
|
+
|
|
3
|
+
Skeme is a library for tagging objects (server instances, storage volumes, etc). It is intended to allow tagging of the same resource in multiple systems simultaneously.
|
|
4
|
+
|
|
5
|
+
Currenly Skeme supports the following cloud providers and management tools. Also listed are which resources can be tagged for each provider or manager
|
|
6
|
+
+Cloud Providers+
|
|
7
|
+
* Amazon EC2
|
|
8
|
+
* Amazon EC2 Server Instance
|
|
9
|
+
* Amazon EC2 EBS Volume
|
|
10
|
+
* Amazon EC2 EBS Snapshot
|
|
11
|
+
|
|
12
|
+
+Cloud Management Tools+
|
|
13
|
+
* RightScale
|
|
14
|
+
* Amazon EC2 Server Instance
|
|
15
|
+
* Amazon EC2 EBS Volume
|
|
16
|
+
* Amazon EC2 EBS Snapshot
|
|
17
|
+
|
|
18
|
+
== Copyright
|
|
19
|
+
|
|
20
|
+
Copyright (c) 2011 Ryan Geyer. See LICENSE.txt for
|
|
21
|
+
further details.
|
|
22
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler'
|
|
3
|
+
begin
|
|
4
|
+
Bundler.setup(:default, :development)
|
|
5
|
+
rescue Bundler::BundlerError => e
|
|
6
|
+
$stderr.puts e.message
|
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
8
|
+
exit e.status_code
|
|
9
|
+
end
|
|
10
|
+
require 'rake'
|
|
11
|
+
|
|
12
|
+
require 'jeweler'
|
|
13
|
+
Jeweler::Tasks.new do |gem|
|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
15
|
+
gem.name = "skeme"
|
|
16
|
+
gem.homepage = "http://github.com/rgeyer/skeme"
|
|
17
|
+
gem.license = "Apache2"
|
|
18
|
+
gem.summary = %Q{A cloud management tagging library}
|
|
19
|
+
gem.description = IO.read(File.join(File.dirname(__FILE__), "README.rdoc"))
|
|
20
|
+
gem.email = "me@ryangeyer.com"
|
|
21
|
+
gem.authors = ["Ryan J. Geyer"]
|
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
|
26
|
+
end
|
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
28
|
+
|
|
29
|
+
require 'rake/testtask'
|
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
|
31
|
+
test.libs << 'lib' << 'test'
|
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
|
33
|
+
test.verbose = true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
require 'rcov/rcovtask'
|
|
37
|
+
Rcov::RcovTask.new do |test|
|
|
38
|
+
test.libs << 'test'
|
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
|
40
|
+
test.verbose = true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
task :default => :test
|
|
44
|
+
|
|
45
|
+
require 'rake/rdoctask'
|
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
48
|
+
|
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
50
|
+
rdoc.title = "skeme #{version}"
|
|
51
|
+
rdoc.rdoc_files.include('README*')
|
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
53
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.1
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright 2011 Ryan J. Geyer
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'right_aws'
|
|
15
|
+
|
|
16
|
+
module Skeme
|
|
17
|
+
module CloudProviders
|
|
18
|
+
class Aws
|
|
19
|
+
attr_accessor :logger, :ec2
|
|
20
|
+
|
|
21
|
+
def initialize(options={})
|
|
22
|
+
@logger = options[:logger]
|
|
23
|
+
if options[:aws_access_key_id] && options[:aws_secret_access_key]
|
|
24
|
+
@logger.info("AWS credentials supplied. EC2 Tagging Enabled.")
|
|
25
|
+
@ec2 = Rightscale::Ec2.new(options[:aws_access_key_id], options[:aws_secret_access_key], {:logger => options[:logger]})
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def set_tag(params={})
|
|
30
|
+
tag(params.merge({:action => "set"}))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unset_tag(params={})
|
|
34
|
+
tag(params.merge({:action => "unset"}))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def tag(params={})
|
|
40
|
+
if @ec2
|
|
41
|
+
tag = params[:ec2_tag] || params[:tag]
|
|
42
|
+
setting = params[:action] == "set"
|
|
43
|
+
|
|
44
|
+
taggable_resources = [:ec2_instance_id, :ec2_ebs_volume_id, :ec2_ebs_snapshot_id]
|
|
45
|
+
supplied_id_type = taggable_resources & params.keys
|
|
46
|
+
supplied_id_type.each do |resource_id_key|
|
|
47
|
+
resource_id = params[resource_id_key]
|
|
48
|
+
if setting
|
|
49
|
+
@logger.info("Tagging AWS resource id (#{resource_id}) with (#{tag})")
|
|
50
|
+
@ec2.create_tags(resource_id, [tag])
|
|
51
|
+
else
|
|
52
|
+
@logger.info("Removing tag (#{tag}) from AWS resource id (#{resource_id})")
|
|
53
|
+
@ec2.delete_tags(resource_id, [tag])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Copyright 2011 Ryan J. Geyer
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'rest_connection'
|
|
15
|
+
require 'yaml'
|
|
16
|
+
|
|
17
|
+
module Skeme
|
|
18
|
+
module Managers
|
|
19
|
+
class RightScale
|
|
20
|
+
attr_accessor :logger, :gotime
|
|
21
|
+
|
|
22
|
+
def initialize(options={})
|
|
23
|
+
@logger = options[:logger]
|
|
24
|
+
if options[:rs_email] && options[:rs_pass] && options[:rs_acct_num]
|
|
25
|
+
@logger.info("RightScale credentials supplied. RightScale Tagging Enabled.")
|
|
26
|
+
::RightScale::Api::BaseExtend.class_eval <<-EOF
|
|
27
|
+
@@connection ||= RestConnection::Connection.new
|
|
28
|
+
@@connection.settings = {
|
|
29
|
+
:user => "#{options[:rs_email]}",
|
|
30
|
+
:pass => "#{options[:rs_pass]}",
|
|
31
|
+
:api_url => "https://my.rightscale.com/api/acct/#{options[:rs_acct_num]}",
|
|
32
|
+
:common_headers => {
|
|
33
|
+
"X_API_VERSION" => "1.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
EOF
|
|
37
|
+
::RightScale::Api::Base.class_eval <<-EOF
|
|
38
|
+
@@connection ||= RestConnection::Connection.new
|
|
39
|
+
@@connection.settings = {
|
|
40
|
+
:user => "#{options[:rs_email]}",
|
|
41
|
+
:pass => "#{options[:rs_pass]}",
|
|
42
|
+
:api_url => "https://my.rightscale.com/api/acct/#{options[:rs_acct_num]}",
|
|
43
|
+
:common_headers => {
|
|
44
|
+
"X_API_VERSION" => "1.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
EOF
|
|
48
|
+
|
|
49
|
+
@gotime = true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def set_tag(params={})
|
|
54
|
+
tag(params.merge({:action => "set"}))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def unset_tag(params={})
|
|
58
|
+
tag(params.merge({:action => "unset"}))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def server_from_unique_id(ec2_instance_id, rs_tag_target)
|
|
64
|
+
# Prefer the target tag if we have it, because it's much more efficient
|
|
65
|
+
if rs_tag_target
|
|
66
|
+
instance = Tag.search('ec2_instance', rs_tag_target).first
|
|
67
|
+
server = Server.find(:first) { |s| instance["href"].start_with? s.href }
|
|
68
|
+
else
|
|
69
|
+
server = Server.find(:first) do |s|
|
|
70
|
+
# This makes an additional API call to get "settings". This process can get expensive in a very big hurry
|
|
71
|
+
# When RS API 1.5 is released, hopefully we'll have a better way to search for EC2 instances
|
|
72
|
+
s.settings['aws-id'] == ec2_instance_id
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
server
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def tag(params={})
|
|
79
|
+
if @gotime
|
|
80
|
+
tag = params[:rs_tag] || params[:tag]
|
|
81
|
+
setting = params[:action] == "set"
|
|
82
|
+
|
|
83
|
+
params.keys.each do |resource_id_key|
|
|
84
|
+
resource_href = nil
|
|
85
|
+
case resource_id_key
|
|
86
|
+
# This creates a condition where the instance is tagged twice if both ec2_instance_id and rs_tag_target are both provided.
|
|
87
|
+
# It's still less calls than iterating all of the servers for the aws-id though.
|
|
88
|
+
when :ec2_instance_id, :rs_tag_target
|
|
89
|
+
resource_href = server_from_unique_id(params[:ec2_instance_id], params[:rs_tag_target]).current_instance_href
|
|
90
|
+
when :ec2_ebs_volume_id
|
|
91
|
+
resource_href = Ec2EbsVolume.find(:first) { |vol| vol.aws_id == params[:ec2_ebs_volume_id] }.href
|
|
92
|
+
when :ec2_ebs_snapshot_id
|
|
93
|
+
resource_href = Ec2EbsSnapshot.find(:first) { |snap| snap.aws_id == params[:ec2_ebs_snapshot_id] }.href
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
if resource_href
|
|
97
|
+
if setting
|
|
98
|
+
Tag.set(resource_href, [tag])
|
|
99
|
+
else
|
|
100
|
+
Tag.unset(resource_href, [tag])
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
data/lib/skeme.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright 2011 Ryan J. Geyer
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'rubygems'
|
|
15
|
+
require 'cloud_providers/aws.rb'
|
|
16
|
+
require 'managers/rightscale.rb'
|
|
17
|
+
|
|
18
|
+
module Skeme
|
|
19
|
+
class Skeme
|
|
20
|
+
# Cloud providers
|
|
21
|
+
attr_accessor :cloud_providers
|
|
22
|
+
|
|
23
|
+
# Management tools
|
|
24
|
+
attr_accessor :managers
|
|
25
|
+
|
|
26
|
+
# Just useful internal bits
|
|
27
|
+
attr_accessor :logger
|
|
28
|
+
|
|
29
|
+
def initialize(options={})
|
|
30
|
+
@cloud_providers = []
|
|
31
|
+
@managers = []
|
|
32
|
+
|
|
33
|
+
if options[:logger]
|
|
34
|
+
@logger = options[:logger]
|
|
35
|
+
else
|
|
36
|
+
@logger = Logger.new(STDOUT)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
options[:logger] = @logger
|
|
40
|
+
|
|
41
|
+
cloud_providers << CloudProviders::Aws.new(options)
|
|
42
|
+
|
|
43
|
+
managers << Managers::RightScale.new(options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def set_tag(params={})
|
|
47
|
+
cloud_providers.each do |provider|
|
|
48
|
+
provider.set_tag(params)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
managers.each do |manager|
|
|
52
|
+
manager.set_tag(params)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def unset_tag(params={})
|
|
57
|
+
cloud_providers.each do |provider|
|
|
58
|
+
provider.unset_tag(params)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
managers.each do |manager|
|
|
62
|
+
manager.unset_tag(params)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/skeme.gemspec
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{skeme}
|
|
8
|
+
s.version = "0.0.1"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Ryan J. Geyer"]
|
|
12
|
+
s.date = %q{2011-05-26}
|
|
13
|
+
s.description = %q{= skeme
|
|
14
|
+
|
|
15
|
+
Skeme is a library for tagging objects (server instances, storage volumes, etc). It is intended to allow tagging of the same resource in multiple systems simultaneously.
|
|
16
|
+
|
|
17
|
+
Currenly Skeme supports the following cloud providers and management tools. Also listed are which resources can be tagged for each provider or manager
|
|
18
|
+
+Cloud Providers+
|
|
19
|
+
* Amazon EC2
|
|
20
|
+
* Amazon EC2 Server Instance
|
|
21
|
+
* Amazon EC2 EBS Volume
|
|
22
|
+
* Amazon EC2 EBS Snapshot
|
|
23
|
+
|
|
24
|
+
+Cloud Management Tools+
|
|
25
|
+
* RightScale
|
|
26
|
+
* Amazon EC2 Server Instance
|
|
27
|
+
* Amazon EC2 EBS Volume
|
|
28
|
+
* Amazon EC2 EBS Snapshot
|
|
29
|
+
|
|
30
|
+
== Copyright
|
|
31
|
+
|
|
32
|
+
Copyright (c) 2011 Ryan Geyer. See LICENSE.txt for
|
|
33
|
+
further details.
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
s.email = %q{me@ryangeyer.com}
|
|
37
|
+
s.extra_rdoc_files = [
|
|
38
|
+
"LICENSE.txt",
|
|
39
|
+
"README.rdoc"
|
|
40
|
+
]
|
|
41
|
+
s.files = [
|
|
42
|
+
".document",
|
|
43
|
+
"Gemfile",
|
|
44
|
+
"LICENSE.txt",
|
|
45
|
+
"NOTICE",
|
|
46
|
+
"README.rdoc",
|
|
47
|
+
"Rakefile",
|
|
48
|
+
"VERSION",
|
|
49
|
+
"lib/cloud_providers/aws.rb",
|
|
50
|
+
"lib/managers/rightscale.rb",
|
|
51
|
+
"lib/skeme.rb",
|
|
52
|
+
"skeme.gemspec",
|
|
53
|
+
"test/helper.rb",
|
|
54
|
+
"test/test_skeme.rb"
|
|
55
|
+
]
|
|
56
|
+
s.homepage = %q{http://github.com/rgeyer/skeme}
|
|
57
|
+
s.licenses = ["Apache2"]
|
|
58
|
+
s.require_paths = ["lib"]
|
|
59
|
+
s.rubygems_version = %q{1.5.2}
|
|
60
|
+
s.summary = %q{A cloud management tagging library}
|
|
61
|
+
s.test_files = [
|
|
62
|
+
"test/helper.rb",
|
|
63
|
+
"test/test_skeme.rb"
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
if s.respond_to? :specification_version then
|
|
67
|
+
s.specification_version = 3
|
|
68
|
+
|
|
69
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
70
|
+
s.add_runtime_dependency(%q<right_aws>, [">= 2.1.0"])
|
|
71
|
+
s.add_runtime_dependency(%q<rest_connection>, [">= 0.0.21"])
|
|
72
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
73
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
74
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
|
75
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
|
76
|
+
else
|
|
77
|
+
s.add_dependency(%q<right_aws>, [">= 2.1.0"])
|
|
78
|
+
s.add_dependency(%q<rest_connection>, [">= 0.0.21"])
|
|
79
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
|
82
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
|
83
|
+
end
|
|
84
|
+
else
|
|
85
|
+
s.add_dependency(%q<right_aws>, [">= 2.1.0"])
|
|
86
|
+
s.add_dependency(%q<rest_connection>, [">= 0.0.21"])
|
|
87
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
88
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
89
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
|
90
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler'
|
|
3
|
+
begin
|
|
4
|
+
Bundler.setup(:default, :development)
|
|
5
|
+
rescue Bundler::BundlerError => e
|
|
6
|
+
$stderr.puts e.message
|
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
8
|
+
exit e.status_code
|
|
9
|
+
end
|
|
10
|
+
require 'test/unit'
|
|
11
|
+
require 'shoulda'
|
|
12
|
+
|
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
15
|
+
require 'skeme'
|
|
16
|
+
|
|
17
|
+
class Test::Unit::TestCase
|
|
18
|
+
end
|
data/test/test_skeme.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: skeme
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Ryan J. Geyer
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2011-05-26 00:00:00 -07:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
prerelease: false
|
|
23
|
+
type: :runtime
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 11
|
|
30
|
+
segments:
|
|
31
|
+
- 2
|
|
32
|
+
- 1
|
|
33
|
+
- 0
|
|
34
|
+
version: 2.1.0
|
|
35
|
+
name: right_aws
|
|
36
|
+
version_requirements: *id001
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
prerelease: false
|
|
39
|
+
type: :runtime
|
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
hash: 53
|
|
46
|
+
segments:
|
|
47
|
+
- 0
|
|
48
|
+
- 0
|
|
49
|
+
- 21
|
|
50
|
+
version: 0.0.21
|
|
51
|
+
name: rest_connection
|
|
52
|
+
version_requirements: *id002
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
prerelease: false
|
|
55
|
+
type: :development
|
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
hash: 3
|
|
62
|
+
segments:
|
|
63
|
+
- 0
|
|
64
|
+
version: "0"
|
|
65
|
+
name: shoulda
|
|
66
|
+
version_requirements: *id003
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
prerelease: false
|
|
69
|
+
type: :development
|
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ~>
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
hash: 23
|
|
76
|
+
segments:
|
|
77
|
+
- 1
|
|
78
|
+
- 0
|
|
79
|
+
- 0
|
|
80
|
+
version: 1.0.0
|
|
81
|
+
name: bundler
|
|
82
|
+
version_requirements: *id004
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
prerelease: false
|
|
85
|
+
type: :development
|
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
87
|
+
none: false
|
|
88
|
+
requirements:
|
|
89
|
+
- - ~>
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
hash: 7
|
|
92
|
+
segments:
|
|
93
|
+
- 1
|
|
94
|
+
- 5
|
|
95
|
+
- 2
|
|
96
|
+
version: 1.5.2
|
|
97
|
+
name: jeweler
|
|
98
|
+
version_requirements: *id005
|
|
99
|
+
- !ruby/object:Gem::Dependency
|
|
100
|
+
prerelease: false
|
|
101
|
+
type: :development
|
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
|
103
|
+
none: false
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
hash: 3
|
|
108
|
+
segments:
|
|
109
|
+
- 0
|
|
110
|
+
version: "0"
|
|
111
|
+
name: rcov
|
|
112
|
+
version_requirements: *id006
|
|
113
|
+
description: |+
|
|
114
|
+
= skeme
|
|
115
|
+
|
|
116
|
+
Skeme is a library for tagging objects (server instances, storage volumes, etc). It is intended to allow tagging of the same resource in multiple systems simultaneously.
|
|
117
|
+
|
|
118
|
+
Currenly Skeme supports the following cloud providers and management tools. Also listed are which resources can be tagged for each provider or manager
|
|
119
|
+
+Cloud Providers+
|
|
120
|
+
* Amazon EC2
|
|
121
|
+
* Amazon EC2 Server Instance
|
|
122
|
+
* Amazon EC2 EBS Volume
|
|
123
|
+
* Amazon EC2 EBS Snapshot
|
|
124
|
+
|
|
125
|
+
+Cloud Management Tools+
|
|
126
|
+
* RightScale
|
|
127
|
+
* Amazon EC2 Server Instance
|
|
128
|
+
* Amazon EC2 EBS Volume
|
|
129
|
+
* Amazon EC2 EBS Snapshot
|
|
130
|
+
|
|
131
|
+
== Copyright
|
|
132
|
+
|
|
133
|
+
Copyright (c) 2011 Ryan Geyer. See LICENSE.txt for
|
|
134
|
+
further details.
|
|
135
|
+
|
|
136
|
+
email: me@ryangeyer.com
|
|
137
|
+
executables: []
|
|
138
|
+
|
|
139
|
+
extensions: []
|
|
140
|
+
|
|
141
|
+
extra_rdoc_files:
|
|
142
|
+
- LICENSE.txt
|
|
143
|
+
- README.rdoc
|
|
144
|
+
files:
|
|
145
|
+
- .document
|
|
146
|
+
- Gemfile
|
|
147
|
+
- LICENSE.txt
|
|
148
|
+
- NOTICE
|
|
149
|
+
- README.rdoc
|
|
150
|
+
- Rakefile
|
|
151
|
+
- VERSION
|
|
152
|
+
- lib/cloud_providers/aws.rb
|
|
153
|
+
- lib/managers/rightscale.rb
|
|
154
|
+
- lib/skeme.rb
|
|
155
|
+
- skeme.gemspec
|
|
156
|
+
- test/helper.rb
|
|
157
|
+
- test/test_skeme.rb
|
|
158
|
+
has_rdoc: true
|
|
159
|
+
homepage: http://github.com/rgeyer/skeme
|
|
160
|
+
licenses:
|
|
161
|
+
- Apache2
|
|
162
|
+
post_install_message:
|
|
163
|
+
rdoc_options: []
|
|
164
|
+
|
|
165
|
+
require_paths:
|
|
166
|
+
- lib
|
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
|
+
none: false
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
hash: 3
|
|
173
|
+
segments:
|
|
174
|
+
- 0
|
|
175
|
+
version: "0"
|
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
|
+
none: false
|
|
178
|
+
requirements:
|
|
179
|
+
- - ">="
|
|
180
|
+
- !ruby/object:Gem::Version
|
|
181
|
+
hash: 3
|
|
182
|
+
segments:
|
|
183
|
+
- 0
|
|
184
|
+
version: "0"
|
|
185
|
+
requirements: []
|
|
186
|
+
|
|
187
|
+
rubyforge_project:
|
|
188
|
+
rubygems_version: 1.5.2
|
|
189
|
+
signing_key:
|
|
190
|
+
specification_version: 3
|
|
191
|
+
summary: A cloud management tagging library
|
|
192
|
+
test_files:
|
|
193
|
+
- test/helper.rb
|
|
194
|
+
- test/test_skeme.rb
|