Class: Wakame::Service::CloudHost

Inherits:
Wakame::StatusDB::Model show all
Defined in:
lib/wakame/service.rb

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Method Summary collapse

Methods inherited from Wakame::StatusDB::Model

#delete, #dirty?, #id, inherited, #new_record?, #on_after_delete, #on_after_load, #on_before_delete, #on_before_load, #reload, #save

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Instance Method Details

#agentObject



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_ipObject



284
285
286
# File 'lib/wakame/service.rb', line 284

def agent_ip
  self.agent.agent_ip
end

#assigned_resourcesObject



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_servicesObject



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

Returns:

  • (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

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


229
230
231
# File 'lib/wakame/service.rb', line 229

def mapped?
  !self.agent_id.nil?
end

#reported_servicesObject



276
277
278
# File 'lib/wakame/service.rb', line 276

def reported_services
  self.agent.reported_services
end

#root_pathObject



280
281
282
# File 'lib/wakame/service.rb', line 280

def root_path
  self.agent.root_path
end

#statusObject

Delegate methods for Agent class



272
273
274
# File 'lib/wakame/service.rb', line 272

def status
  self.agent.status
end

#unmap_agentObject



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_saveObject



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_specObject



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