Skip to content

Commit

Permalink
Refactoring the available_flavors method for the automate Cloud Orche…
Browse files Browse the repository at this point in the history
…stration.
  • Loading branch information
pkomanek committed Nov 17, 2016
1 parent 9699fcc commit e68519a
Showing 1 changed file with 57 additions and 17 deletions.
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

0 comments on commit e68519a

Please sign in to comment.