Sharing information between service catalog items

Posted by Christian Jung on Thu, Dec 17, 2015
In CloudForms, IT, ManageIQ
Tags

In case of a deployment of an multi tiered application, it is often necessary to store information which was generated while provisioning the first VM, so it can be retrieved during provisioning of the following VMs.

A simple example could be a service catalog bundle consisting of one DB VM and two application servers. The two application servers have to be configured to use the previously created DB.

One way to store and retrieve this information, is to use the parent miq_request object. The following code block is doing this:

  db_ip = $evm.root['miq_provision'].miq_request.get_option(:db_ip)
  if db_ip.nil?
    $evm.log("info", "#{@method} - Storing IP address #{vm.ipaddresses[0]} in db_ip for later use")
    $evm.root['miq_provision'].miq_request.set_option(:db_ip,vm.ipaddresses[0])
  else
    $evm.log("info", "#{@method} - db_ip is #{db_ip}")
  end

As you can see, the option db_ip is only set, if it was nil. This should make it easier to reuse the same code in all provisioning state machines, but only set the db_ip while provisioning the (first) Database instance.

When creating the service catalog bundle, it is important to make sure, the DB Instance is created first. The application servers are second - and since they do not depend on each, they can be deployed in parallel, to speed up the overall process.

To retreive the db_ip during provisioning of the applicatin servers, this code block can be used:

db_ip = $evm.root['miq_provision'].miq_request.get_option(:db_ip)
if not db_ip.nil?
  $evm.log("info", "#{@method} - Found db_ip #{db_ip} and storing it for later...")
  prov.set_option(:db_ip,db_ip)
end

If this is added in the customize_request method, the following methods can retrieve the db_ip by using

db_ip = prov.get_option(:db_ip)

Retrieving the IP from the miq_request and storing it in the prov.options is optional. However, storing the information in the provisioning object is more efficient, if the variable is needed in multiple methods.