Class: RHC::Commands::Cartridge
Constant Summary
Constants included
from Helpers
Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#find_app, #find_domain, #find_membership_container, #find_team, #from_local_git, included, #namespace_context, #server_context
Methods included from GitHelpers
#git_clone_application, #git_clone_deploy_hooks, #git_clone_repo, #git_cmd, #git_config_get, #git_config_set, #git_remote_add, #git_version, #has_git?
Methods included from Helpers
#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding
#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #display_team, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message
Instance Method Details
#add(cart_type) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rhc/commands/cartridge.rb', line 81
def add(cart_type)
cart = check_cartridges(cart_type, :from => not_standalone_cartridges).first
say "Adding #{cart.short_name} to application '#{options.app}' ... "
say format_usage_message(cart) if cart.usage_rate?
rest_app = find_app(:include => :cartridges)
supports_env_vars = rest_app.supports_add_cartridge_with_env_vars?
supports_gear_size = rest_app.supports_add_cartridge_with_gear_size?
cart.environment_variables = collect_env_vars(options.env).map { |item| item.to_hash } if options.env && supports_env_vars
cart.gear_size = options.gear_size if options.gear_size && supports_gear_size
rest_cartridge = rest_app.add_cartridge(cart)
success "done"
rest_cartridge.environment_variables = cart.environment_variables if cart.environment_variables.present?
paragraph{ display_cart(rest_cartridge) }
paragraph{ say "Use 'app env --help' to manage environment variable(s) on this cartridge and application." } if cart.environment_variables.present?
paragraph{ warn "Server does not support environment variables." if options.env && !supports_env_vars }
paragraph{ warn "Server does not support gear sizes for cartridges." if options.gear_size && !supports_gear_size }
paragraph{ rest_cartridge.messages.each { |msg| success msg } }
0
end
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rhc/commands/cartridge.rb', line 39
def list
carts = rest_client.cartridges.sort_by{ |c| "#{c.type == 'standalone' && 1}_#{c.tags.include?('experimental') ? 1 : 0}_#{(c.display_name || c.name).downcase}" }
if options.verbose
carts.each do |c|
paragraph do
name = c.name
name += '*' if c.usage_rate?
name = c.display_name != c.name && "#{color(c.display_name, :cyan)} [#{name}]" || name
tags = c.tags - RHC::Rest::Cartridge::HIDDEN_TAGS
say ([name, "(#{c.only_in_existing? ? 'addon' : 'web'})"])
say c.description
paragraph{ say "Tagged with: #{tags.sort.join(', ')}" } if tags.present?
paragraph{ say format_usage_message(c) } if c.usage_rate?
paragraph{ warn "Does not receive automatic security updates" } unless c.automatic_updates?
end
end
else
say table(carts.collect do |c|
[[c.name, c.usage_rate? ? " (*)" : "", c.automatic_updates? ? '' : ' (!)'].join(''),
c.display_name,
c.only_in_existing? ? 'addon' : 'web',
]
end)
end
paragraph{ say "Note: Web cartridges can only be added to new applications." }
paragraph{ say "(*) denotes a cartridge with additional usage costs." } if carts.any?(&:usage_rate?)
paragraph{ say "(!) denotes a cartridge that will not receive automatic security updates." } unless options.verbose || carts.none?(&:automatic_updates?)
0
end
|
#reload(cartridge) ⇒ Object
192
193
194
195
|
# File 'lib/rhc/commands/cartridge.rb', line 192
def reload(cartridge)
cartridge_action(cartridge, :reload, 'Reloading %s ... ')
0
end
|
#remove(cartridge) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/rhc/commands/cartridge.rb', line 130
def remove(cartridge)
rest_app = find_app(:include => :cartridges)
rest_cartridge = check_cartridges(cartridge, :from => rest_app.cartridges).first
confirm_action "Removing a cartridge is a destructive operation that may result in loss of data associated with the cartridge.\n\nAre you sure you wish to remove #{rest_cartridge.name} from '#{rest_app.name}'?"
say "Removing #{rest_cartridge.name} from '#{rest_app.name}' ... "
rest_cartridge.destroy
success "removed"
paragraph{ rest_cartridge.messages.each { |msg| success msg } }
0
end
|
#restart(cartridge) ⇒ Object
170
171
172
173
|
# File 'lib/rhc/commands/cartridge.rb', line 170
def restart(cartridge)
cartridge_action(cartridge, :restart, 'Restarting %s ... ')
0
end
|
#scale(cartridge, multiplier) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/rhc/commands/cartridge.rb', line 217
def scale(cartridge, multiplier)
options.default(:min => Integer(multiplier), :max => Integer(multiplier)) if multiplier rescue raise ArgumentError, "Multiplier must be a positive integer."
raise RHC::MissingScalingValueException unless options.min || options.max
rest_app = find_app(:include => :cartridges)
rest_cartridge = check_cartridges(cartridge, :from => rest_app.cartridges).first
raise RHC::CartridgeNotScalableException unless rest_cartridge.scalable?
warn "This operation will run until the application is at the minimum scale and may take several minutes."
say "Setting scale range for #{rest_cartridge.name} ... "
cart = rest_cartridge.set_scales({
:scales_from => options.min,
:scales_to => options.max
})
success "done"
paragraph{ display_cart(cart) }
0
rescue RHC::Rest::TimeoutException => e
raise unless e.on_receive?
info "The server has closed the connection, but your scaling operation is still in progress. Please check the status of your operation via 'app show-app'."
1
end
|
#show(cartridge) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/rhc/commands/cartridge.rb', line 115
def show(cartridge)
rest_app = find_app(:include => :cartridges)
rest_cartridge = check_cartridges(cartridge, :from => rest_app.cartridges).first
display_cart(rest_cartridge)
0
end
|
#start(cartridge) ⇒ Object
150
151
152
153
|
# File 'lib/rhc/commands/cartridge.rb', line 150
def start(cartridge)
cartridge_action(cartridge, :start, 'Starting %s ... ')
0
end
|
#status(cartridge) ⇒ Object
180
181
182
183
184
185
|
# File 'lib/rhc/commands/cartridge.rb', line 180
def status(cartridge)
rest_app = find_app(:include => :cartridges)
rest_cartridge = check_cartridges(cartridge, :from => rest_app.cartridges).first
results { rest_cartridge.status.each{ |msg| say msg['message'] } }
0
end
|
#stop(cartridge) ⇒ Object
160
161
162
163
|
# File 'lib/rhc/commands/cartridge.rb', line 160
def stop(cartridge)
cartridge_action(cartridge, :stop, 'Stopping %s ... ')
0
end
|
#storage(cartridge) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/rhc/commands/cartridge.rb', line 254
def storage(cartridge)
cartridges = Array(cartridge)
rest_client(:min_api => 1.3).api
rest_app = find_app(:include => :cartridges)
actions = options.__hash__.keys & [:show, :add, :remove, :set]
raise RHC::AdditionalStorageArgumentsException if actions.length > 1
operation = actions.first || :show
amount = options.__hash__[operation]
if operation == :show
results do
if cartridges.length == 0
display_cart_storage_list rest_app.cartridges
else
check_cartridges(cartridge, :from => rest_app.cartridges).each do |cart|
display_cart_storage_info cart, cart.display_name
end
end
end
else
raise RHC::MultipleCartridgesException,
'Exactly one cartridge must be specified for this operation' if cartridges.length != 1
rest_cartridge = check_cartridges(cartridge, :from => rest_app.cartridges).first
amount = amount.match(/^(\d+)(GB)?$/i)
raise RHC::AdditionalStorageValueException if amount.nil?
amount = amount[1].to_i
total_amount = rest_cartridge.additional_gear_storage
if operation == :add
total_amount += amount
elsif operation == :remove
if amount > total_amount && !options.force
raise RHC::AdditionalStorageRemoveException
else
total_amount = [total_amount - amount, 0].max
end
else
total_amount = amount
end
say "Set storage on cartridge ... "
cart = rest_cartridge.set_storage(:additional_gear_storage => total_amount)
success "set to #{total_amount}GB"
paragraph{ display_cart_storage_info cart }
end
0
end
|