Here is a little workaround I came up with, put a hidden field with a value specific for that catalog item then do the preprocess based on that value. Dont know if there is a better way of doing. Also having the JSON env data in the script looks ugly. Please suggest any cleaner way of doing this.
require 'json'
#
# Description: This method prepares arguments and parameters for orchestration provisioning
#
$evm.log("info", "Starting Orchestration Pre-Provisioning")
service = $evm.root["service_template_provision_task"].destination
# Through service you can examine the orchestration template, manager (i.e., provider)
# stack_name, and options to create the stack
# You can also override these selections through service
envdata = ' {
"image": {
"dev": {
"rhel": "rhel-7.3-35.x86_64",
"Windows": "Windows Image"
}
},
"private_net_id": {
"dev": "191dc33a-ccc8-4624-82d5-78da86400390"
},
"private_subnet_id": {
"dev": "3adbc77d-8962-4605-8e32-9fcbbc872e9e"
},
"public_subnet_id": {
"dev": "191dc33a-ccc8-4624-82d5-78da86400390"
}
}
'
env_parsed=JASON.parse(envdata) #returns a hash
$evm.log("info", "manager = #{service.orchestration_manager.name}(#{service.orchestration_manager.id})")
$evm.log("info", "template = #{service.orchestration_template.name}(#{service.orchestration_template.id}))")
$evm.log("info", "stack name = #{service.stack_name}")
if $evm.root['dialog_App'] == "anstwr1"
#in anstwr1
env = $evm.root['dialog_param_env']
$evm.log(:info, "Environment = \'#{env}\'")
if env == "dev"
stack_options[:parameters]['image'] = env_parsed["image"][env]["rhel"]
stack_options[:parameters]['private_net_id'] = env_parsed["private_net_id"]["env"]
stack_options[:parameters]['private_subnet_id'] = env_parsed["private_subnet_id"]["env"]
stack_options[:parameters]['public_subnet_id'] = env_parsed["public_subnet_id"]["env"]
else
exit MIQ_ERROR
end
end
# Caution: stack_options may contain passwords.
# $evm.log(“info”, “stack options = #{service.stack_options.inspect}”)
# Example how to programmatically modify stack options:
# service.stack_name = 'new_name'
# stack_options = service.stack_options
# stack_options[:disable_rollback] = false
# stack_options[:timeout_mins] = 2 # this option is provider dependent
# stack_options[:parameters]['flavor'] = 'm1.small'
# # Important: set stack_options
# service.stack_options = stack_options