-
Notifications
You must be signed in to change notification settings - Fork 897
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
add create_catalog_item to ServiceTemplateOrchestration #13628
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,27 @@ class ServiceTemplateOrchestration < ServiceTemplate | |
|
||
before_save :remove_invalid_resource | ||
|
||
def self.create_catalog_item(options, _auth_user = nil) | ||
transaction do | ||
create(options.except(:config_info)).tap do |service_template| | ||
config_info = validate_config_info(options) | ||
|
||
service_template.orchestration_template = if config_info[:template_id] | ||
OrchestrationTemplate.find(config_info[:template_id]) | ||
else | ||
config_info[:template] | ||
end | ||
service_template.orchestration_manager = if config_info[:manager_id] | ||
ExtManagementSystem.find(config_info[:manager_id]) | ||
else | ||
config_info[:manager] | ||
end | ||
|
||
service_template.create_resource_actions(config_info) | ||
end | ||
end | ||
end | ||
|
||
def remove_invalid_resource | ||
# remove the resource from both memory and table | ||
service_resources.to_a.delete_if { |r| r.destroy unless r.resource } | ||
|
@@ -24,4 +45,13 @@ def self.default_reconfiguration_entry_point | |
def my_zone | ||
orchestration_manager.try(:my_zone) || MiqServer.my_zone | ||
end | ||
|
||
def self.validate_config_info(options) | ||
config_info = options[:config_info] | ||
unless (config_info[:template_id] && config_info[:manager_id]) || (config_info[:template] && config_info[:manager]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bzwei should I check for combinations of ids / objects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we should allow the combination. What you have here is likely real. I am ok with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jntullo I would suggest allowing for the different combinations since that would better align with the logic in the |
||
raise _('Must provide both template_id and manager_id or manager and template') | ||
end | ||
config_info | ||
end | ||
private_class_method :validate_config_info | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may simply put
config_info[:template] || OrchestrationTemplate.find(config_info[:template_id])
since we already validate either one must exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei I wanted to, but the line was too long so rubocop wasn't happy, and this was more readable than breaking that up onto two lines imo