right_link 5.9.1 → 5.9.2

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/scripts/tagger.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # === Synopsis:
2
- # RightScale Tagger (rs_tag) - (c) 2009-2012 RightScale Inc
2
+ # RightScale Tagger (rs_tag) - (c) 2009-2013 RightScale Inc
3
3
  #
4
4
  # Tagger allows listing, adding and removing tags on the current instance and
5
5
  # querying for all instances with a given set of tags
@@ -43,10 +43,12 @@ require 'trollop'
43
43
  require 'right_agent'
44
44
  require 'right_agent/scripts/usage'
45
45
  require 'right_agent/scripts/common_parser'
46
+ require File.expand_path(File.join(File.dirname(__FILE__), 'command_helper'))
46
47
 
47
48
  module RightScale
48
49
 
49
50
  class Tagger
51
+ include CommandHelper
50
52
 
51
53
  TAG_REQUEST_TIMEOUT = 2 * 60 # synchronous tag requests need a long timeout
52
54
 
@@ -59,101 +61,103 @@ module RightScale
59
61
  end
60
62
  end
61
63
 
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)
64
+ def get_tags(res, options)
65
+ raise TagError.new("List current server tags failed: #{res.inspect}", 45) unless res.kind_of?(Array)
66
+ if res.empty?
67
+ if options[:die]
68
+ raise TagError.new('No server tags found', 44)
69
+ else
70
+ write_output(format_output([], options[:format]))
71
+ end
72
72
  else
73
- log = Logger.new(StringIO.new)
73
+ write_output(format_output(res, options[:format]))
74
74
  end
75
- RightScale::Log.force_logger(log)
75
+ end
76
76
 
77
- unless options.include?(:action)
78
- write_error("Missing argument, rs_tag --help for additional information")
79
- fail(1)
77
+ def query_tags(res, options)
78
+ r = serialize_operation_result(res)
79
+ raise TagError.new("Query tags failed: #{r.inspect}", 46) unless r.kind_of?(OperationResult)
80
+ if r.success?
81
+ if r.content.empty?
82
+ if options[:die]
83
+ raise TagError.new("No servers with tags #{options[:tags].inspect}", 44)
84
+ else
85
+ write_output(format_output({}, options[:format]))
86
+ end
87
+ else
88
+ write_output(format_output(r.content, options[:format]))
89
+ end
90
+ else
91
+ raise TagError.new("Query tags failed: #{r.content}", 53)
80
92
  end
93
+ end
94
+
95
+ def add_tag(res, options)
96
+ r = serialize_operation_result(res)
97
+ raise TagError.new("Add tag failed: #{r.inspect}", 47) unless r.kind_of?(OperationResult)
98
+ if r.success?
99
+ write_error("Successfully added tag #{options[:tag]}")
100
+ else
101
+ raise TagError.new("Add tag failed: #{r.content}", 54)
102
+ end
103
+ end
104
+
105
+ def remove_tag(res, options)
106
+ r = serialize_operation_result(res)
107
+ raise TagError.new("Remove tag failed: #{r.inspect}", 48) unless r.kind_of?(OperationResult)
108
+ if r.success?
109
+ write_error("Successfully removed tag #{options[:tag]}")
110
+ else
111
+ raise TagError.new("Remove tag failed: #{r.content}", 55)
112
+ end
113
+ end
114
+
115
+ def build_cmd(options)
81
116
  cmd = { :name => options[:action] }
82
117
  cmd[:tag] = options[:tag] if options[:tag]
83
118
  cmd[:tags] = options[:tags] if options[:tags]
84
119
  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
120
+ cmd
121
+ end
122
+
123
+ def set_logger(options)
124
+ if options[:verbose]
125
+ log = Logger.new(STDERR)
126
+ else
127
+ log = Logger.new(StringIO.new)
149
128
  end
129
+ RightScale::Log.force_logger(log)
130
+ end
150
131
 
151
- Thread.pass while @disposition.nil?
152
- case @disposition
153
- when 0
154
- succeed
132
+ def missing_argument
133
+ write_error("Missing argument, rs_tag --help for additional information")
134
+ fail(1)
135
+ end
136
+
137
+ # Manage instance tags
138
+ #
139
+ # === Parameters
140
+ # options(Hash):: Hash of options as defined in +parse_args+
141
+ #
142
+ # === Return
143
+ # true:: Always return true
144
+ def run(options)
145
+ check_privileges
146
+ set_logger(options)
147
+ missing_argument unless options.include?(:action)
148
+ send_command(build_cmd(options), options[:verbose], options[:timeout]) do |res|
149
+ case options[:action]
150
+ when :get_tags
151
+ get_tags(res, options)
152
+ when :query_tags
153
+ query_tags(res, options)
154
+ when :add_tag
155
+ add_tag(res, options)
156
+ when :remove_tag
157
+ remove_tag(res, options)
155
158
  else
156
- fail(@disposition)
159
+ write_error(res)
160
+ end
157
161
  end
158
162
  rescue SystemExit => e
159
163
  raise e
@@ -174,11 +178,11 @@ module RightScale
174
178
  opt :verbose
175
179
  opt :die, "", :short => "-e"
176
180
  opt :format, "", :type => :string, :default => "json"
177
- opt :timeout, "", :type => :int
181
+ opt :timeout, "", :type => :int, :default => TAG_REQUEST_TIMEOUT
178
182
  version ""
179
183
  end
180
184
 
181
- begin
185
+ parse do
182
186
  options = parser.parse
183
187
  options[:action] = :get_tags if options.delete(:list)
184
188
  if options[:add]
@@ -204,17 +208,6 @@ module RightScale
204
208
  raise Trollop::CommandlineError, "Unknown output format #{options[:format]}"
205
209
  end
206
210
  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
211
  end
219
212
  end
220
213
 
@@ -235,31 +228,6 @@ protected
235
228
  STDERR.puts(message)
236
229
  end
237
230
 
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
231
  # Splits the TAG_LIST parameter on space unless an equals is present in
264
232
  # order to support both the "x:y a:b" and the "x:y=a b c" (tag value
265
233
  # contains space(s)) cases. the "x:y=a b c:d=x y" case is ambiguous and will
@@ -302,56 +270,16 @@ protected
302
270
  end
303
271
  end
304
272
 
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
273
  # Version information
349
274
  #
350
275
  # === Return
351
276
  # (String):: Version information
352
277
  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"
278
+ "rs_tag #{right_link_version} - RightLink's tagger (c) 2009-2013 RightScale"
279
+ end
280
+
281
+ def usage
282
+ Usage.scan(__FILE__)
355
283
  end
356
284
 
357
285
  end # Tagger
data/scripts/thunker.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # === Synopsis:
2
- # RightScale Thunker (rs_thunk) - (c) 2011 RightScale Inc
2
+ # RightScale Thunker (rs_thunk) - (c) 2013 RightScale Inc
3
3
  #
4
4
  # Thunker allows you to manage custom SSH logins for non root users. It uses the rightscale
5
5
  # user and group RightScale to give privileges for authorization, managing the instance
@@ -31,6 +31,7 @@ require 'right_agent/scripts/usage'
31
31
  require 'right_agent/scripts/common_parser'
32
32
  require 'right_agent/core_payload_types'
33
33
  require 'right_support/net'
34
+ require File.expand_path(File.join(File.dirname(__FILE__), 'command_helper'))
34
35
 
35
36
  basedir = File.expand_path('../..', __FILE__)
36
37
  require File.join(basedir, 'lib', 'instance')
@@ -38,6 +39,8 @@ require File.join(basedir, 'lib', 'instance')
38
39
  module RightScale
39
40
 
40
41
  class Thunker
42
+ include CommandHelper
43
+
41
44
  SCP_COMMAND = %r{^[A-Za-z0-9_/]*scp}
42
45
  SFTP_COMMAND = %r{^[A-Za-z0-9_/]*sftp-server}
43
46
  AUDIT_REQUEST_TIMEOUT = 15 # best-effort auditing, but try not to block user
@@ -51,6 +54,7 @@ module RightScale
51
54
  # === Return
52
55
  # true:: Always return true
53
56
  def run(options)
57
+ check_privileges
54
58
  @log_sink = StringIO.new
55
59
  @log = Logger.new(@log_sink)
56
60
  RightScale::Log.force_logger(@log)
@@ -136,19 +140,8 @@ module RightScale
136
140
  version ""
137
141
  end
138
142
 
139
- begin
143
+ parse do
140
144
  parser.parse
141
- rescue Trollop::VersionNeeded
142
- puts version
143
- succeed
144
- rescue Trollop::HelpNeeded
145
- puts Usage.scan(__FILE__)
146
- succeed
147
- rescue Trollop::CommandlineError => e
148
- STDERR.puts e.message + "\nUse rs_thunk --help for additional information"
149
- fail(1)
150
- rescue SystemExit => e
151
- raise e
152
145
  end
153
146
  end
154
147
 
@@ -171,14 +164,6 @@ module RightScale
171
164
  return false
172
165
  end
173
166
 
174
- # Exit with success.
175
- #
176
- # === Return
177
- # R.I.P. does not return
178
- def succeed
179
- exit(0)
180
- end
181
-
182
167
  # Print error on console and exit abnormally
183
168
  #
184
169
  # === Parameters
@@ -189,10 +174,6 @@ module RightScale
189
174
  # R.I.P. does not return
190
175
  def fail(reason=nil, options={})
191
176
  case reason
192
- when Errno::EACCES
193
- STDERR.puts reason.message
194
- STDERR.puts "Try elevating privilege (sudo/runas) before invoking this command."
195
- code = 2
196
177
  when Exception
197
178
  STDOUT.puts "Unexpected #{reason.class.name}: #{reason.message}"
198
179
  STDOUT.puts "We apologize for the inconvenience. You may try connecting as root"
@@ -229,11 +210,6 @@ module RightScale
229
210
  # === Return
230
211
  # Returns true on success, false otherwise
231
212
  def create_audit_entry(email, username, access, command, client_ip=nil)
232
- config_options = AgentConfig.agent_options('instance')
233
- listen_port = config_options[:listen_port]
234
- raise ArgumentError.new('Could not retrieve agent listen port') unless listen_port
235
- client = CommandClient.new(listen_port, config_options[:cookie])
236
-
237
213
  begin
238
214
  hostname = `hostname`.strip
239
215
  rescue Exception => e
@@ -269,7 +245,7 @@ module RightScale
269
245
  :detail => detail,
270
246
  :category => RightScale::EventCategories::CATEGORY_SECURITY
271
247
  }
272
- client.send_command(options, false, AUDIT_REQUEST_TIMEOUT)
248
+ send_command(options, false, AUDIT_REQUEST_TIMEOUT)
273
249
 
274
250
  true
275
251
  rescue Exception => e
@@ -325,8 +301,11 @@ module RightScale
325
301
  # === Return
326
302
  # (String):: Version information
327
303
  def version
328
- gemspec = eval(File.read(File.join(File.dirname(__FILE__), '..', 'right_link.gemspec')))
329
- "rs_thunk #{gemspec.version} - RightLink's thunker (c) 2011 RightScale"
304
+ "rs_thunk #{right_link_version} - RightLink's thunker (c) 2013 RightScale"
305
+ end
306
+
307
+ def usage
308
+ Usage.scan(__FILE__)
330
309
  end
331
310
 
332
311
  end # Thunker
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_link
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 5
8
8
  - 9
9
- - 1
10
- version: 5.9.1
9
+ - 2
10
+ version: 5.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - RightScale
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-08-07 00:00:00 -07:00
18
+ date: 2013-10-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -367,12 +367,14 @@ files:
367
367
  - lib/repo_conf_generators/rightscale_conf_generators.rb
368
368
  - lib/repo_conf_generators/yum_conf_generators.rb
369
369
  - lib/repo_conf_generators.rb
370
+ - lib/right_link/version.rb
370
371
  - lib/run_shell.rb
371
372
  - scripts/agent_checker.rb
372
373
  - scripts/agent_controller.rb
373
374
  - scripts/agent_deployer.rb
374
375
  - scripts/bundle_runner.rb
375
376
  - scripts/cloud_controller.rb
377
+ - scripts/command_helper.rb
376
378
  - scripts/log_level_manager.rb
377
379
  - scripts/ohai_runner.rb
378
380
  - scripts/reenroller.rb