Skip to content

Commit

Permalink
Merge pull request #12602 from gmcculloug/custom_attributes_service_m…
Browse files Browse the repository at this point in the history
…odel

Expose custom_attribute methods to ext_management_system service model.
(cherry picked from commit bd01f6e)

https://bugzilla.redhat.com/show_bug.cgi?id=1410851
mkanoor authored and simaishi committed Jan 6, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 976c94d commit f52d2b3
Showing 7 changed files with 24 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -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
19 changes: 3 additions & 16 deletions lib/miq_automation_engine/service_models/miq_ae_service_host.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
@@ -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]

19 changes: 3 additions & 16 deletions lib/miq_automation_engine/service_models/miq_ae_service_user.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
Original file line number Diff line number Diff line change
@@ -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
@@ -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)

Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f52d2b3

Please sign in to comment.