Class: Wakame::Service::CloudHost
Constant Summary
AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES
Instance Method Summary
collapse
#delete, #dirty?, #id, inherited, #new_record?, #on_after_delete, #on_after_load, #on_before_delete, #on_before_load, #reload, #save
#dump_attrs, #retrieve_attr_attribute
Instance Method Details
#agent ⇒ Object
258
259
260
261
|
# File 'lib/wakame/service.rb', line 258
def agent
raise "#{self.class}: Agent is not mapped yet to this cloud host \"#{self.id}\"." unless mapped?
Agent.find(self.agent_id) || raise("#{self.class}: Could not find the mapped agent for #{self.class}.id=\"#{self.id}\"")
end
|
#agent_ip ⇒ Object
284
285
286
|
# File 'lib/wakame/service.rb', line 284
def agent_ip
self.agent.agent_ip
end
|
#assigned_resources ⇒ Object
302
303
304
305
306
|
# File 'lib/wakame/service.rb', line 302
def assigned_resources()
assigned_services.map { |svc_id|
ServiceInstance.find(svc_id).resource
}.uniq
end
|
#assigned_services ⇒ Object
297
298
299
300
|
# File 'lib/wakame/service.rb', line 297
def assigned_services()
cluster = ServiceCluster.find(self.cluster_id)
cluster.services.keys.find_all { |svc_id| ServiceInstance.find(svc_id).cloud_host_id == self.id }
end
|
#has_resource_type?(key) ⇒ Boolean
288
289
290
291
292
293
294
295
|
# File 'lib/wakame/service.rb', line 288
def has_resource_type?(key)
res_id = key.is_a?(ServiceInstance) ? key.resource.id : Resource.id(key)
assigned_services.any? { |k|
svc = ServiceInstance.find(k)
svc.resource.id == res_id
}
end
|
#map_agent(agent) ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/wakame/service.rb', line 233
def map_agent(agent)
raise ArgumentError unless agent.is_a?(Agent)
raise "Ensure to call unmap_agent() prior to mapping new agent" if self.mapped?
raise "The agent \"#{agent.id}\" is already mapped to the cloud host: #{agent.cloud_host_id}" if agent.mapped?
self.agent_id = agent.id
agent.cloud_host_id = self.id
self.save
agent.save
end
|
#mapped? ⇒ Boolean
229
230
231
|
# File 'lib/wakame/service.rb', line 229
def mapped?
!self.agent_id.nil?
end
|
#reported_services ⇒ Object
276
277
278
|
# File 'lib/wakame/service.rb', line 276
def reported_services
self.agent.reported_services
end
|
#root_path ⇒ Object
280
281
282
|
# File 'lib/wakame/service.rb', line 280
def root_path
self.agent.root_path
end
|
#status ⇒ Object
Delegate methods for Agent class
272
273
274
|
# File 'lib/wakame/service.rb', line 272
def status
self.agent.status
end
|
#unmap_agent ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/wakame/service.rb', line 245
def unmap_agent()
if mapped?
agent = Agent.find(self.agent_id)
if agent && self.agent_id == agent.id
agent.cloud_host_id = nil
agent.save
end
self.agent_id = nil
self.save
end
end
|
#validate_on_save ⇒ Object
308
309
310
|
# File 'lib/wakame/service.rb', line 308
def validate_on_save
raise "#{self.class}.cluster_id property can't be nil." if self.cluster_id.nil?
end
|
#vm_spec ⇒ Object
263
264
265
266
267
|
# File 'lib/wakame/service.rb', line 263
def vm_spec
spec = VmSpec.current
spec.table = self.vm_attr
spec
end
|