Class: RHC::Rest::Cartridge
- Inherits:
-
Base
show all
- Defined in:
- lib/rhc/rest/cartridge.rb
Constant Summary
collapse
- HIDDEN_TAGS =
[:framework, :web_framework, :cartridge].map(&:to_s)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_message, #has_param?, #initialize, #link_href, #links, #rest_method, #supports?
#define_attr, #model_name
Methods included from Attributes
#attribute, #attributes, #attributes=, #clear_attribute
Class Method Details
.for_url(url) ⇒ Object
149
150
151
|
# File 'lib/rhc/rest/cartridge.rb', line 149
def self.for_url(url)
new 'url' => url
end
|
Instance Method Details
#<=>(other) ⇒ Object
133
134
135
136
137
|
# File 'lib/rhc/rest/cartridge.rb', line 133
def <=>(other)
return -1 if other.type == 'standalone' && type != 'standalone'
return 1 if type == 'standalone' && other.type != 'standalone'
name <=> other.name
end
|
#additional_gear_storage ⇒ Object
41
42
43
|
# File 'lib/rhc/rest/cartridge.rb', line 41
def additional_gear_storage
attribute(:additional_gear_storage).to_i rescue 0
end
|
#collocated_with ⇒ Object
29
30
31
|
# File 'lib/rhc/rest/cartridge.rb', line 29
def collocated_with
Array(attribute(:collocated_with))
end
|
#connection_info ⇒ Object
128
129
130
131
|
# File 'lib/rhc/rest/cartridge.rb', line 128
def connection_info
info = property(:cart_data, :connection_url) || property(:cart_data, :job_url) || property(:cart_data, :monitoring_url)
info ? (info["value"] || '').rstrip : nil
end
|
#custom? ⇒ Boolean
14
15
16
|
# File 'lib/rhc/rest/cartridge.rb', line 14
def custom?
url.present?
end
|
#destroy ⇒ Object
Also known as:
delete
111
112
113
114
|
# File 'lib/rhc/rest/cartridge.rb', line 111
def destroy
debug "Deleting cartridge #{name}"
rest_method "DELETE"
end
|
#display_name ⇒ Object
45
46
47
|
# File 'lib/rhc/rest/cartridge.rb', line 45
def display_name
attribute(:display_name) || name || url_basename
end
|
#gear_storage ⇒ Object
37
38
39
|
# File 'lib/rhc/rest/cartridge.rb', line 37
def gear_storage
(base_gear_storage + additional_gear_storage) * 1024 * 1024 * 1024
end
|
#only_in_existing? ⇒ Boolean
22
23
24
|
# File 'lib/rhc/rest/cartridge.rb', line 22
def only_in_existing?
type == 'embedded'
end
|
#only_in_new? ⇒ Boolean
18
19
20
|
# File 'lib/rhc/rest/cartridge.rb', line 18
def only_in_new?
type == 'standalone'
end
|
#property(type, key) ⇒ Object
80
81
82
83
|
# File 'lib/rhc/rest/cartridge.rb', line 80
def property(type, key)
key, type = key.to_s, type.to_s
properties.select{ |p| p['type'] == type }.find{ |p| p['name'] == key }
end
|
106
107
108
109
|
# File 'lib/rhc/rest/cartridge.rb', line 106
def reload
debug "Reloading cartridge #{name}"
rest_method "RESTART", :event => "reload"
end
|
101
102
103
104
|
# File 'lib/rhc/rest/cartridge.rb', line 101
def restart
debug "Restarting cartridge #{name}"
rest_method "RESTART", :event => "restart"
end
|
#scalable? ⇒ Boolean
10
11
12
|
# File 'lib/rhc/rest/cartridge.rb', line 10
def scalable?
supported_scales_to != supported_scales_from
end
|
71
72
73
74
75
76
77
78
|
# File 'lib/rhc/rest/cartridge.rb', line 71
def scaling
{
:current_scale => current_scale,
:scales_from => scales_from,
:scales_to => scales_to,
:gear_profile => gear_profile,
} if scalable?
end
|
#set_scales(values) ⇒ Object
117
118
119
120
121
|
# File 'lib/rhc/rest/cartridge.rb', line 117
def set_scales(values)
values.delete_if{|k,v| v.nil? }
debug "Setting scales = %s" % values.map{|k,v| "#{k}: #{v}"}.join(" ")
rest_method "UPDATE", values
end
|
#set_storage(values) ⇒ Object
123
124
125
126
|
# File 'lib/rhc/rest/cartridge.rb', line 123
def set_storage(values)
debug "Setting additional storage: #{values[:additional_gear_storage]}GB"
rest_method "UPDATE", values
end
|
#shares_gears? ⇒ Boolean
26
27
28
|
# File 'lib/rhc/rest/cartridge.rb', line 26
def shares_gears?
Array(collocated_with).present?
end
|
#short_name ⇒ Object
Use this value when the user should interact with this cart via CLI arguments
52
53
54
|
# File 'lib/rhc/rest/cartridge.rb', line 52
def short_name
name || url
end
|
91
92
93
94
|
# File 'lib/rhc/rest/cartridge.rb', line 91
def start
debug "Starting cartridge #{name}"
rest_method "START", :event => "start"
end
|
85
86
87
88
89
|
# File 'lib/rhc/rest/cartridge.rb', line 85
def status
debug "Getting cartridge #{name}'s status"
result = rest_method "GET", :include => "status_messages"
result.status_messages
end
|
96
97
98
99
|
# File 'lib/rhc/rest/cartridge.rb', line 96
def stop
debug "Stopping cartridge #{name}"
rest_method "STOP", :event => "stop"
end
|
33
34
35
|
# File 'lib/rhc/rest/cartridge.rb', line 33
def tags
Array(attribute(:tags))
end
|
#url_basename ⇒ Object
139
140
141
142
143
144
145
146
147
|
# File 'lib/rhc/rest/cartridge.rb', line 139
def url_basename
uri = URI.parse(url)
name = uri.fragment
name = Rack::Utils.parse_nested_query(uri.query)['name'] if name.blank? && uri.query
name = File.basename(uri.path) if name.blank? && uri.path.present? && uri.path != '/'
name.presence || url
rescue
url
end
|
#usage_rate ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/rhc/rest/cartridge.rb', line 61
def usage_rate
rate = attribute(:usage_rate_usd)
if attribute(:usage_rates)
rate ||= attribute(:usage_rates).inject(0) { |total, rate| total + rate['usd'].to_f }
end
rate.to_f rescue 0.0
end
|
#usage_rate? ⇒ Boolean
56
57
58
59
|
# File 'lib/rhc/rest/cartridge.rb', line 56
def usage_rate?
rate = usage_rate
rate && rate > 0.0
end
|