right_agent 0.5.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.
Files changed (147) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +78 -0
  3. data/Rakefile +86 -0
  4. data/lib/right_agent.rb +66 -0
  5. data/lib/right_agent/actor.rb +163 -0
  6. data/lib/right_agent/actor_registry.rb +76 -0
  7. data/lib/right_agent/actors/agent_manager.rb +189 -0
  8. data/lib/right_agent/agent.rb +735 -0
  9. data/lib/right_agent/agent_config.rb +403 -0
  10. data/lib/right_agent/agent_identity.rb +209 -0
  11. data/lib/right_agent/agent_tags_manager.rb +213 -0
  12. data/lib/right_agent/audit_formatter.rb +107 -0
  13. data/lib/right_agent/broker_client.rb +683 -0
  14. data/lib/right_agent/command.rb +30 -0
  15. data/lib/right_agent/command/agent_manager_commands.rb +134 -0
  16. data/lib/right_agent/command/command_client.rb +136 -0
  17. data/lib/right_agent/command/command_constants.rb +42 -0
  18. data/lib/right_agent/command/command_io.rb +128 -0
  19. data/lib/right_agent/command/command_parser.rb +87 -0
  20. data/lib/right_agent/command/command_runner.rb +105 -0
  21. data/lib/right_agent/command/command_serializer.rb +63 -0
  22. data/lib/right_agent/console.rb +65 -0
  23. data/lib/right_agent/core_payload_types.rb +42 -0
  24. data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
  25. data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
  26. data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
  27. data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
  28. data/lib/right_agent/core_payload_types/dev_repositories.rb +90 -0
  29. data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
  30. data/lib/right_agent/core_payload_types/executable_bundle.rb +138 -0
  31. data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
  32. data/lib/right_agent/core_payload_types/login_user.rb +62 -0
  33. data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
  34. data/lib/right_agent/core_payload_types/recipe_instantiation.rb +60 -0
  35. data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
  36. data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
  37. data/lib/right_agent/core_payload_types/right_script_instantiation.rb +73 -0
  38. data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
  39. data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
  40. data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
  41. data/lib/right_agent/daemonize.rb +35 -0
  42. data/lib/right_agent/dispatcher.rb +348 -0
  43. data/lib/right_agent/enrollment_result.rb +217 -0
  44. data/lib/right_agent/exceptions.rb +30 -0
  45. data/lib/right_agent/ha_broker_client.rb +1278 -0
  46. data/lib/right_agent/idempotent_request.rb +140 -0
  47. data/lib/right_agent/log.rb +418 -0
  48. data/lib/right_agent/monkey_patches.rb +29 -0
  49. data/lib/right_agent/monkey_patches/amqp_patch.rb +274 -0
  50. data/lib/right_agent/monkey_patches/ruby_patch.rb +49 -0
  51. data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
  52. data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
  53. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
  54. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
  55. data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
  56. data/lib/right_agent/monkey_patches/ruby_patch/singleton_patch.rb +46 -0
  57. data/lib/right_agent/monkey_patches/ruby_patch/string_patch.rb +107 -0
  58. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
  59. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +90 -0
  60. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
  61. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
  62. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
  63. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
  64. data/lib/right_agent/multiplexer.rb +91 -0
  65. data/lib/right_agent/operation_result.rb +270 -0
  66. data/lib/right_agent/packets.rb +637 -0
  67. data/lib/right_agent/payload_formatter.rb +104 -0
  68. data/lib/right_agent/pid_file.rb +159 -0
  69. data/lib/right_agent/platform.rb +319 -0
  70. data/lib/right_agent/platform/darwin.rb +227 -0
  71. data/lib/right_agent/platform/linux.rb +268 -0
  72. data/lib/right_agent/platform/windows.rb +1204 -0
  73. data/lib/right_agent/scripts/agent_controller.rb +522 -0
  74. data/lib/right_agent/scripts/agent_deployer.rb +379 -0
  75. data/lib/right_agent/scripts/common_parser.rb +153 -0
  76. data/lib/right_agent/scripts/log_level_manager.rb +193 -0
  77. data/lib/right_agent/scripts/stats_manager.rb +256 -0
  78. data/lib/right_agent/scripts/usage.rb +58 -0
  79. data/lib/right_agent/secure_identity.rb +92 -0
  80. data/lib/right_agent/security.rb +32 -0
  81. data/lib/right_agent/security/cached_certificate_store_proxy.rb +63 -0
  82. data/lib/right_agent/security/certificate.rb +102 -0
  83. data/lib/right_agent/security/certificate_cache.rb +89 -0
  84. data/lib/right_agent/security/distinguished_name.rb +56 -0
  85. data/lib/right_agent/security/encrypted_document.rb +84 -0
  86. data/lib/right_agent/security/rsa_key_pair.rb +76 -0
  87. data/lib/right_agent/security/signature.rb +86 -0
  88. data/lib/right_agent/security/static_certificate_store.rb +69 -0
  89. data/lib/right_agent/sender.rb +937 -0
  90. data/lib/right_agent/serialize.rb +29 -0
  91. data/lib/right_agent/serialize/message_pack.rb +102 -0
  92. data/lib/right_agent/serialize/secure_serializer.rb +131 -0
  93. data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
  94. data/lib/right_agent/serialize/serializable.rb +135 -0
  95. data/lib/right_agent/serialize/serializer.rb +149 -0
  96. data/lib/right_agent/stats_helper.rb +731 -0
  97. data/lib/right_agent/subprocess.rb +38 -0
  98. data/lib/right_agent/tracer.rb +124 -0
  99. data/right_agent.gemspec +60 -0
  100. data/spec/actor_registry_spec.rb +81 -0
  101. data/spec/actor_spec.rb +99 -0
  102. data/spec/agent_config_spec.rb +226 -0
  103. data/spec/agent_identity_spec.rb +75 -0
  104. data/spec/agent_spec.rb +571 -0
  105. data/spec/broker_client_spec.rb +961 -0
  106. data/spec/command/agent_manager_commands_spec.rb +51 -0
  107. data/spec/command/command_io_spec.rb +93 -0
  108. data/spec/command/command_parser_spec.rb +79 -0
  109. data/spec/command/command_runner_spec.rb +72 -0
  110. data/spec/command/command_serializer_spec.rb +51 -0
  111. data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
  112. data/spec/core_payload_types/executable_bundle_spec.rb +59 -0
  113. data/spec/core_payload_types/login_user_spec.rb +98 -0
  114. data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
  115. data/spec/core_payload_types/spec_helper.rb +23 -0
  116. data/spec/dispatcher_spec.rb +372 -0
  117. data/spec/enrollment_result_spec.rb +53 -0
  118. data/spec/ha_broker_client_spec.rb +1673 -0
  119. data/spec/idempotent_request_spec.rb +136 -0
  120. data/spec/log_spec.rb +177 -0
  121. data/spec/monkey_patches/amqp_patch_spec.rb +100 -0
  122. data/spec/monkey_patches/eventmachine_spec.rb +62 -0
  123. data/spec/monkey_patches/string_patch_spec.rb +99 -0
  124. data/spec/multiplexer_spec.rb +48 -0
  125. data/spec/operation_result_spec.rb +171 -0
  126. data/spec/packets_spec.rb +418 -0
  127. data/spec/platform/platform_spec.rb +60 -0
  128. data/spec/results_mock.rb +45 -0
  129. data/spec/secure_identity_spec.rb +50 -0
  130. data/spec/security/cached_certificate_store_proxy_spec.rb +56 -0
  131. data/spec/security/certificate_cache_spec.rb +71 -0
  132. data/spec/security/certificate_spec.rb +49 -0
  133. data/spec/security/distinguished_name_spec.rb +46 -0
  134. data/spec/security/encrypted_document_spec.rb +55 -0
  135. data/spec/security/rsa_key_pair_spec.rb +55 -0
  136. data/spec/security/signature_spec.rb +66 -0
  137. data/spec/security/static_certificate_store_spec.rb +52 -0
  138. data/spec/sender_spec.rb +887 -0
  139. data/spec/serialize/message_pack_spec.rb +131 -0
  140. data/spec/serialize/secure_serializer_spec.rb +102 -0
  141. data/spec/serialize/serializable_spec.rb +90 -0
  142. data/spec/serialize/serializer_spec.rb +174 -0
  143. data/spec/spec.opts +2 -0
  144. data/spec/spec_helper.rb +77 -0
  145. data/spec/stats_helper_spec.rb +681 -0
  146. data/spec/tracer_spec.rb +114 -0
  147. metadata +320 -0
@@ -0,0 +1,193 @@
1
+ # === Synopsis:
2
+ # RightAgent Log Level Manager (rlog) - (c) 2009-2011 RightScale Inc
3
+ #
4
+ # rlog is a command line tool for retrieving and setting the log level
5
+ # for a RightAgent
6
+ #
7
+ # === Examples:
8
+ # Retrieve log level for all configured agents:
9
+ # rlog
10
+ #
11
+ # Retrieve log level for a specific agent:
12
+ # rlog AGENT
13
+ #
14
+ # Set log level to debug for all configured agents:
15
+ # rlog [AGENT] --log-level debug
16
+ # rlog [AGENT] -l debug
17
+ #
18
+ # Set log level to debug for a specific agent:
19
+ # rlog AGENT -l debug
20
+ #
21
+ # === Usage
22
+ # rs_set_log_level [AGENT] [--log-level, -l debug|info|warn|error|fatal]
23
+ #
24
+ # options:
25
+ # --log-level, -l LVL Set log level of agent
26
+ # --cfg-dir, -c DIR Set directory containing configuration for all agents
27
+ # --verbose, -v Display debug information
28
+ # --help: Display help
29
+ #
30
+ # No options prints the current agent log level
31
+ #
32
+
33
+ require 'rubygems'
34
+ require 'optparse'
35
+ require File.expand_path(File.join(File.dirname(__FILE__), 'usage'))
36
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'right_agent'))
37
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'actors', 'agent_manager'))
38
+ require File.expand_path(File.join(File.dirname(__FILE__), 'common_parser'))
39
+
40
+ module RightScale
41
+
42
+ class LogLevelManager
43
+
44
+ # Convenience wrapper for creating and running log level manager
45
+ #
46
+ # === Return
47
+ # true:: Always return true
48
+ def self.run
49
+ m = LogLevelManager.new
50
+ m.manage(m.parse_args)
51
+ end
52
+
53
+ # Handle log level request
54
+ #
55
+ # === Parameters
56
+ # options(Hash):: Command line options
57
+ #
58
+ # === Return
59
+ # true:: Always return true
60
+ def manage(options)
61
+ # Initialize configuration directory setting
62
+ AgentConfig.cfg_dir = options[:cfg_dir]
63
+
64
+ # Determine command
65
+ level = options[:level]
66
+ command = { :name => (level ? 'set_log_level' : 'get_log_level') }
67
+ command[:level] = level.to_sym if level
68
+
69
+ # Determine candidate agents
70
+ agent_names = if options[:agent_name]
71
+ [options[:agent_name]]
72
+ else
73
+ AgentConfig.cfg_agents
74
+ end
75
+ fail("No agents configured") if agent_names.empty?
76
+
77
+ # Perform command for each agent
78
+ count = 0
79
+ agent_names.each do |agent_name|
80
+ count += 1 if request_log_level(agent_name, command, options)
81
+ end
82
+ puts("No agents running") if count == 0
83
+ true
84
+ end
85
+
86
+ # Create options hash from command line arguments
87
+ #
88
+ # === Return
89
+ # options(Hash):: Hash of options as defined by the command line
90
+ def parse_args
91
+ options = { :verbose => false }
92
+ options[:agent_name] = ARGV[0] unless ARGV[0] =~ /^-/
93
+
94
+ opts = OptionParser.new do |opts|
95
+
96
+ opts.on('-l', '--log-level LEVEL') do |l|
97
+ fail("Invalid log level '#{l}'") unless AgentManager::LEVELS.include?(l.to_sym)
98
+ options[:level] = l
99
+ end
100
+
101
+ opts.on("-c", "--cfg-dir DIR") do |d|
102
+ options[:cfg_dir] = d
103
+ end
104
+
105
+ opts.on('-v', '--verbose') do
106
+ options[:verbose] = true
107
+ end
108
+
109
+ end
110
+
111
+ opts.on_tail('--help') do
112
+ puts Usage.scan(__FILE__)
113
+ exit
114
+ end
115
+
116
+ begin
117
+ opts.parse!(ARGV)
118
+ rescue Exception => e
119
+ exit 0 if e.is_a?(SystemExit)
120
+ fail(e.message + "\nUse 'rlog --help' for additional information")
121
+ end
122
+ options
123
+ end
124
+
125
+ protected
126
+
127
+ # Send log level request to agent
128
+ #
129
+ # === Parameters
130
+ # agent_name(String):: Agent name
131
+ # command(String):: Command request
132
+ # options(Hash):: Command line options
133
+ #
134
+ # === Return
135
+ # (Boolean):: true if agent running, otherwise false
136
+ def request_log_level(agent_name, command, options)
137
+ res = false
138
+ config_options = AgentConfig.agent_options(agent_name)
139
+ unless config_options.empty?
140
+ listen_port = config_options[:listen_port]
141
+ fail("Could not retrieve #{agent_name} agent listen port") unless listen_port
142
+ client = CommandClient.new(listen_port, config_options[:cookie])
143
+ begin
144
+ client.send_command(command, options[:verbose]) do |level|
145
+ puts "Agent #{agent_name} log level: #{level.to_s.upcase}"
146
+ end
147
+ res = true
148
+ rescue Exception => e
149
+ puts "Command #{command.inspect} to #{agent_name} agent failed (#{e})"
150
+ end
151
+ end
152
+ res
153
+ end
154
+
155
+ # Print error on console and exit abnormally
156
+ #
157
+ # === Parameter
158
+ # message(String):: Error message, default to nil (no message printed)
159
+ # print_usage(Boolean):: Whether script usage should be printed, default to false
160
+ #
161
+ # === Return
162
+ # R.I.P. does not return
163
+ def fail(message = nil, print_usage = false)
164
+ puts "** #{message}" if message
165
+ puts Usage.scan(__FILE__) if print_usage
166
+ exit(1)
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
+ #
174
+ # Copyright (c) 2009-2011 RightScale Inc
175
+ #
176
+ # Permission is hereby granted, free of charge, to any person obtaining
177
+ # a copy of this software and associated documentation files (the
178
+ # "Software"), to deal in the Software without restriction, including
179
+ # without limitation the rights to use, copy, modify, merge, publish,
180
+ # distribute, sublicense, and/or sell copies of the Software, and to
181
+ # permit persons to whom the Software is furnished to do so, subject to
182
+ # the following conditions:
183
+ #
184
+ # The above copyright notice and this permission notice shall be
185
+ # included in all copies or substantial portions of the Software.
186
+ #
187
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
188
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
189
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
190
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
191
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
192
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
193
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,256 @@
1
+ # === Synopsis:
2
+ # RightAgent Statistics Manager (rstat) - (c) 2010-2011 RightScale Inc
3
+ #
4
+ # rstat is a command line tool for displaying operation statistics for RightAgents
5
+ #
6
+ # === Examples:
7
+ # Retrieve statistics for all locally running agents:
8
+ # rstat
9
+ #
10
+ # Retrieve statistics for an agent named AGENT:
11
+ # rstat AGENT
12
+ #
13
+ # Retrieve statistics for an agent in JSON format:
14
+ # rstat AGENT --json
15
+ # rstat AGENT --j
16
+ #
17
+ # === Usage:
18
+ # rstat [AGENT] [options]
19
+ #
20
+ # Options:
21
+ # --reset, -r As part of gathering the stats from an agent also reset the stats
22
+ # --timeout, -t SEC Override default timeout in seconds to wait for a response from an agent
23
+ # --json, -j Display the stats data in JSON format
24
+ # --cfg-dir, -c DIR Set directory containing configuration for all agents
25
+ # --help Display help
26
+
27
+ require 'rubygems'
28
+ require 'optparse'
29
+ require File.expand_path(File.join(File.dirname(__FILE__), 'usage'))
30
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'right_agent'))
31
+ require File.expand_path(File.join(File.dirname(__FILE__), 'common_parser'))
32
+
33
+ module RightScale
34
+
35
+ class StatsManager
36
+
37
+ include StatsHelper
38
+
39
+ # Default time to wait for a response from an agent
40
+ DEFAULT_TIMEOUT = 5
41
+
42
+ # Create and run manager
43
+ #
44
+ # === Return
45
+ # true:: Always return true
46
+ def self.run
47
+ m = StatsManager.new
48
+ m.manage(m.parse_args)
49
+ end
50
+
51
+ # Initialize manager
52
+ def initialize
53
+ @command_serializer = Serializer.new
54
+ end
55
+
56
+ # Handle stats request
57
+ #
58
+ # === Parameters
59
+ # options(Hash):: Command line options
60
+ #
61
+ # === Return
62
+ # true:: Always return true
63
+ def manage(options)
64
+ init_log
65
+ AgentConfig.cfg_dir = options[:cfg_dir]
66
+ options[:timeout] ||= DEFAULT_TIMEOUT
67
+ request_stats(options)
68
+ rescue Exception => e
69
+ fail("#{e}\n#{e.backtrace.join("\n")}") unless e.is_a?(SystemExit)
70
+ end
71
+
72
+ # Create options hash from command line arguments
73
+ #
74
+ # === Return
75
+ # options(Hash):: Parsed options
76
+ def parse_args
77
+ options = {:reset => false}
78
+ options[:agent_name] = ARGV[0] unless ARGV[0] =~ /^-/
79
+
80
+ opts = OptionParser.new do |opts|
81
+ parse_other_args(opts, options)
82
+
83
+ opts.on('-r', '--reset') do
84
+ options[:reset] = true
85
+ end
86
+
87
+ opts.on('-t', '--timeout SEC') do |sec|
88
+ options[:timeout] = sec
89
+ end
90
+
91
+ opts.on('-j', '--json') do
92
+ options[:json] = true
93
+ end
94
+
95
+ opts.on("-c", "--cfg-dir DIR") do |d|
96
+ options[:cfg_dir] = d
97
+ end
98
+
99
+ opts.on_tail('--help') do
100
+ puts Usage.scan(__FILE__)
101
+ exit
102
+ end
103
+
104
+ end
105
+
106
+ begin
107
+ opts.parse(ARGV)
108
+ rescue Exception => e
109
+ exit 0 if e.is_a?(SystemExit)
110
+ fail(e.message + "\nUse 'rstat --help' for additional information")
111
+ end
112
+
113
+ options
114
+ end
115
+
116
+ # Request and display statistics for agents
117
+ #
118
+ # === Parameters
119
+ # options(Hash):: Command line options
120
+ #
121
+ # === Return
122
+ # true:: Always return true
123
+ def request_stats(options)
124
+ # Determine candidate agents
125
+ agent_names = if options[:agent_name]
126
+ [options[:agent_name]]
127
+ else
128
+ AgentConfig.cfg_agents
129
+ end
130
+ fail("No agents configured") if agent_names.empty?
131
+
132
+ # Request stats from agents
133
+ count = 0
134
+ agent_names.each do |agent_name|
135
+ begin
136
+ count += 1 if request_agent_stats(agent_name, options)
137
+ rescue Exception => e
138
+ $stderr.puts "Command to #{agent_name} agent failed (#{e})" unless e.is_a?(SystemExit)
139
+ end
140
+ end
141
+ $stderr.puts("No agents running") if count == 0
142
+ end
143
+
144
+ # Request and display statistics for agent
145
+ #
146
+ # === Parameters
147
+ # agent_name(String):: Agent name
148
+ # options(Hash):: Command line options
149
+ #
150
+ # === Return
151
+ # (Boolean):: true if agent running, otherwise false
152
+ def request_agent_stats(agent_name, options)
153
+ res = false
154
+ config_options = AgentConfig.agent_options(agent_name)
155
+ unless config_options.empty? || (listen_port = config_options[:listen_port]).nil?
156
+ client = CommandClient.new(listen_port, config_options[:cookie])
157
+ command = {:name => :stats, :reset => options[:reset]}
158
+ begin
159
+ client.send_command(command, options[:verbose], options[:timeout]) { |r| display(agent_name, r, options) }
160
+ res = true
161
+ rescue Exception => e
162
+ msg = "Could not retrieve #{agent_name} agent stats: #{e}"
163
+ msg += "\n" + e.backtrace.join("\n") unless e.message =~ /Timed out/
164
+ fail(msg)
165
+ end
166
+ end
167
+ res
168
+ end
169
+
170
+ protected
171
+
172
+ # Initialize logging
173
+ #
174
+ # === Return
175
+ # true:: Always return true
176
+ def init_log
177
+ Log.program_name = "stats_manager"
178
+ Log.log_to_file_only(true)
179
+ Log.init("stats_manager", Platform.filesystem.temp_dir, :print => true)
180
+ true
181
+ end
182
+
183
+ # Parse other arguments unique to given stats manager
184
+ #
185
+ # === Parameters
186
+ # opts(OptionParser):: Options parser with options to be parsed
187
+ # options(Hash):: Storage for options that are parsed
188
+ #
189
+ # === Return
190
+ # true:: Always return true
191
+ def parse_other_args(opts, options)
192
+ true
193
+ end
194
+
195
+ # Display stats returned from an agent in human readable or JSON format
196
+ #
197
+ # === Parameters
198
+ # agent_name(String):: Agent name
199
+ # result(String):: Result packet in JSON format containing stats or error
200
+ # options(Hash):: Command line options:
201
+ # :json(Boolean):: Whether to display in JSON format
202
+ #
203
+ # === Return
204
+ # true:: Always return true
205
+ def display(agent_name, result, options)
206
+ result = RightScale::OperationResult.from_results(@command_serializer.load(result))
207
+ if options[:json]
208
+ $stdout.puts result.content.to_json
209
+ else
210
+ if result.respond_to?(:success?) && result.success?
211
+ $stdout.puts "\n#{stats_str(result.content)}\n"
212
+ else
213
+ $stderr.puts "\nCould not retrieve #{agent_name} agent stats: #{result.inspect}"
214
+ end
215
+ end
216
+ true
217
+ end
218
+
219
+ # Print failure message and exit abnormally
220
+ #
221
+ # === Parameters
222
+ # message(String):: Failure message
223
+ # print_usage(Boolean):: Whether to display usage information
224
+ #
225
+ # === Return
226
+ # exits the program
227
+ def fail(message, print_usage = false)
228
+ $stderr.puts "** #{message}"
229
+ puts Usage.scan(__FILE__) if print_usage
230
+ exit(1)
231
+ end
232
+
233
+ end
234
+ end
235
+
236
+ #
237
+ # Copyright (c) 2009-2011 RightScale Inc
238
+ #
239
+ # Permission is hereby granted, free of charge, to any person obtaining
240
+ # a copy of this software and associated documentation files (the
241
+ # "Software"), to deal in the Software without restriction, including
242
+ # without limitation the rights to use, copy, modify, merge, publish,
243
+ # distribute, sublicense, and/or sell copies of the Software, and to
244
+ # permit persons to whom the Software is furnished to do so, subject to
245
+ # the following conditions:
246
+ #
247
+ # The above copyright notice and this permission notice shall be
248
+ # included in all copies or substantial portions of the Software.
249
+ #
250
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
251
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
252
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
253
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
254
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
255
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
256
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright (c) 2009-2011 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
+ # Scans the 'usage' for a given file and returns the resulting String.
24
+ #
25
+ # Note : no formatting occurs. Rdoc is nice as is.
26
+ #
27
+
28
+ module Usage
29
+
30
+ # Scans the given file from its usage (the top comment block) and
31
+ # returns it
32
+ #
33
+ # === Parameters
34
+ # file(String)::
35
+ # path to file to read
36
+ #
37
+ # === Return
38
+ # String::
39
+ # the usage as found in the file
40
+ #
41
+ def self.scan(file)
42
+
43
+ lines = File.readlines(file) # Display usage from the given file
44
+ result = []
45
+
46
+ while line = lines.shift
47
+ if m = line.match(/^ *#(.*)$/)
48
+ result << m[1]
49
+ else
50
+ break unless result.empty?
51
+ end
52
+ end
53
+
54
+ result.join("\n")
55
+ end
56
+
57
+ end
58
+