right_link 5.9.0
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/actors/agent_manager.rb +88 -0
- data/actors/instance_scheduler.rb +321 -0
- data/actors/instance_services.rb +64 -0
- data/actors/instance_setup.rb +567 -0
- data/bin/cloud +25 -0
- data/bin/cook_runner +44 -0
- data/bin/deploy +120 -0
- data/bin/enroll +385 -0
- data/bin/rad +32 -0
- data/bin/rchk +29 -0
- data/bin/rnac +39 -0
- data/bin/rs_connect +33 -0
- data/bin/rs_log_level +31 -0
- data/bin/rs_ohai +28 -0
- data/bin/rs_reenroll +31 -0
- data/bin/rs_run_recipe +34 -0
- data/bin/rs_run_right_script +34 -0
- data/bin/rs_shutdown +33 -0
- data/bin/rs_tag +33 -0
- data/bin/rs_thunk +33 -0
- data/bin/rstat +31 -0
- data/bin/system +16 -0
- data/ext/Rakefile +18 -0
- data/init/config.yml +5 -0
- data/init/init.rb +79 -0
- data/lib/chef/ohai_setup.rb +51 -0
- data/lib/chef/plugins/cloud.rb +91 -0
- data/lib/chef/plugins/cloudstack.rb +23 -0
- data/lib/chef/plugins/ec2.rb +23 -0
- data/lib/chef/plugins/linux/block_device2.rb +24 -0
- data/lib/chef/plugins/rackspace.rb +23 -0
- data/lib/chef/plugins/rightscale.rb +125 -0
- data/lib/chef/plugins/windows/network.rb +114 -0
- data/lib/chef/plugins.rb +74 -0
- data/lib/chef/providers/dns_dnsmadeeasy_provider.rb +81 -0
- data/lib/chef/providers/dns_resource.rb +100 -0
- data/lib/chef/providers/executable_schedule_provider.rb +70 -0
- data/lib/chef/providers/executable_schedule_resource.rb +144 -0
- data/lib/chef/providers/remote_recipe_provider.rb +86 -0
- data/lib/chef/providers/remote_recipe_resource.rb +101 -0
- data/lib/chef/providers/right_link_tag_provider.rb +73 -0
- data/lib/chef/providers/right_link_tag_resource.rb +59 -0
- data/lib/chef/providers/right_script_provider.rb +190 -0
- data/lib/chef/providers/right_script_resource.rb +113 -0
- data/lib/chef/providers/rs_shutdown_provider.rb +75 -0
- data/lib/chef/providers/rs_shutdown_resource.rb +55 -0
- data/lib/chef/providers/server_collection_provider.rb +66 -0
- data/lib/chef/providers/server_collection_resource.rb +93 -0
- data/lib/chef/providers/windows/powershell_provider.rb +151 -0
- data/lib/chef/providers/windows/powershell_resource.rb +111 -0
- data/lib/chef/providers/windows/unsupported_provider.rb +51 -0
- data/lib/chef/right_providers.rb +55 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.csproj +104 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.dll-Help.xml +141 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Exceptions.cs +182 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionCommand.cs +178 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionRequest.cs +67 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionResponse.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueCommandBase.cs +142 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueRequestBase.cs +64 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueResponseBase.cs +69 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/JsonTransport.cs +110 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeClient.cs +158 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeServer.cs +142 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolConstants.cs +55 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolUtilities.cs +77 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ReadMe.txt +53 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeResponse.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceResponse.cs +40 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceResponse.cs +40 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueCommandBase.cs +293 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueRequestBase.cs +75 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueResponseBase.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Transport.cs +91 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet.sln +35 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Program.cs +374 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/TestChefNodeCmdlet.csproj +65 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Program.cs +136 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Properties/AssemblyInfo.cs +36 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/ReadMe.txt +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/TestNextActionCmdlet.csproj +68 -0
- data/lib/chef/windows/bin/Newtonsoft.Json.dll +0 -0
- data/lib/chef/windows/chef_node_server.rb +463 -0
- data/lib/chef/windows/dynamic_powershell_provider.rb +296 -0
- data/lib/chef/windows/pipe_server.rb +283 -0
- data/lib/chef/windows/powershell_host.rb +285 -0
- data/lib/chef/windows/powershell_pipe_server.rb +136 -0
- data/lib/chef/windows/powershell_provider_base.rb +92 -0
- data/lib/chef/windows/scripts/run_loop.ps1 +105 -0
- data/lib/clouds/cloud.rb +557 -0
- data/lib/clouds/cloud_factory.rb +250 -0
- data/lib/clouds/cloud_utilities.rb +244 -0
- data/lib/clouds/clouds/azure.rb +106 -0
- data/lib/clouds/clouds/cloudstack.rb +114 -0
- data/lib/clouds/clouds/ec2.rb +113 -0
- data/lib/clouds/clouds/eucalyptus.rb +46 -0
- data/lib/clouds/clouds/google.rb +102 -0
- data/lib/clouds/clouds/none.rb +76 -0
- data/lib/clouds/clouds/openstack.rb +30 -0
- data/lib/clouds/clouds/rackspace-ng.rb +54 -0
- data/lib/clouds/clouds/rackspace.rb +78 -0
- data/lib/clouds/clouds/softlayer.rb +91 -0
- data/lib/clouds/metadata_formatter.rb +108 -0
- data/lib/clouds/metadata_provider.rb +128 -0
- data/lib/clouds/metadata_source.rb +87 -0
- data/lib/clouds/metadata_sources/certificate_metadata_source.rb +207 -0
- data/lib/clouds/metadata_sources/config_drive_metadata_source.rb +129 -0
- data/lib/clouds/metadata_sources/file_metadata_source.rb +74 -0
- data/lib/clouds/metadata_sources/http_metadata_source.rb +277 -0
- data/lib/clouds/metadata_sources/selective_metadata_source.rb +122 -0
- data/lib/clouds/metadata_tree_climber.rb +144 -0
- data/lib/clouds/metadata_writer.rb +155 -0
- data/lib/clouds/metadata_writers/dictionary_metadata_writer.rb +72 -0
- data/lib/clouds/metadata_writers/ruby_metadata_writer.rb +76 -0
- data/lib/clouds/metadata_writers/shell_metadata_writer.rb +121 -0
- data/lib/clouds/register_clouds.rb +34 -0
- data/lib/clouds.rb +32 -0
- data/lib/gem_dependencies.rb +83 -0
- data/lib/git_hooks/commit-msg.rb +7 -0
- data/lib/instance/agent_config.rb +168 -0
- data/lib/instance/agent_watcher.rb +233 -0
- data/lib/instance/audit_cook_stub.rb +104 -0
- data/lib/instance/audit_proxy.rb +247 -0
- data/lib/instance/bundle_queue.rb +104 -0
- data/lib/instance/cook/agent_connection.rb +109 -0
- data/lib/instance/cook/audit_logger.rb +165 -0
- data/lib/instance/cook/audit_stub.rb +142 -0
- data/lib/instance/cook/ca-bundle.crt +2794 -0
- data/lib/instance/cook/chef_state.rb +211 -0
- data/lib/instance/cook/cook.rb +306 -0
- data/lib/instance/cook/cook_state.rb +298 -0
- data/lib/instance/cook/cookbook_path_mapping.rb +66 -0
- data/lib/instance/cook/cookbook_repo_retriever.rb +190 -0
- data/lib/instance/cook/executable_sequence.rb +765 -0
- data/lib/instance/cook/external_parameter_gatherer.rb +190 -0
- data/lib/instance/cook/repose_downloader.rb +349 -0
- data/lib/instance/cook/shutdown_request_proxy.rb +121 -0
- data/lib/instance/cook.rb +41 -0
- data/lib/instance/downloader.rb +208 -0
- data/lib/instance/duplicable.rb +67 -0
- data/lib/instance/exceptions.rb +49 -0
- data/lib/instance/executable_sequence_proxy.rb +278 -0
- data/lib/instance/instance_commands.rb +577 -0
- data/lib/instance/instance_state.rb +633 -0
- data/lib/instance/json_utilities.rb +102 -0
- data/lib/instance/login_manager.rb +533 -0
- data/lib/instance/login_user_manager.rb +522 -0
- data/lib/instance/message_encoder.rb +118 -0
- data/lib/instance/multi_thread_bundle_queue.rb +232 -0
- data/lib/instance/operation_context.rb +60 -0
- data/lib/instance/options_bag.rb +65 -0
- data/lib/instance/payload_formatter.rb +46 -0
- data/lib/instance/policy.rb +53 -0
- data/lib/instance/policy_audit.rb +100 -0
- data/lib/instance/policy_manager.rb +146 -0
- data/lib/instance/reenroll_manager.rb +104 -0
- data/lib/instance/right_scripts_cookbook.rb +181 -0
- data/lib/instance/shutdown_request.rb +221 -0
- data/lib/instance/single_thread_bundle_queue.rb +189 -0
- data/lib/instance/volume_management.rb +450 -0
- data/lib/instance.rb +50 -0
- data/lib/repo_conf_generators/apt_conf_generators.rb +106 -0
- data/lib/repo_conf_generators/gem_conf_generators.rb +80 -0
- data/lib/repo_conf_generators/rightscale_conf_generators.rb +254 -0
- data/lib/repo_conf_generators/rightscale_key.pub +17 -0
- data/lib/repo_conf_generators/yum_conf_generators.rb +225 -0
- data/lib/repo_conf_generators.rb +30 -0
- data/lib/run_shell.rb +28 -0
- data/scripts/agent_checker.rb +571 -0
- data/scripts/agent_controller.rb +247 -0
- data/scripts/agent_deployer.rb +148 -0
- data/scripts/bundle_runner.rb +336 -0
- data/scripts/cloud_controller.rb +176 -0
- data/scripts/log_level_manager.rb +142 -0
- data/scripts/ohai_runner.rb +33 -0
- data/scripts/reenroller.rb +193 -0
- data/scripts/server_importer.rb +293 -0
- data/scripts/shutdown_client.rb +183 -0
- data/scripts/system_configurator.rb +367 -0
- data/scripts/tagger.rb +381 -0
- data/scripts/thunker.rb +356 -0
- metadata +418 -0
data/scripts/tagger.rb
ADDED
@@ -0,0 +1,381 @@
|
|
1
|
+
# === Synopsis:
|
2
|
+
# RightScale Tagger (rs_tag) - (c) 2009-2012 RightScale Inc
|
3
|
+
#
|
4
|
+
# Tagger allows listing, adding and removing tags on the current instance and
|
5
|
+
# querying for all instances with a given set of tags
|
6
|
+
#
|
7
|
+
# === Examples:
|
8
|
+
# Retrieve all tags:
|
9
|
+
# rs_tag --list
|
10
|
+
# rs_tag -l
|
11
|
+
#
|
12
|
+
# Add tag 'a_tag' to instance:
|
13
|
+
# rs_tag --add a_tag
|
14
|
+
# rs_tag -a a_tag
|
15
|
+
#
|
16
|
+
# Remove tag 'a_tag':
|
17
|
+
# rs_tag --remove a_tag
|
18
|
+
# rs_tag -r a_tag
|
19
|
+
#
|
20
|
+
# Retrieve all instances with any of the tags in a set:
|
21
|
+
# rs_tag --query "a_tag b_tag"
|
22
|
+
# rs_tag -q "a_tag b_tag"
|
23
|
+
#
|
24
|
+
# === Usage
|
25
|
+
# rs_tag (--list, -l | --add, -a TAG | --remove, -r TAG | --query, -q TAG_LIST)
|
26
|
+
#
|
27
|
+
# Options:
|
28
|
+
# --list, -l List current server tags
|
29
|
+
# --add, -a TAG Add tag named TAG
|
30
|
+
# --remove, -r TAG Remove tag named TAG
|
31
|
+
# --query, -q TAG_LIST Query for all instances that have any of the tags in TAG_LIST
|
32
|
+
# with the TAG_LIST being quoted if it contains spaces
|
33
|
+
# --die, -e Exit with error if query/list fails
|
34
|
+
# --format, -f FMT Output format: json, yaml, text
|
35
|
+
# --verbose, -v Display debug information
|
36
|
+
# --help: Display help
|
37
|
+
# --version: Display version information
|
38
|
+
# --timeout, -t Custom timeout parameter (default 120 sec)
|
39
|
+
#
|
40
|
+
|
41
|
+
require 'rubygems'
|
42
|
+
require 'trollop'
|
43
|
+
require 'right_agent'
|
44
|
+
require 'right_agent/scripts/usage'
|
45
|
+
require 'right_agent/scripts/common_parser'
|
46
|
+
|
47
|
+
module RightScale
|
48
|
+
|
49
|
+
class Tagger
|
50
|
+
|
51
|
+
TAG_REQUEST_TIMEOUT = 2 * 60 # synchronous tag requests need a long timeout
|
52
|
+
|
53
|
+
class TagError < Exception
|
54
|
+
attr_reader :code
|
55
|
+
|
56
|
+
def initialize(msg, code=nil)
|
57
|
+
super(msg)
|
58
|
+
@code = code || 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Manage instance tags
|
63
|
+
#
|
64
|
+
# === Parameters
|
65
|
+
# options(Hash):: Hash of options as defined in +parse_args+
|
66
|
+
#
|
67
|
+
# === Return
|
68
|
+
# true:: Always return true
|
69
|
+
def run(options)
|
70
|
+
if options[:verbose]
|
71
|
+
log = Logger.new(STDERR)
|
72
|
+
else
|
73
|
+
log = Logger.new(StringIO.new)
|
74
|
+
end
|
75
|
+
RightScale::Log.force_logger(log)
|
76
|
+
|
77
|
+
unless options.include?(:action)
|
78
|
+
write_error("Missing argument, rs_tag --help for additional information")
|
79
|
+
fail(1)
|
80
|
+
end
|
81
|
+
cmd = { :name => options[:action] }
|
82
|
+
cmd[:tag] = options[:tag] if options[:tag]
|
83
|
+
cmd[:tags] = options[:tags] if options[:tags]
|
84
|
+
cmd[:query] = options[:query] if options[:query]
|
85
|
+
begin
|
86
|
+
@disposition = nil
|
87
|
+
send_command(cmd, options[:verbose], options[:timeout]) do |res|
|
88
|
+
begin
|
89
|
+
case options[:action]
|
90
|
+
when :get_tags
|
91
|
+
raise TagError.new("List current server tags failed: #{res.inspect}", 45) unless res.kind_of?(Array)
|
92
|
+
if res.empty?
|
93
|
+
if options[:die]
|
94
|
+
raise TagError.new('No server tags found', 44)
|
95
|
+
else
|
96
|
+
write_output(format_output([], options[:format]))
|
97
|
+
@disposition = 0
|
98
|
+
end
|
99
|
+
else
|
100
|
+
write_output(format_output(res, options[:format]))
|
101
|
+
@disposition = 0
|
102
|
+
end
|
103
|
+
when :query_tags
|
104
|
+
r = serialize_operation_result(res)
|
105
|
+
raise TagError.new("Query tags failed: #{r.inspect}", 46) unless r.kind_of?(OperationResult)
|
106
|
+
if r.success?
|
107
|
+
if r.content.empty?
|
108
|
+
if options[:die]
|
109
|
+
raise TagError.new("No servers with tags #{options[:tags].inspect}", 44)
|
110
|
+
else
|
111
|
+
write_output(format_output({}, options[:format]))
|
112
|
+
@disposition = 0
|
113
|
+
end
|
114
|
+
else
|
115
|
+
write_output(format_output(r.content, options[:format]))
|
116
|
+
@disposition = 0
|
117
|
+
end
|
118
|
+
else
|
119
|
+
raise TagError.new("Query tags failed: #{r.content}", 53)
|
120
|
+
end
|
121
|
+
when :add_tag
|
122
|
+
r = serialize_operation_result(res)
|
123
|
+
raise TagError.new("Add tag failed: #{r.inspect}", 47) unless r.kind_of?(OperationResult)
|
124
|
+
if r.success?
|
125
|
+
write_error("Successfully added tag #{options[:tag]}")
|
126
|
+
@disposition = 0
|
127
|
+
else
|
128
|
+
raise TagError.new("Add tag failed: #{r.content}", 54)
|
129
|
+
end
|
130
|
+
when :remove_tag
|
131
|
+
r = serialize_operation_result(res)
|
132
|
+
raise TagError.new("Remove tag failed: #{r.inspect}", 48) unless r.kind_of?(OperationResult)
|
133
|
+
if r.success?
|
134
|
+
write_error("Successfully removed tag #{options[:tag]}")
|
135
|
+
@disposition = 0
|
136
|
+
else
|
137
|
+
raise TagError.new("Remove tag failed: #{r.content}", 55)
|
138
|
+
end
|
139
|
+
else
|
140
|
+
write_error(res)
|
141
|
+
@disposition = 0
|
142
|
+
end
|
143
|
+
rescue Exception => e
|
144
|
+
@disposition = e
|
145
|
+
end
|
146
|
+
end
|
147
|
+
rescue Exception => e
|
148
|
+
@disposition = e
|
149
|
+
end
|
150
|
+
|
151
|
+
Thread.pass while @disposition.nil?
|
152
|
+
case @disposition
|
153
|
+
when 0
|
154
|
+
succeed
|
155
|
+
else
|
156
|
+
fail(@disposition)
|
157
|
+
end
|
158
|
+
rescue SystemExit => e
|
159
|
+
raise e
|
160
|
+
rescue Exception => e
|
161
|
+
fail(e)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Create options hash from command line arguments
|
165
|
+
#
|
166
|
+
# === Return
|
167
|
+
# options(Hash):: Hash of options as defined by the command line
|
168
|
+
def parse_args
|
169
|
+
parser = Trollop::Parser.new do
|
170
|
+
opt :list
|
171
|
+
opt :add, "", :type => :string
|
172
|
+
opt :remove, "", :type => :string
|
173
|
+
opt :query, "", :type => :string
|
174
|
+
opt :verbose
|
175
|
+
opt :die, "", :short => "-e"
|
176
|
+
opt :format, "", :type => :string, :default => "json"
|
177
|
+
opt :timeout, "", :type => :int
|
178
|
+
version ""
|
179
|
+
end
|
180
|
+
|
181
|
+
begin
|
182
|
+
options = parser.parse
|
183
|
+
options[:action] = :get_tags if options.delete(:list)
|
184
|
+
if options[:add]
|
185
|
+
options[:action] = :add_tag
|
186
|
+
options[:tag] = options.delete(:add)
|
187
|
+
end
|
188
|
+
if options[:remove]
|
189
|
+
options[:action] = :remove_tag
|
190
|
+
options[:tag] = options.delete(:remove)
|
191
|
+
end
|
192
|
+
if options[:query]
|
193
|
+
options[:action] = :query_tags
|
194
|
+
options[:tags] = parse_tag_list(options.delete(:query))
|
195
|
+
end
|
196
|
+
options[:format] = case options[:format]
|
197
|
+
when /^jso?n?$/, nil
|
198
|
+
:json
|
199
|
+
when /^ya?ml$/
|
200
|
+
:yaml
|
201
|
+
when /^te?xt$/, /^sh(ell)?/, 'list'
|
202
|
+
:text
|
203
|
+
else
|
204
|
+
raise Trollop::CommandlineError, "Unknown output format #{options[:format]}"
|
205
|
+
end
|
206
|
+
options
|
207
|
+
rescue Trollop::VersionNeeded
|
208
|
+
write_output(version)
|
209
|
+
succeed
|
210
|
+
rescue Trollop::HelpNeeded
|
211
|
+
write_output(Usage.scan(__FILE__))
|
212
|
+
succeed
|
213
|
+
rescue Trollop::CommandlineError => e
|
214
|
+
write_error(e.message + "\nUse rs_tag --help for additional information")
|
215
|
+
fail(1)
|
216
|
+
rescue SystemExit => e
|
217
|
+
raise e
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
protected
|
222
|
+
# Writes to STDOUT (and a placeholder for spec mocking).
|
223
|
+
#
|
224
|
+
# === Parameters
|
225
|
+
# @param [String] message to write
|
226
|
+
def write_output(message)
|
227
|
+
STDOUT.puts(message)
|
228
|
+
end
|
229
|
+
|
230
|
+
# Writes to STDERR (and a placeholder for spec mocking).
|
231
|
+
#
|
232
|
+
# === Parameters
|
233
|
+
# @param [String] message to write
|
234
|
+
def write_error(message)
|
235
|
+
STDERR.puts(message)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Creates a command client and sends the given payload.
|
239
|
+
#
|
240
|
+
# === Parameters
|
241
|
+
# @param [Hash] cmd as a payload hash
|
242
|
+
# @param [TrueClass, FalseClass] verbose flag
|
243
|
+
# @param [TrueClass, FalseClass] timeout or nil
|
244
|
+
#
|
245
|
+
# === Block
|
246
|
+
# @yield [response] callback for response
|
247
|
+
# @yieldparam response [Object] response of any type
|
248
|
+
def send_command(cmd, verbose, timeout, &callback)
|
249
|
+
config_options = ::RightScale::AgentConfig.agent_options('instance')
|
250
|
+
listen_port = config_options[:listen_port]
|
251
|
+
raise ::ArgumentError.new('Could not retrieve agent listen port') unless listen_port
|
252
|
+
client = ::RightScale::CommandClient.new(listen_port, config_options[:cookie])
|
253
|
+
timeout ||= TAG_REQUEST_TIMEOUT
|
254
|
+
client.send_command(cmd, verbose, timeout, &callback)
|
255
|
+
true
|
256
|
+
end
|
257
|
+
|
258
|
+
def serialize_operation_result(res)
|
259
|
+
command_serializer = ::RightScale::Serializer.new
|
260
|
+
::RightScale::OperationResult.from_results(command_serializer.load(res))
|
261
|
+
end
|
262
|
+
|
263
|
+
# Splits the TAG_LIST parameter on space unless an equals is present in
|
264
|
+
# order to support both the "x:y a:b" and the "x:y=a b c" (tag value
|
265
|
+
# contains space(s)) cases. the "x:y=a b c:d=x y" case is ambiguous and will
|
266
|
+
# be interpreted as follows:
|
267
|
+
# namespace=x, name=y, value=a b c:d=x y
|
268
|
+
#
|
269
|
+
# === Parameters
|
270
|
+
# @param [String] tag_list to parse
|
271
|
+
#
|
272
|
+
# === Return
|
273
|
+
# @return [Array] tags to query
|
274
|
+
def parse_tag_list(tag_list)
|
275
|
+
tag_list = tag_list.to_s
|
276
|
+
if tag_list.index('=')
|
277
|
+
[tag_list.strip]
|
278
|
+
else
|
279
|
+
tag_list.split
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# Format output for display to user
|
284
|
+
#
|
285
|
+
# === Parameter
|
286
|
+
# result(Object):: JSON-compatible data structure (array, hash, etc)
|
287
|
+
# format(String):: how to print output - json, yaml, text
|
288
|
+
#
|
289
|
+
# === Return
|
290
|
+
# a String containing the specified output format
|
291
|
+
def format_output(result, format)
|
292
|
+
case format
|
293
|
+
when :json
|
294
|
+
JSON.pretty_generate(result)
|
295
|
+
when :yaml
|
296
|
+
YAML.dump(result)
|
297
|
+
when :text
|
298
|
+
result = result.keys if result.respond_to?(:keys)
|
299
|
+
result.join(" ")
|
300
|
+
else
|
301
|
+
raise ArgumentError, "Unknown output format #{format}"
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
# Exit with success.
|
306
|
+
#
|
307
|
+
# === Return
|
308
|
+
# R.I.P. does not return
|
309
|
+
def succeed
|
310
|
+
exit(0)
|
311
|
+
end
|
312
|
+
|
313
|
+
# Print error on console and exit abnormally
|
314
|
+
#
|
315
|
+
# === Parameter
|
316
|
+
# reason(Exception|String|Integer):: Exception, error message or numeric failure code
|
317
|
+
#
|
318
|
+
# === Options
|
319
|
+
# :print_usage(Boolean):: Whether script usage should be printed, default to false
|
320
|
+
#
|
321
|
+
# === Return
|
322
|
+
# R.I.P. does not return
|
323
|
+
def fail(reason=nil, options={})
|
324
|
+
case reason
|
325
|
+
when TagError
|
326
|
+
write_error(reason.message)
|
327
|
+
code = reason.code
|
328
|
+
when Errno::EACCES
|
329
|
+
write_error(reason.message)
|
330
|
+
write_error("Try elevating privilege (sudo/runas) before invoking this command.")
|
331
|
+
code = 2
|
332
|
+
when Exception
|
333
|
+
write_error(reason.message)
|
334
|
+
code = 50
|
335
|
+
when String
|
336
|
+
write_error(reason)
|
337
|
+
code = 50
|
338
|
+
when Integer
|
339
|
+
code = reason
|
340
|
+
else
|
341
|
+
code = 1
|
342
|
+
end
|
343
|
+
|
344
|
+
write_output(Usage.scan(__FILE__)) if options[:print_usage]
|
345
|
+
exit(code)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Version information
|
349
|
+
#
|
350
|
+
# === Return
|
351
|
+
# (String):: Version information
|
352
|
+
def version
|
353
|
+
gemspec = eval(File.read(File.join(File.dirname(__FILE__), '..', 'right_link.gemspec')))
|
354
|
+
"rs_tag #{gemspec.version} - RightLink's tagger (c) 2009-2012 RightScale"
|
355
|
+
end
|
356
|
+
|
357
|
+
end # Tagger
|
358
|
+
|
359
|
+
end # RightScale
|
360
|
+
|
361
|
+
#
|
362
|
+
# Copyright (c) 2011 RightScale Inc
|
363
|
+
#
|
364
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
365
|
+
# a copy of this software and associated documentation files (the
|
366
|
+
# "Software"), to deal in the Software without restriction, including
|
367
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
368
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
369
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
370
|
+
# the following conditions:
|
371
|
+
#
|
372
|
+
# The above copyright notice and this permission notice shall be
|
373
|
+
# included in all copies or substantial portions of the Software.
|
374
|
+
#
|
375
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
376
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
377
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
378
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
379
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
380
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
381
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|