rhc 0.98.16 → 1.0.4

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 (94) hide show
  1. data/bin/rhc +7 -49
  2. data/bin/rhc-app +14 -3
  3. data/bin/rhc-chk +16 -16
  4. data/bin/rhc-create-app +2 -0
  5. data/bin/rhc-create-domain +1 -2
  6. data/bin/rhc-ctl-app +12 -3
  7. data/bin/rhc-ctl-domain +1 -2
  8. data/bin/rhc-domain +1 -2
  9. data/bin/rhc-domain-info +1 -2
  10. data/bin/rhc-port-forward +1 -2
  11. data/bin/rhc-snapshot +3 -0
  12. data/bin/rhc-sshkey +1 -2
  13. data/bin/rhc-tail-files +1 -1
  14. data/bin/rhc-user-info +1 -3
  15. data/features/application.feature +4 -1
  16. data/features/domain.feature +0 -4
  17. data/features/geared_application.feature +11 -0
  18. data/features/lib/rhc_helper/app.rb +16 -5
  19. data/features/lib/rhc_helper/cartridge.rb +25 -9
  20. data/features/lib/rhc_helper/commandify.rb +34 -7
  21. data/features/lib/rhc_helper/domain.rb +2 -2
  22. data/features/lib/rhc_helper/httpify.rb +24 -14
  23. data/features/lib/rhc_helper/persistable.rb +1 -1
  24. data/features/lib/rhc_helper/sshkey.rb +11 -7
  25. data/features/lib/rhc_helper.rb +5 -3
  26. data/features/multiple_cartridge.feature +1 -1
  27. data/features/scaled_application.feature +48 -0
  28. data/features/sshkey.feature +37 -31
  29. data/features/step_definitions/application_steps.rb +18 -7
  30. data/features/step_definitions/cartridge_steps.rb +29 -3
  31. data/features/step_definitions/domain_steps.rb +2 -2
  32. data/features/step_definitions/sshkey_steps.rb +34 -34
  33. data/features/support/assumptions.rb +21 -9
  34. data/features/support/before_hooks.rb +24 -6
  35. data/features/support/env.rb +45 -19
  36. data/lib/rhc/cartridge_helper.rb +27 -0
  37. data/lib/rhc/cli.rb +1 -1
  38. data/lib/rhc/command_runner.rb +31 -3
  39. data/lib/rhc/commands/alias.rb +38 -0
  40. data/lib/rhc/commands/app.rb +478 -0
  41. data/lib/rhc/commands/base.rb +42 -12
  42. data/lib/rhc/commands/cartridge.rb +189 -0
  43. data/lib/rhc/commands/domain.rb +11 -49
  44. data/lib/rhc/commands/port-forward.rb +0 -1
  45. data/lib/rhc/commands/setup.rb +2 -1
  46. data/lib/rhc/commands/snapshot.rb +118 -0
  47. data/lib/rhc/commands/sshkey.rb +24 -38
  48. data/lib/rhc/commands/tail.rb +24 -0
  49. data/lib/rhc/commands/threaddump.rb +16 -0
  50. data/lib/rhc/commands.rb +33 -7
  51. data/lib/rhc/config.rb +28 -12
  52. data/lib/rhc/context_helper.rb +19 -5
  53. data/lib/rhc/core_ext.rb +86 -0
  54. data/lib/rhc/exceptions.rb +44 -0
  55. data/lib/rhc/git_helper.rb +59 -0
  56. data/lib/rhc/helpers.rb +86 -5
  57. data/lib/rhc/output_helpers.rb +213 -0
  58. data/lib/rhc/rest/application.rb +134 -67
  59. data/lib/rhc/rest/base.rb +48 -0
  60. data/lib/rhc/rest/cartridge.rb +40 -44
  61. data/lib/rhc/rest/client.rb +127 -59
  62. data/lib/rhc/rest/domain.rb +29 -39
  63. data/lib/rhc/rest/gear_group.rb +10 -0
  64. data/lib/rhc/rest/key.rb +8 -23
  65. data/lib/rhc/rest/user.rb +8 -24
  66. data/lib/rhc/rest.rb +22 -11
  67. data/lib/rhc/ssh_key_helpers.rb +47 -0
  68. data/lib/rhc/usage_templates/help.erb +0 -1
  69. data/lib/rhc/version.rb +3 -3
  70. data/lib/rhc/wizard.rb +123 -225
  71. data/lib/rhc-common.rb +43 -62
  72. data/spec/rest_spec_helper.rb +159 -36
  73. data/spec/rhc/cli_spec.rb +29 -1
  74. data/spec/rhc/command_spec.rb +32 -35
  75. data/spec/rhc/commands/alias_spec.rb +123 -0
  76. data/spec/rhc/commands/app_spec.rb +414 -0
  77. data/spec/rhc/commands/cartridge_spec.rb +342 -0
  78. data/spec/rhc/commands/domain_spec.rb +8 -8
  79. data/spec/rhc/commands/setup_spec.rb +17 -6
  80. data/spec/rhc/commands/snapshot_spec.rb +140 -0
  81. data/spec/rhc/commands/sshkey_spec.rb +26 -4
  82. data/spec/rhc/commands/tail_spec.rb +34 -0
  83. data/spec/rhc/commands/threaddump_spec.rb +83 -0
  84. data/spec/rhc/config_spec.rb +39 -13
  85. data/spec/rhc/context_spec.rb +51 -0
  86. data/spec/rhc/helpers_spec.rb +52 -12
  87. data/spec/rhc/rest_application_spec.rb +16 -3
  88. data/spec/rhc/rest_client_spec.rb +144 -36
  89. data/spec/rhc/rest_spec.rb +1 -1
  90. data/spec/rhc/wizard_spec.rb +133 -232
  91. data/spec/spec_helper.rb +4 -3
  92. metadata +56 -31
  93. data/features/support/ssh.sh +0 -2
  94. data/spec/rhc/common_spec.rb +0 -49
@@ -0,0 +1,213 @@
1
+ module RHC
2
+ module OutputHelpers
3
+ # Issues collector collects a set of recoverable issues and steps to fix them
4
+ # for output at the end of a complex command
5
+ def add_issue(reason, commands_header, *commands)
6
+ @issues ||= []
7
+ issue = {:reason => reason,
8
+ :commands_header => commands_header,
9
+ :commands => commands}
10
+ @issues << issue
11
+ end
12
+
13
+ def format_issues(indent)
14
+ return nil unless issues?
15
+
16
+ indentation = " " * indent
17
+ reasons = ""
18
+ steps = ""
19
+
20
+ @issues.each_with_index do |issue, i|
21
+ reasons << "#{indentation}#{i+1}. #{issue[:reason].strip}\n"
22
+ steps << "#{indentation}#{i+1}. #{issue[:commands_header].strip}\n"
23
+ issue[:commands].each { |cmd| steps << "#{indentation} $ #{cmd}\n" }
24
+ end
25
+
26
+ [reasons, steps]
27
+ end
28
+
29
+ def issues?
30
+ not @issues.nil?
31
+ end
32
+
33
+ #---------------------------
34
+ # Domain information
35
+ #---------------------------
36
+
37
+ # This is a little different because we don't want to recreate the display_app function
38
+ def display_domain(domain)
39
+ say "No domain exists. You can use 'rhc domain create' to create a namespace for applications." and return unless domain
40
+ header "Applications in %s" % domain.id do
41
+ domain.applications.each do |a|
42
+ display_app(a,a.cartridges,a.scalable_carts.first)
43
+ end.blank? and say "No applications. You can use 'rhc app create' to create new applications."
44
+ end
45
+ end
46
+
47
+ #---------------------------
48
+ # Application information
49
+ #---------------------------
50
+ def display_app(app,cartridges = nil,scalable_cart = nil)
51
+ heading = "%s @ %s" % [app.name, app.app_url]
52
+ paragraph do
53
+ header heading do
54
+ display_app_properties(app,:creation_time,:uuid,:gear_profile,:git_url,:ssh_url,:aliases)
55
+ display_included_carts(cartridges) if cartridges
56
+ display_scaling_info(app,scalable_cart) if scalable_cart
57
+ end
58
+ end
59
+ end
60
+
61
+ def display_app_properties(app,*properties)
62
+ say_table \
63
+ "Application Info",
64
+ get_properties(app,*properties),
65
+ :delete => true
66
+ end
67
+
68
+ def display_included_carts(carts)
69
+ properties = Hash[carts.map do |cart|
70
+ [cart.name,cart.connection_info]
71
+ end]
72
+
73
+ properties = "None" unless properties.present?
74
+
75
+ say_table \
76
+ "Cartridges",
77
+ properties,
78
+ :preserve_keys => true
79
+ end
80
+
81
+ def display_scaling_info(app,cart)
82
+ # Save these values for easier reuse
83
+ values = [:current_scale,:scales_from,:scales_to,:scales_with]
84
+ # Get the scaling properties we care about
85
+ properties = get_properties(cart,*values)
86
+ # Format the string for applications
87
+ properties = "Scaled x%d (minimum: %s, maximum: %s) with %s on %s gears" %
88
+ [properties.values_at(*values), app.gear_profile].flatten
89
+
90
+ say_table \
91
+ "Scaling Info",
92
+ properties
93
+ end
94
+
95
+ #---------------------------
96
+ # Cartridge information
97
+ #---------------------------
98
+
99
+ def display_cart(cart,properties = nil)
100
+ @table_displayed = false
101
+ header cart.name do
102
+ display_cart_properties(cart,properties) if properties
103
+ display_cart_scaling_info(cart) if cart.scalable?
104
+ display_no_info("cartridge") unless @table_displayed
105
+ end
106
+ end
107
+
108
+ def display_cart_properties(cart,properties)
109
+ # We need to actually access the cart because it's not a simple hash
110
+ properties = get_properties(cart,*properties.keys) do |prop|
111
+ cart.property(:cart_data,prop)["value"]
112
+ end
113
+
114
+ say_table \
115
+ "Properties",
116
+ properties
117
+ end
118
+
119
+ def display_cart_scaling_info(cart)
120
+ say_table \
121
+ "Scaling Info",
122
+ get_properties(cart,:current_scale,:scales_from,:scales_to)
123
+ end
124
+
125
+ #---------------------------
126
+ # Misc information
127
+ #---------------------------
128
+
129
+ def display_no_info(type)
130
+ say_table \
131
+ nil,
132
+ ["This #{type} has no information to show"]
133
+ end
134
+
135
+ private
136
+ def say_table(heading,values,opts = {})
137
+ @table_displayed = true
138
+ table = make_table(values,opts)
139
+
140
+ # Go through all the table rows
141
+ _proc = proc{
142
+ table.each do |s|
143
+ # Remove trailing = (like for cartridges list)
144
+ indent s.gsub(/\s*=\s*$/,'')
145
+ end
146
+ }
147
+
148
+ # Make sure we nest properly
149
+ if heading
150
+ header heading do
151
+ _proc.call
152
+ end
153
+ else
154
+ _proc.call
155
+ end
156
+ end
157
+
158
+ # This uses the array of properties to retrieve them from an object
159
+ def get_properties(object,*properties)
160
+ Hash[properties.map do |prop|
161
+ # Either send the property to the object or yield it
162
+ value = block_given? ? yield(prop) : object.send(prop)
163
+ # Some values (like date) need some special handling
164
+ value = format_value(prop,value)
165
+
166
+ [prop,value]
167
+ end]
168
+ end
169
+
170
+ # Format some special values
171
+ def format_value(prop,value)
172
+ case prop
173
+ when :creation_time
174
+ date(value)
175
+ when :scales_from,:scales_to
176
+ (value == -1 ? "available gears" : value)
177
+ else
178
+ value
179
+ end
180
+ end
181
+
182
+ # Make the rows for the table
183
+ # If we pass a hash, it will manipulate it into a nice table
184
+ # Arrays and single vars will just be passed back as arrays
185
+ def make_table(values,opts = {})
186
+ case values
187
+ when Hash
188
+ # Loop through the values in case we need to fix them
189
+ _values = values.inject({}) do |h,(k,v)|
190
+ # Format the keys based on the table_heading function
191
+ # If we pass :preserve_keys, we leave them alone (like for cart names)
192
+ key = opts[:preserve_keys] ? k : table_heading(k)
193
+
194
+ # Replace empty or nil values with spaces
195
+ # If we pass :delete, we assume those are not needed
196
+ if v.blank?
197
+ h[key] = "" unless opts[:delete]
198
+ else
199
+ h[key] = v.to_s
200
+ end
201
+ h
202
+ end
203
+ # Join the values into rows
204
+ table _values, :join => " = "
205
+ # Create a simple array
206
+ when Array
207
+ values
208
+ else
209
+ [values]
210
+ end
211
+ end
212
+ end
213
+ end
@@ -1,94 +1,161 @@
1
+ require 'uri'
2
+ require 'rhc/rest/base'
1
3
 
2
4
  module RHC
3
5
  module Rest
4
- class Application
6
+ class Application < Base
5
7
  include Rest
6
- attr_reader :domain_id, :name, :creation_time, :uuid, :aliases, :git_url, :app_url, :gear_profile, :framework,
7
- :scalable, :health_check_path, :embedded, :gear_count, :ssh_url, :scale_min, :scale_max
8
- def initialize(args)
9
- #logger.debug args
10
- @domain_id = args[:domain_id] || args["domain_id"]
11
- @name = args[:name] || args["name"]
12
- @creation_time = args[:creation_time] || args["creation_time"]
13
- @uuid = args[:uuid] || args["uuid"]
14
- @aliases = args[:aliases] || args["aliases"]
15
- @git_url = args[:git_url] || args["git_url"]
16
- @app_url = args[:app_url] || args["app_url"]
17
- @gear_profile = args[:gear_profile] || args["gear_profile"]
18
- @framework = args[:framework] || args["framework"]
19
- @scalable = args[:scalable] || args["scalable"]
20
- @health_check_path = args[:health_check_path] || args["health_check_path"]
21
- @embedded = args[:embedded] || args["embedded"]
22
- @gear_count = args[:gear_count] || args["gear_count"]
23
- @ssh_url = args[:ssh_url] || args["ssh_url"]
24
- @scale_min = args[:scale_min] || args["scale_min"]
25
- @scale_max = args[:scale_max] || args["scale_max"]
26
- @links = args[:links] || args["links"]
27
-
28
- end
29
-
30
- #Add Cartridge
31
- def add_cartridge(name)
32
- logger.debug "Adding cartridge #{name}" if @mydebug
33
- url = @links['ADD_CARTRIDGE']['href']
34
- method = @links['ADD_CARTRIDGE']['method']
35
- payload = {:name => name}
36
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
37
- return request(request)
38
- end
39
-
40
- #Get all Cartridge for this applications
8
+
9
+ attr_reader :domain_id, :name, :creation_time, :uuid, :aliases,
10
+ :git_url, :app_url, :gear_profile, :framework,
11
+ :scalable, :health_check_path, :embedded, :gear_count,
12
+ :ssh_url
13
+
14
+ # Query helper to say consistent with cartridge
15
+ def scalable?
16
+ scalable
17
+ end
18
+
19
+ def scalable_carts
20
+ return [] unless scalable?
21
+ carts = cartridges.select(&:scalable?)
22
+ scales_with = carts.map(&:scales_with)
23
+ carts.delete_if{|x| scales_with.include?(x.name)}
24
+ end
25
+
26
+ def add_cartridge(name, timeout=nil)
27
+ debug "Adding cartridge #{name}"
28
+ rest_method "ADD_CARTRIDGE", {:name => name}, timeout
29
+ end
30
+
41
31
  def cartridges
42
- logger.debug "Getting all cartridges for application #{self.name}" if @mydebug
43
- url = @links['LIST_CARTRIDGES']['href']
44
- method = @links['LIST_CARTRIDGES']['method']
45
- request = new_request(:url => url, :method => method, :headers => @@headers)
46
- return request(request)
32
+ debug "Getting all cartridges for application #{name}"
33
+ rest_method "LIST_CARTRIDGES"
34
+ end
35
+
36
+ def gear_groups
37
+ debug "Getting all gear groups for application #{name}"
38
+ rest_method "GET_GEAR_GROUPS"
39
+ end
40
+
41
+ def tidy
42
+ debug "Starting application #{name}"
43
+ rest_method 'TIDY', :event => "tidy"
47
44
  end
48
45
 
49
- #Start Application
50
46
  def start
51
- logger.debug "Starting application #{self.name}" if @mydebug
52
- url = @links['START']['href']
53
- method = @links['START']['method']
54
- payload = {:event=> "start"}
55
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
56
- return request(request)
47
+ debug "Starting application #{name}"
48
+ rest_method 'START', :event => "start"
57
49
  end
58
50
 
59
- #Stop Application
60
51
  def stop(force=false)
61
- logger.debug "Stopping application #{self.name} force-#{force}" if @mydebug
62
- url = @links['STOP']['href']
63
- method = @links['STOP']['method']
52
+ debug "Stopping application #{name} force-#{force}"
53
+
64
54
  if force
65
55
  payload = {:event=> "force-stop"}
66
56
  else
67
57
  payload = {:event=> "stop"}
68
58
  end
69
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
70
- return request(request)
59
+
60
+ rest_method "STOP", payload
71
61
  end
72
62
 
73
- #Restart Application
74
63
  def restart
75
- logger.debug "Restarting application #{self.name}" if @mydebug
76
- url = @links['RESTART']['href']
77
- method = @links['RESTART']['method']
78
- payload = {:event=> "restart"}
79
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
80
- return request(request)
64
+ debug "Restarting application #{name}"
65
+ rest_method "RESTART", :event => "restart"
81
66
  end
82
67
 
83
- #Delete Application
84
68
  def destroy
85
- logger.debug "Deleting application #{self.name}" if @mydebug
86
- url = @links['DELETE']['href']
87
- method = @links['DELETE']['method']
88
- request = new_request(:url => url, :method => method, :headers => @@headers)
89
- return request(request)
69
+ debug "Deleting application #{name}"
70
+ rest_method "DELETE"
90
71
  end
91
72
  alias :delete :destroy
73
+
74
+ def reload
75
+ debug "Reload application #{name}"
76
+ rest_method "RELOAD", :event => "reload"
77
+ end
78
+
79
+ def threaddump
80
+ debug "Running thread dump for #{name}"
81
+ rest_method "THREAD_DUMP", :event => "thread-dump"
82
+ end
83
+
84
+ def add_alias(app_alias)
85
+ debug "Running add_alias for #{name}"
86
+ rest_method "ADD_ALIAS", :event => "add-alias", :alias => app_alias
87
+ end
88
+
89
+ def remove_alias(app_alias)
90
+ debug "Running add_alias for #{name}"
91
+ rest_method "REMOVE_ALIAS", :event => "remove-alias", :alias => app_alias
92
+ end
93
+
94
+ #Find Cartridge by name
95
+ def find_cartridge(sought, options={})
96
+ debug "Finding cartridge #{sought} in app #{name}"
97
+
98
+ type = options[:type]
99
+
100
+ cartridges.each { |cart| return cart if cart.name == sought and (type.nil? or cart.type == type) }
101
+
102
+ suggested_msg = ""
103
+ valid_cartridges = cartridges.select {|c| type.nil? or c.type == type}
104
+ unless valid_cartridges.empty?
105
+ suggested_msg = "\n\nValid cartridges:"
106
+ valid_cartridges.each { |cart| suggested_msg += "\n#{cart.name}" }
107
+ end
108
+ raise RHC::CartridgeNotFoundException.new("Cartridge #{sought} can't be found in application #{name}.#{suggested_msg}")
109
+ end
110
+
111
+ #Find Cartridges by name or regex
112
+ def find_cartridges(name, options={})
113
+ if name.is_a?(Hash)
114
+ options = name
115
+ name = options[:name]
116
+ end
117
+
118
+ type = options[:type]
119
+ regex = options[:regex]
120
+ debug "Finding cartridge #{name || regex} in app #{@name}"
121
+
122
+ filtered = Array.new
123
+ cartridges.each do |cart|
124
+ if regex
125
+ filtered.push(cart) if cart.name.match(regex) and (type.nil? or cart.type == type)
126
+ else
127
+ filtered.push(cart) if cart.name == name and (type.nil? or cart.type == type)
128
+ end
129
+ end
130
+ filtered
131
+ end
132
+
133
+ def host
134
+ @host ||= URI(app_url).host
135
+ end
136
+
137
+ #Application log file tailing
138
+ def tail(options)
139
+ debug "Tail in progress for #{name}"
140
+
141
+ file_glob = options.files ? options.files : "#{cartridges.first.name}/logs/*"
142
+ remote_cmd = "tail#{options.opts ? ' --opts ' + Base64::encode64(options.opts).chomp : ''} #{file_glob}"
143
+ ssh_cmd = "ssh -t #{uuid}@#{host} '#{remote_cmd}'"
144
+ begin
145
+ #Use ssh -t to tail the logs
146
+ debug ssh_cmd
147
+ ssh_ruby(host, uuid, remote_cmd)
148
+ rescue SocketError => e
149
+ msg =<<MESSAGE
150
+ Could not connect: #{e.message}
151
+ You can try to run this manually if you have ssh installed:
152
+ #{ssh_cmd}
153
+
154
+ MESSAGE
155
+ debug "DEBUG: #{e.message}\n"
156
+ raise SocketError, msg
157
+ end
158
+ end
92
159
  end
93
160
  end
94
161
  end
@@ -0,0 +1,48 @@
1
+ require 'base64'
2
+ require 'rhc/json'
3
+
4
+ module RHC
5
+ module Rest
6
+ class Base
7
+ include Rest
8
+
9
+ attr_reader :messages
10
+
11
+ def initialize(json_args={}, use_debug=false)
12
+ @debug = use_debug
13
+ @__json_args__ = json_args
14
+ @messages = []
15
+ end
16
+
17
+ def add_message(msg)
18
+ @messages << msg
19
+ end
20
+
21
+ private
22
+ def debug(msg)
23
+ logger.debug(msg) if @debug
24
+ end
25
+
26
+ def rest_method(link_name, payload={}, timeout=nil)
27
+ url = links[link_name]['href']
28
+ method = links[link_name]['method']
29
+
30
+ request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload, :timeout => timeout)
31
+ debug "Request: #{request.inspect}"
32
+ request(request)
33
+ end
34
+
35
+ def links
36
+ @__json_args__[:links] || @__json_args__['links']
37
+ end
38
+
39
+ def self.attr_reader(*names)
40
+ names.each do |name|
41
+ define_method(name) do
42
+ instance_variable_get("@#{name}") || @__json_args__[name] || @__json_args__[name.to_s]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,12 +1,10 @@
1
+ require 'rhc/rest/base'
2
+
1
3
  module RHC
2
4
  module Rest
3
- class Cartridge
4
- include Rest
5
- attr_reader :type, :name, :properties
6
- def initialize(args)
7
- @name = args[:name] || args["name"]
8
- @type = args[:type] || args["type"]
9
- @links = args[:links] || args["links"]
5
+ class Cartridge < Base
6
+ attr_reader :type, :name, :properties, :status_messages, :scales_to, :scales_from, :scales_with, :current_scale
7
+ def initialize(args, use_debug=false)
10
8
  @properties = {}
11
9
  props = args[:properties] || args["properties"] || []
12
10
  props.each do |p|
@@ -14,63 +12,61 @@ module RHC
14
12
  category[:"#{p['name']}"] = p
15
13
  @properties[:"#{p['type']}"] = category
16
14
  end
15
+
16
+ super
17
+ end
18
+
19
+ def scalable?
20
+ [scales_to,scales_from].map{|x| x > 1 || x == -1}.inject(:|)
17
21
  end
18
22
 
19
23
  def property(category, key)
20
- category = properties[category]
21
- category ? category[key] : nil
24
+ category = properties[category]
25
+ category ? category[key] : nil
26
+ end
27
+
28
+ def status
29
+ debug "Getting cartridge #{name}'s status"
30
+ result = rest_method "GET", :include => "status_messages"
31
+ result.status_messages
22
32
  end
23
33
 
24
- #Start Cartridge
25
34
  def start
26
- logger.debug "Starting cartridge #{self.name}" if @mydebug
27
- url = @links['START']['href']
28
- method = @links['START']['method']
29
- payload = {:event=> "start"}
30
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
31
- return request(request)
35
+ debug "Starting cartridge #{name}"
36
+ rest_method "START", :event => "start"
32
37
  end
33
38
 
34
- #Stop Cartridge
35
39
  def stop()
36
- logger.debug "Stopping cartridge #{self.name}" if @mydebug
37
- url = @links['STOP']['href']
38
- method = @links['STOP']['method']
39
- payload = {:event=> "stop"}
40
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
41
- return request(request)
40
+ debug "Stopping cartridge #{name}"
41
+ rest_method "STOP", :event => "stop"
42
42
  end
43
43
 
44
- #Restart Cartridge
45
44
  def restart
46
- logger.debug "Restarting cartridge #{self.name}" if @mydebug
47
- url = @links['RESTART']['href']
48
- method = @links['RESTART']['method']
49
- payload = {:event=> "restart"}
50
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
51
- return request(request)
45
+ debug "Restarting cartridge #{name}"
46
+ rest_method "RESTART", :event => "restart"
52
47
  end
53
48
 
54
- #Reload Cartridge
55
49
  def reload
56
- logger.debug "Reloading cartridge #{self.name}" if @mydebug
57
- url = @links['RESTART']['href']
58
- method = @links['RESTART']['method']
59
- payload = {:event=> "reload"}
60
- request = new_request(:url => url, :method => method, :headers => @@headers, :payload => payload)
61
- return request(request)
50
+ debug "Reloading cartridge #{name}"
51
+ rest_method "RESTART", :event => "reload"
62
52
  end
63
53
 
64
- #Delete Cartridge
65
54
  def destroy
66
- logger.debug "Deleting cartridge #{self.name}" if @mydebug
67
- url = @links['DELETE']['href']
68
- method = @links['DELETE']['method']
69
- request = new_request(:url => url, :method => method, :headers => @@headers)
70
- return request(request)
55
+ debug "Deleting cartridge #{name}"
56
+ rest_method "DELETE"
71
57
  end
72
58
  alias :delete :destroy
73
- alias :delete :destroy
59
+
60
+ def set_scales(values)
61
+ values.delete_if{|k,v| v.nil? }
62
+ debug "Setting scales = %s" % values.map{|k,v| "#{k}: #{v}"}.join(" ")
63
+ rest_method "UPDATE", values
64
+ end
65
+
66
+ def connection_info
67
+ info = property(:cart_data, :connection_url) || property(:cart_data, :job_url) || property(:cart_data, :monitoring_url)
68
+ info ? (info["value"] || '').rstrip : nil
69
+ end
74
70
  end
75
71
  end
76
72
  end