-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a concern for storing and accessing default embedded ansible obje…
…ct ids This will allow us to determine the ansible side object to relate new objects to. This also frees us from having to store an extra flag in our inventory to identify which objects are the "system created" ones and which are the other objects that may be artifacts of running jobs. https://www.pivotaltracker.com/story/show/140098929
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/models/manageiq/providers/embedded_ansible/provider/default_ansible_objects.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module ManageIQ::Providers::EmbeddedAnsible::Provider::DefaultAnsibleObjects | ||
extend ActiveSupport::Concern | ||
|
||
ANSIBLE_OBJECT_SOURCE = "MIQ_ANSIBLE".freeze | ||
|
||
included do | ||
has_many :default_ansible_objects, -> { where(:source => ANSIBLE_OBJECT_SOURCE) }, :as => :resource, :dependent => :destroy, :class_name => "CustomAttribute" | ||
end | ||
|
||
def default_organization | ||
get_default_ansible_object("organization") | ||
end | ||
|
||
def default_credential | ||
get_default_ansible_object("credential") | ||
end | ||
|
||
def default_inventory | ||
get_default_ansible_object("inventory") | ||
end | ||
|
||
def default_host | ||
get_default_ansible_object("host") | ||
end | ||
|
||
def default_organization=(org) | ||
set_default_ansible_object("organization", org) | ||
end | ||
|
||
def default_credential=(cred) | ||
set_default_ansible_object("credential", cred) | ||
end | ||
|
||
def default_inventory=(inv) | ||
set_default_ansible_object("inventory", inv) | ||
end | ||
|
||
def default_host=(host) | ||
set_default_ansible_object("host", host) | ||
end | ||
|
||
def delete_ansible_object(name) | ||
default_ansible_objects.find_by(:name => name).try(:delete) | ||
end | ||
|
||
private | ||
|
||
def get_default_ansible_object(name) | ||
default_ansible_objects.find_by(:name => name).try(:value).try(:to_i) | ||
end | ||
|
||
def set_default_ansible_object(name, value) | ||
default_ansible_objects.find_or_initialize_by(:name => name).update_attributes(:value => value) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters