-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring the available_flavors method for the automate Cloud Orche…
…stration.
- Loading branch information
Showing
1 changed file
with
57 additions
and
17 deletions.
There are no files selected for viewing
74 changes: 57 additions & 17 deletions
74
...re/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.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 |
---|---|---|
@@ -1,26 +1,66 @@ | ||
# | ||
# Description: provide the dynamic list content from available flavors | ||
# | ||
flavor_list = {} | ||
service = $evm.root.attributes["service_template"] || $evm.root.attributes["service"] | ||
if service.respond_to?(:orchestration_manager) && service.orchestration_manager | ||
service.orchestration_manager.flavors.each { |f| flavor_list[f.name] = f.name } | ||
end | ||
flavor_list[nil] = flavor_list.empty? ? "<None>" : "<Choose>" | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module Orchestration | ||
module Operations | ||
class AvailableFlavors | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
fill_dialog_field(fetch_selected_os) | ||
end | ||
|
||
def fetch_selected_os | ||
flavor_list = {} | ||
service = $evm.root.attributes["service_template"] || $evm.root.attributes["service"] | ||
if service.respond_to?(:orchestration_manager) && service.orchestration_manager | ||
service.orchestration_manager.flavors.each { |f| flavor_list[f.name] = f.name } | ||
end | ||
flavor_list[nil] = flavor_list.empty? ? "<None>" : "<Choose>" | ||
|
||
|
||
service = @handle.root.attributes["service_template"] || @handle.root.attributes["service"] | ||
flavors = service.try(:orchestration_manager).try(:flavors) | ||
|
||
flavor_list = {} | ||
flavor_list.each { |f| flavor_list[f.name] = f.name } if flavors | ||
|
||
dialog_field = $evm.object | ||
return nil => "<None>" if flavor_list.blank? | ||
|
||
# sort_by: value / description / none | ||
dialog_field["sort_by"] = "description" | ||
flavor_list[nil] = "<Choose>" if flavor_list.length > 1 | ||
flavor_list | ||
end | ||
|
||
# sort_order: ascending / descending | ||
dialog_field["sort_order"] = "ascending" | ||
def fill_dialog_field(list) | ||
dialog_field = @handle.object | ||
|
||
# data_type: string / integer | ||
dialog_field["data_type"] = "string" | ||
# sort_by: value / description / none | ||
dialog_field["sort_by"] = "description" | ||
|
||
# required: true / false | ||
dialog_field["required"] = "true" | ||
# sort_order: ascending / descending | ||
dialog_field["sort_order"] = "ascending" | ||
|
||
dialog_field["values"] = flavor_list | ||
dialog_field["default_value"] = nil | ||
# data_type: string / integer | ||
dialog_field["data_type"] = "string" | ||
|
||
# required: true / false | ||
dialog_field["required"] = "true" | ||
|
||
dialog_field["values"] = list | ||
dialog_field["default_value"] = nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Cloud::Orchestration::Operations::AvailableFlavors.new.main | ||
end |