Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare to move OrchestrationTemplate to each provider
Move the template classes to the corresponding provider repository. This is a step before the migration. https://bugzilla.redhat.com/show_bug.cgi?id=1417021
- Loading branch information
Showing
5 changed files
with
423 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
131 changes: 131 additions & 0 deletions
131
app/models/manageiq/providers/openstack/cloud_manager/orchestration_template.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,131 @@ | ||
class ManageIQ::Providers::Openstack::CloudManager::OrchestrationTemplate < ::OrchestrationTemplate | ||
def parameter_groups | ||
content_hash = YAML.load(content) | ||
raw_groups = content_hash["parameter_groups"] | ||
|
||
if raw_groups | ||
indexed_parameters = parameters(content_hash).index_by(&:name) | ||
raw_groups.collect do |raw| | ||
OrchestrationTemplate::OrchestrationParameterGroup.new( | ||
:label => raw["label"], | ||
:description => raw["description"], | ||
# Map each parameter name to its corresponding object | ||
:parameters => raw["parameters"].collect { |name| indexed_parameters[name] } | ||
) | ||
end | ||
else | ||
# Create a single group to include all parameters | ||
[OrchestrationTemplate::OrchestrationParameterGroup.new( | ||
:label => "Parameters", | ||
:parameters => parameters(content_hash) | ||
)] | ||
end | ||
end | ||
|
||
def parameters(content_hash = nil) | ||
content_hash = YAML.load(content) unless content_hash | ||
(content_hash["parameters"] || {}).collect do |key, val| | ||
OrchestrationTemplate::OrchestrationParameter.new( | ||
:name => key, | ||
:label => val.key?('label') ? val['label'] : key.titleize, | ||
:data_type => val['type'], | ||
:default_value => val['default'], | ||
:description => val['description'], | ||
:hidden => val['hidden'] == true, | ||
:constraints => val.key?('constraints') ? parse_constraints(val['constraints']) : nil, | ||
:required => true | ||
) | ||
end | ||
end | ||
|
||
def deployment_options(_manager_class = nil) | ||
onfailure_opt = OrchestrationTemplate::OrchestrationParameter.new( | ||
:name => "stack_onfailure", | ||
:label => "On Failure", | ||
:data_type => "string", | ||
:description => "Select what to do if stack creation failed", | ||
:constraints => [ | ||
OrchestrationTemplate::OrchestrationParameterAllowed.new( | ||
:allowed_values => {'ROLLBACK' => 'Rollback', 'DO_NOTHING' => 'Do nothing'} | ||
) | ||
] | ||
) | ||
|
||
timeout_opt = OrchestrationTemplate::OrchestrationParameter.new( | ||
:name => "stack_timeout", | ||
:label => "Timeout(minutes, optional)", | ||
:data_type => "integer", | ||
:description => "Abort the creation if it does not complete in a proper time window", | ||
) | ||
|
||
super << onfailure_opt << timeout_opt | ||
end | ||
|
||
def self.eligible_manager_types | ||
[ManageIQ::Providers::Openstack::CloudManager] | ||
end | ||
|
||
# return the parsing error message if not valid JSON; otherwise nil | ||
def validate_format | ||
YAML.parse(content) && nil if content | ||
rescue Psych::SyntaxError => err | ||
err.message | ||
end | ||
|
||
private | ||
|
||
def parse_constraints(raw_constraints) | ||
raw_constraints.collect do |raw_constraint| | ||
if raw_constraint.key?('allowed_values') | ||
parse_allowed_values(raw_constraint) | ||
elsif raw_constraint.key?('allowed_pattern') | ||
parse_pattern(raw_constraint) | ||
elsif raw_constraint.key?('length') | ||
parse_length_constraint(raw_constraint) | ||
elsif raw_constraint.key?('range') | ||
parse_value_constraint(raw_constraint) | ||
elsif raw_constraint.key?('custom_constraint') | ||
parse_custom_constraint(raw_constraint) | ||
else | ||
raise MiqException::MiqParsingError, _("Unknown constraint %{constraint}") % {:constraint => raw_constraint} | ||
end | ||
end | ||
end | ||
|
||
def parse_allowed_values(hash) | ||
OrchestrationTemplate::OrchestrationParameterAllowed.new( | ||
:allowed_values => hash['allowed_values'], | ||
:description => hash['description'] | ||
) | ||
end | ||
|
||
def parse_pattern(hash) | ||
OrchestrationTemplate::OrchestrationParameterPattern.new( | ||
:pattern => hash['allowed_pattern'], | ||
:description => hash['description'] | ||
) | ||
end | ||
|
||
def parse_length_constraint(hash) | ||
OrchestrationTemplate::OrchestrationParameterLength.new( | ||
:min_length => hash['length']['min'], | ||
:max_length => hash['length']['max'], | ||
:description => hash['description'] | ||
) | ||
end | ||
|
||
def parse_value_constraint(hash) | ||
OrchestrationTemplate::OrchestrationParameterRange.new( | ||
:min_value => hash['range']['min'], | ||
:max_value => hash['range']['max'], | ||
:description => hash['description'] | ||
) | ||
end | ||
|
||
def parse_custom_constraint(hash) | ||
OrchestrationTemplate::OrchestrationParameterCustom.new( | ||
:custom_constraint => hash['custom_constraint'], | ||
:description => hash['description'] | ||
) | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
app/models/manageiq/providers/openstack/cloud_manager/vnfd_template.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,69 @@ | ||
class ManageIQ::Providers::Openstack::CloudManager::VnfdTemplate < ::OrchestrationTemplate | ||
belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::CloudManager" | ||
|
||
before_create :raw_create, :if => :remote_proxy? | ||
before_update :raw_update, :if => :remote_proxy? | ||
before_destroy :raw_destroy, :if => :remote_proxy? | ||
|
||
def raw_create | ||
vnfd_data = {:attributes => {:vnfd => content}, | ||
:service_types => [{:service_type => "vnfd"}], | ||
:mgmt_driver => "noop", | ||
:infra_driver => "heat"} | ||
|
||
vnfd_data[:name] = name unless name.blank? | ||
vnfd_data[:description] = description unless description.blank? | ||
|
||
connection_options = {:service => "NFV"} | ||
ext_management_system.with_provider_connection(connection_options) do |service| | ||
self.ems_ref = service.vnfds.create(:vnfd => vnfd_data, :auth => {}).id | ||
end | ||
end | ||
|
||
def raw_update | ||
# Tacker does not have an update call | ||
raw_destroy && raw_create | ||
end | ||
|
||
def raw_destroy | ||
connection_options = {:service => "NFV"} | ||
ext_management_system.with_provider_connection(connection_options) do |service| | ||
service.vnfds.get(ems_ref).try(:destroy) | ||
end | ||
end | ||
|
||
def parameter_groups | ||
[] | ||
end | ||
|
||
def parameters | ||
[] | ||
end | ||
|
||
def self.eligible_manager_types | ||
[ManageIQ::Providers::Openstack::CloudManager] | ||
end | ||
|
||
def self.stack_type | ||
"Vnf" | ||
end | ||
|
||
# return the parsing error message if not valid YAML; otherwise nil | ||
def validate_format | ||
YAML.parse(content) && nil if content | ||
rescue Psych::SyntaxError => err | ||
err.message | ||
end | ||
|
||
def unique_md5? | ||
false | ||
end | ||
|
||
def save_as_orderable! | ||
error_msg = validate_format unless draft | ||
raise MiqException::MiqParsingError, error_msg if error_msg | ||
|
||
self.orderable = true | ||
save! | ||
end | ||
end |
Oops, something went wrong.