Class: MiqAeMethodService::MiqAeServiceVmOrTemplate

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

Direct Known Subclasses

MiqAeServiceMiqTemplate, MiqAeServiceVm

Constant Summary collapse

METHODS_WITH_NO_ARGS =
%w(start stop suspend unregister collect_running_processes shutdown_guest standby_guest reboot_guest)

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

Instance Method Summary collapse

Methods included from MiqAeServiceRetirementMixin

#retirement_state=, #retirement_warn=, #retires_on=

Methods included from MiqAeServiceEmsOperationsMixin

#sync_or_async_ems_operation

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

Instance Method Details

#ems_custom_get(key) ⇒ Object


119
120
121
122
123
124
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 119

def ems_custom_get(key)
  ar_method do
    c1 = @object.ems_custom_attributes.find_by(:name => key.to_s)
    c1.try(:value)
  end
end

#ems_custom_keysObject


113
114
115
116
117
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 113

def ems_custom_keys
  ar_method do
    @object.ems_custom_attributes.collect(&:name)
  end
end

#ems_custom_set(attribute, value) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 126

def ems_custom_set(attribute, value)
  _log.info "Setting EMS Custom Key on #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}> with key=#{attribute.inspect} to #{value.inspect}"
  MiqQueue.put(
    :class_name  => @object.class.name,
    :instance_id => @object.id,
    :method_name => 'set_custom_field',
    :zone        => @object.my_zone,
    :role        => 'ems_operations',
    :args        => [attribute, value]
  )
  true
end

#ems_ref_stringObject

Used to return string object instead of VimString to automate methods which end up with a DrbUnknow object.


90
91
92
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 90

def ems_ref_string
  object_send(:ems_ref)
end

#group=(group) ⇒ Object

Raises:

  • (ArgumentError)

149
150
151
152
153
154
155
156
157
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 149

def group=(group)
  raise ArgumentError, "group must be nil or a MiqAeServiceMiqGroup" unless group.nil? || group.kind_of?(MiqAeMethodService::MiqAeServiceMiqGroup)

  ar_method do
    @object.miq_group = group && group.instance_variable_get("@object")
    _log.info "Setting EVM Owning Group on #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}> to #{@object.miq_group.inspect}"
    @object.save
  end
end

#migrate(host, pool = nil, priority = "defaultPriority", state = nil) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 62

def migrate(host, pool = nil, priority = "defaultPriority", state = nil)
  raise "Host Class must be MiqAeServiceHost, but is <#{host.class.name}>" unless host.kind_of?(MiqAeServiceHost)
  raise "Pool Class must be MiqAeServiceResourcePool, but is <#{pool.class.name}>" unless pool.nil? || pool.kind_of?(MiqAeServiceResourcePool)

  args = []
  args << host['id']
  args << (pool.nil? ? nil : pool['id'])
  args << priority
  args << state

  MiqQueue.put(
    :class_name  => @object.class.name,
    :instance_id => @object.id,
    :method_name => 'migrate_via_ids',
    :zone        => @object.my_zone,
    :role        => 'ems_operations',
    :args        => args
  )
  true
end

#ownerObject


83
84
85
86
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 83

def owner
  evm_owner = object_send(:evm_owner)
  wrap_results(evm_owner)
end

#owner=(owner) ⇒ Object

Raises:

  • (ArgumentError)

139
140
141
142
143
144
145
146
147
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 139

def owner=(owner)
  raise ArgumentError, "owner must be nil or a MiqAeServiceUser" unless owner.nil? || owner.kind_of?(MiqAeMethodService::MiqAeServiceUser)

  ar_method do
    @object.evm_owner = owner && owner.instance_variable_get("@object")
    _log.info "Setting EVM Owning User on #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}> to #{@object.evm_owner.inspect}"
    @object.save
  end
end

#remove_from_disk(sync = true) ⇒ Object


159
160
161
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 159

def remove_from_disk(sync = true)
  sync_or_async_ems_operation(sync, "vm_destroy", [])
end

#remove_from_vmdbObject


94
95
96
97
98
99
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 94

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

#scan(scan_categories = nil) ⇒ Object


101
102
103
104
105
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 101

def scan(scan_categories = nil)
  options = scan_categories.nil? ? {} : {:categories => scan_categories}
  job = object_send(:scan, "system", options)
  wrap_results(job)
end

107
108
109
110
111
# File 'lib/miq_automation_engine/service_models/miq_ae_service_vm_or_template.rb', line 107

def unlink_storage
  _log.info "Unlinking storage on #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}>"
  object_send(:update_attributes, :storage_id => nil)
  true
end