Customize HOT template parameters


#1

Hello,

Is it possible to pass custom parameters to heat orchestration API other than the fields in the dialogue? The use case I am thinking about is user picks a value and based on the selection a number of parameters (not visible to the user) are passed to heat. Is this possible? Any document pointers is helpful.

Thanks.


#2

It is doable through coding in automate method. Take a look at Cloud/Orchestration/Orchestration/Provisioning/StateMachine/Methods/preprovision we already have some sample code

                # 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

#3

Bill,

Much thanks. Will report the test outcome.

Thanks,
SN


#4

is there a way to obtain dialog elements in the preprovision method?I want to assign stack options based on the user selection in the dialog.

Thanks,
SN


#5

should I be looking into miq_provision_request_template object for dialog elements?


#6

OK, I think I got it, for others, its documented here:

https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/service_dialogs/chapter.html

section:
“Using the Input from One Element in Another Element’s Dynamic Method”


We can link elements in such a way that a user’s input in one element can be used by subsequent dynamic elements that are refreshable. The subsequent dynamic method, when refreshed, > can access the first element’s input value using $evm.root[‘dialog_elementname’] or $evm.object[‘dialog_elementname’]


#7

Another question, if I customize Cloud/Orchestration/Provisioning/StateMachines/Methods/preprovision for one specific application deployment, how can I use it again for other custom orchestration tasks?

Thanks,
SN


#8

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

#9

Little bit more progress, but now I am stuck with error from heat:

2017-04-05 14:34:23.792 23233 ERROR heat.common.wsgi [req-30311e48-801a-457d-90b9-6727dbe6ff5a fd32f0ce9f174c23b30ffc70d11eaede 25fe84a3a0214be18a3ea0f20404ae77 - default default] Unexpected error occurred serving API: Remote error: Remote error: DiscoveryFailure Could not determine a suitable URL for the plugin

Anyone seen this before?


#10

Here is the complete error message:

shouldn’t the path be starting with /v2/ or /v3/ for keystone auth? Not sure if that is the source of the issue.

[----] E, [2017-04-05T14:33:53.148396 #19839:e286f0] ERROR – : Q-task_id([service_template_provision_task_1000000000015]) MiqAeServiceModelBase.ar_method raised: MiqException::MiqOrchestrationProvisionError: <Expected(201) <=> Actual(500 InternalServerError)
excon.error.response
:body => “{“explanation”: “The server has either erred or is incapable of performing the requested operation.”, “code”: 500, “error”: {“message”: “Remote error: DiscoveryFailure Could not determine a suitable URL for the plugin\n[u’\”, \“traceback\”: null, \“type\”: \“RemoteError\”}, \“title\”: \“Internal Server Error\”}” :cookies => [ ]
:headers => {
“Content-Length” => "301"
“Content-Type” => "application/json; charset=UTF-8"
“Date” => “Wed, 05 Apr 2017 18:34:23 GMT”
“X-Openstack-Request-Id” => “req-30311e48-801a-457d-90b9-6727dbe6ff5a”
}
:host => xxx
:local_address => “10.4.0.21”
:local_port => 43108
:path => "/v1/25fe84a3a0214be18a3ea0f20404ae77/stacks"
:port => 8004
:reason_phrase => “Internal Server Error”
:remote_ip => “10.3.1.6”
:status => 500
:status_line => “HTTP/1.1 500 Internal Server Error\r\n”


#11

@star_night Were you able to make further progress? If you need assistance please post the whole preprovision script.


#12

Bill,

Thank you. The issue is resolved. It was a configuration issue on the OpenStack side.

Thanks,
SN


#13

I need to customize the HOT parameters adding the OpenStack URL and other stuff in prepriovision.rb

I’m creating an openshift-on-openstack stack and, to integrate openshift with openstack, I need to pass the openstack url to the templates installing openshift.

Is there a way to retrieve those informations?

Thx++,
R:


#14

Ok, I found this: https://github.com/pemcg/mastering-automation-in-cloudforms-and-manageiq/blob/master/chapter44.asciidoc#calling-an-openstack-api-using-the-fog-gem but

require 'fog'
raises a
LoadError: cannot load such file -- fog.

Anybody used it?


#15

You can load openstack gem as follows:

require ‘fog/openstack’


#16

Ok! That works :smiley: We should update the doc :smiley: Thx ++ @ProdubanEs