Class: MiqAeMethodService::MiqAeServiceService

Inherits:
MiqAeServiceModelBase show all
Includes:
MiqAeServiceCustomAttributeMixin, MiqAeServiceRetirementMixin
Defined in:
lib/miq_automation_engine/service_models/miq_ae_service_service.rb

Constant Summary collapse

CREATE_ATTRIBUTES =
[:name, :description, :service_template]

Constants inherited from MiqAeServiceModelBase

MiqAeMethodService::MiqAeServiceModelBase::DELIMS, MiqAeMethodService::MiqAeServiceModelBase::EXPOSED_ATTR_BLACK_LIST, MiqAeMethodService::MiqAeServiceModelBase::SERVICE_MODEL_GLOB, MiqAeMethodService::MiqAeServiceModelBase::SERVICE_MODEL_PATH, MiqAeMethodService::MiqAeServiceModelBase::UNWISE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MiqAeServiceRetirementMixin

#retirement_state=, #retirement_warn=, #retires_on=

Methods inherited from MiqAeServiceModelBase

ar_base_model, ar_method, #ar_method, association, association=, associations, #associations, base_class, base_model, inherited, #initialize, #inspect, #inspect_all, method_missing, #method_missing, model_name_from_active_record_model, model_name_from_file, #model_suffix, normalize, #object_class, #object_send, #reload, respond_to_missing?, service_models, #tag_assign, #tag_unassign, #taggable?, taggable?, #tagged_with?, #tags, #virtual_column_names, #virtual_columns_inspect, wrap_results, #wrap_results

Methods included from Vmdb::Logging

#_log

Methods included from MiqAeServiceObjectCommon

#[], #[]=, #attributes, #attributes=, #class_name, #current_field_name, #current_field_type, #current_message, #decrypt, #id, #instance_name, #name, #namespace, #parent

Constructor Details

This class inherits a constructor from MiqAeMethodService::MiqAeServiceModelBase

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MiqAeMethodService::MiqAeServiceModelBase

Class Method Details

.create(options = {}) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 28

def self.create(options = {})
  attributes = options.symbolize_keys.slice(*CREATE_ATTRIBUTES)
  if attributes[:service_template]
    raise ArgumentError, "service_template must be a MiqAeServiceServiceTemplate" unless
      attributes[:service_template].kind_of?(MiqAeMethodService::MiqAeServiceServiceTemplate)
    attributes[:service_template] = ServiceTemplate.find(attributes[:service_template].id)
  end
  ar_method { MiqAeServiceModelBase.wrap_results(Service.create!(attributes)) }
end

Instance Method Details

#description=(new_description) ⇒ Object


61
62
63
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 61

def description=(new_description)
  ar_method { @object.update_attribute(:description, new_description) }
end

#dialog_optionsObject


38
39
40
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 38

def dialog_options
  @object.options[:dialog] || {}
end

#display=(display) ⇒ Object


65
66
67
68
69
70
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 65

def display=(display)
  ar_method do
    @object.display = display
    @object.save
  end
end

#get_dialog_option(key) ⇒ Object


42
43
44
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 42

def get_dialog_option(key)
  dialog_options[key]
end

#group=(group) ⇒ Object


103
104
105
106
107
108
109
110
111
112
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 103

def group=(group)
  if group.nil? || group.kind_of?(MiqAeMethodService::MiqAeServiceMiqGroup)
    if group.nil?
      @object.miq_group = nil
    else
      @object.miq_group = MiqGroup.find_by_id(group.id)
    end
    @object.save
  end
end

#name=(new_name) ⇒ Object


54
55
56
57
58
59
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 54

def name=(new_name)
  ar_method do
    @object.name = new_name
    @object.save
  end
end

#owner=(owner) ⇒ Object


85
86
87
88
89
90
91
92
93
94
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 85

def owner=(owner)
  if owner.nil? || owner.kind_of?(MiqAeMethodService::MiqAeServiceUser)
    if owner.nil?
      @object.evm_owner = nil
    else
      @object.evm_owner = User.find_by_id(owner.id)
    end
    @object.save
  end
end

#parent_service=(service) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 72

def parent_service=(service)
  ar_method do
    if service
      raise ArgumentError, "service must be a MiqAeServiceService" unless service.kind_of?(
        MiqAeMethodService::MiqAeServiceService)
      @object.service = Service.find(service.id)
    else
      @object.service = nil
    end
    @object.save
  end
end

#remove_from_vmdbObject


96
97
98
99
100
101
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 96

def remove_from_vmdb
  _log.info "Removing #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}>"
  object_send(:destroy)
  @object = nil
  true
end

#set_dialog_option(key, value) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/miq_automation_engine/service_models/miq_ae_service_service.rb', line 46

def set_dialog_option(key, value)
  ar_method do
    @object.options[:dialog] ||= {}
    @object.options[:dialog][key] = value
    @object.update_attribute(:options, @object.options)
  end
end