Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose custom_attribute methods to ext_management_system service model. #12602

Merged
merged 1 commit into from Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,6 +2,8 @@ module MiqAeMethodService
class MiqAeServiceExtManagementSystem < MiqAeServiceModelBase
require_relative "mixins/miq_ae_service_inflector_mixin"
include MiqAeServiceInflectorMixin
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :storages, :association => true
expose :hosts, :association => true
Expand Down
19 changes: 3 additions & 16 deletions lib/miq_automation_engine/service_models/miq_ae_service_host.rb
@@ -1,5 +1,8 @@
module MiqAeMethodService
class MiqAeServiceHost < MiqAeServiceModelBase
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :storages, :association => true
expose :read_only_storages
expose :writable_storages
Expand Down Expand Up @@ -73,22 +76,6 @@ def ems_custom_set(attribute, value)
true
end

def custom_keys
object_send(:miq_custom_keys)
end

def custom_get(key)
object_send(:miq_custom_get, key)
end

def custom_set(key, value)
ar_method do
@object.miq_custom_set(key, value)
@object.save
end
value
end

def ssh_exec(script)
object_send(:ssh_run_script, script)
end
Expand Down
@@ -1,24 +1,11 @@
module MiqAeMethodService
class MiqAeServiceMiqGroup < MiqAeServiceModelBase
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :users, :association => true
expose :vms, :association => true
expose :tenant, :association => true
expose :filters, :method => :get_filters

def custom_keys
object_send(:miq_custom_keys)
end

def custom_get(key)
object_send(:miq_custom_get, key)
end

def custom_set(key, value)
ar_method do
@object.miq_custom_set(key, value)
@object.save
end
value
end
end
end
Expand Up @@ -2,6 +2,8 @@ module MiqAeMethodService
class MiqAeServiceService < MiqAeServiceModelBase
require_relative "mixins/miq_ae_service_retirement_mixin"
include MiqAeServiceRetirementMixin
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :retire_service_resources
expose :automate_retirement_entrypoint
Expand All @@ -20,9 +22,6 @@ class MiqAeServiceService < MiqAeServiceModelBase
expose :indirect_service_children, :association => true
expose :parent_service, :association => true
expose :tenant, :association => true
expose :custom_keys, :method => :miq_custom_keys
expose :custom_get, :method => :miq_custom_get
expose :custom_set, :method => :miq_custom_set, :override_return => true

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

Expand Down
19 changes: 3 additions & 16 deletions lib/miq_automation_engine/service_models/miq_ae_service_user.rb
@@ -1,5 +1,8 @@
module MiqAeMethodService
class MiqAeServiceUser < MiqAeServiceModelBase
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :current_group, :association => true
expose :current_tenant, :association => true
expose :vms, :association => true
Expand Down Expand Up @@ -28,22 +31,6 @@ def get_ldap_attribute(name)
end
end

def custom_keys
object_send(:miq_custom_keys)
end

def custom_get(key)
object_send(:miq_custom_get, key)
end

def custom_set(key, value)
ar_method do
@object.miq_custom_set(key, value)
@object.save
end
value
end

def miq_group
$miq_ae_logger.warn("[DEPRECATION] #{self.class.name}#miq_group accessor is deprecated. Please use current_group instead. At #{caller[0]}")
current_group
Expand Down
Expand Up @@ -6,6 +6,8 @@ class MiqAeServiceVmOrTemplate < MiqAeServiceModelBase
include MiqAeServiceRetirementMixin
require_relative "mixins/miq_ae_service_inflector_mixin"
include MiqAeServiceInflectorMixin
require_relative "mixins/miq_ae_service_custom_attribute_mixin"
include MiqAeServiceCustomAttributeMixin

expose :ext_management_system, :association => true
expose :storage, :association => true
Expand Down Expand Up @@ -134,23 +136,6 @@ def ems_custom_set(attribute, value)
true
end

def custom_keys
object_send(:miq_custom_keys)
end

def custom_get(key)
object_send(:miq_custom_get, key)
end

def custom_set(key, value)
_log.info "Setting EVM Custom Key on #{@object.class.name} id:<#{@object.id}>, name:<#{@object.name}> with key=#{key.inspect} to #{value.inspect}"
ar_method do
@object.miq_custom_set(key, value)
@object.save
end
value
end

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

Expand Down
@@ -0,0 +1,9 @@
module MiqAeServiceCustomAttributeMixin
extend ActiveSupport::Concern

included do
expose :custom_keys, :method => :miq_custom_keys
expose :custom_get, :method => :miq_custom_get
expose :custom_set, :method => :miq_custom_set, :override_return => true
end
end