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
162
163
164
|
# File 'lib/rhc/rest/cartridge.rb', line 162
def self.for_url(url)
new 'url' => url
end
|
Instance Method Details
#<=>(other) ⇒ Object
146
147
148
149
150
|
# File 'lib/rhc/rest/cartridge.rb', line 146
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
54
55
56
|
# File 'lib/rhc/rest/cartridge.rb', line 54
def additional_gear_storage
attribute(:additional_gear_storage).to_i rescue 0
end
|
#automatic_updates? ⇒ Boolean
27
28
29
30
31
32
33
|
# File 'lib/rhc/rest/cartridge.rb', line 27
def automatic_updates?
v = attribute(:automatic_updates)
if v.nil?
v = !(tags.include?('no_updates') || custom?)
end
v
end
|
#collocated_with ⇒ Object
42
43
44
|
# File 'lib/rhc/rest/cartridge.rb', line 42
def collocated_with
Array(attribute(:collocated_with))
end
|
#connection_info ⇒ Object
141
142
143
144
|
# File 'lib/rhc/rest/cartridge.rb', line 141
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
15
16
17
|
# File 'lib/rhc/rest/cartridge.rb', line 15
def custom?
url.present?
end
|
#destroy ⇒ Object
Also known as:
delete
124
125
126
127
|
# File 'lib/rhc/rest/cartridge.rb', line 124
def destroy
debug "Deleting cartridge #{name}"
rest_method "DELETE"
end
|
#display_name ⇒ Object
58
59
60
|
# File 'lib/rhc/rest/cartridge.rb', line 58
def display_name
attribute(:display_name) || name || url_basename
end
|
#external? ⇒ Boolean
35
36
37
|
# File 'lib/rhc/rest/cartridge.rb', line 35
def external?
tags.include?('external')
end
|
#gear_storage ⇒ Object
50
51
52
|
# File 'lib/rhc/rest/cartridge.rb', line 50
def gear_storage
(base_gear_storage + additional_gear_storage) * 1024 * 1024 * 1024
end
|
#only_in_existing? ⇒ Boolean
23
24
25
|
# File 'lib/rhc/rest/cartridge.rb', line 23
def only_in_existing?
type == 'embedded'
end
|
#only_in_new? ⇒ Boolean
19
20
21
|
# File 'lib/rhc/rest/cartridge.rb', line 19
def only_in_new?
type == 'standalone'
end
|
#property(type, key) ⇒ Object
93
94
95
96
|
# File 'lib/rhc/rest/cartridge.rb', line 93
def property(type, key)
key, type = key.to_s, type.to_s
properties.select{ |p| p['type'] == type }.find{ |p| p['name'] == key }
end
|
119
120
121
122
|
# File 'lib/rhc/rest/cartridge.rb', line 119
def reload
debug "Reloading cartridge #{name}"
rest_method "RESTART", :event => "reload"
end
|
114
115
116
117
|
# File 'lib/rhc/rest/cartridge.rb', line 114
def restart
debug "Restarting cartridge #{name}"
rest_method "RESTART", :event => "restart"
end
|
#scalable? ⇒ Boolean
11
12
13
|
# File 'lib/rhc/rest/cartridge.rb', line 11
def scalable?
supported_scales_to != supported_scales_from
end
|
84
85
86
87
88
89
90
91
|
# File 'lib/rhc/rest/cartridge.rb', line 84
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
130
131
132
133
134
|
# File 'lib/rhc/rest/cartridge.rb', line 130
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
136
137
138
139
|
# File 'lib/rhc/rest/cartridge.rb', line 136
def set_storage(values)
debug "Setting additional storage: #{values[:additional_gear_storage]}GB"
rest_method "UPDATE", values
end
|
#shares_gears? ⇒ Boolean
39
40
41
|
# File 'lib/rhc/rest/cartridge.rb', line 39
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
65
66
67
|
# File 'lib/rhc/rest/cartridge.rb', line 65
def short_name
name || url
end
|
104
105
106
107
|
# File 'lib/rhc/rest/cartridge.rb', line 104
def start
debug "Starting cartridge #{name}"
rest_method "START", :event => "start"
end
|
98
99
100
101
102
|
# File 'lib/rhc/rest/cartridge.rb', line 98
def status
debug "Getting cartridge #{name}'s status"
result = rest_method "GET", :include => "status_messages"
result.status_messages
end
|
109
110
111
112
|
# File 'lib/rhc/rest/cartridge.rb', line 109
def stop
debug "Stopping cartridge #{name}"
rest_method "STOP", :event => "stop"
end
|
46
47
48
|
# File 'lib/rhc/rest/cartridge.rb', line 46
def tags
Array(attribute(:tags))
end
|
#url_basename ⇒ Object
152
153
154
155
156
157
158
159
160
|
# File 'lib/rhc/rest/cartridge.rb', line 152
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
74
75
76
77
78
79
80
81
82
|
# File 'lib/rhc/rest/cartridge.rb', line 74
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
69
70
71
72
|
# File 'lib/rhc/rest/cartridge.rb', line 69
def usage_rate?
rate = usage_rate
rate && rate > 0.0
end
|