Control auto or manual approval of a service request through validate_request

Recently we learned a use case where request approval should be based on some user inputs from the service dialog. Here is the scenario and how to achieve it through automate code.

Suppose the request is to provision an AWS instance. When the instance flavor is smaller than t2.micro, the request can be auto-approved; otherwise a manual approval is required. There is a field in the service dialog for the user to pick the instance flavor. The dialog field name is InstanceType.

The approval process goes through the state machine at /Service/Provisioning/StateMachines/ServiceProvisionRequestApproval. The default implementation for validate_request is blank, so it moves further to approve_request state. We can override validate_request method to exit the state machine based on the dialog field value so that the request remains in pending status, waiting for a manual approval. The dialog field can be accessed through request’s options property. Note that options is a hash with all dialog fields having a prefix dialog_. In our example dialog field InstanceType has key dialog_InstanceType. Here is the sample code:

# /Service/Provisioning/StateMachines/ServiceProvisionRequestApproval.class/validate_request.rb

$evm.log("info", "Validating request")
miq_request = $evm.root["miq_request"]
dialog_options = miq_request['options'][:dialog]

unless %w(t2.nano t2.micro).include?(dialog_options['dialog_InstanceType'])
  $evm.log("info", "Instance type too big, need a manual approval")
  exit MIQ_STOP
$evm.log("info", "Auto approval validated")

Note this validate_request method applies to all service requests. We can narrow it down to validate only certain service type, for example ServiceTemplateOrchestration:

if miq_request.source.type == "ServiceTemplateOrchestration" && ...
  exit MIQ_STOP

How do you enable the validate_request method. I am new to manageiq and just started using and after updating the validate_request.rb on the box i still dont see it via the Web UI to select in the Provisioning entry point popup.


Are you trying to validate the request of a provisioning service? Once you override the validate_request method it should take effect automatically. You should not need to manually select the entry point. If you still have problem, please describe what kind of provisioning you have tried, and how you did it.

Bill - I appreciate the quick response. I am trying to setup a manual approval process for provisioning on cloud. When i use the /Service/Provisioning/StateMachines/ServiceProvision_Template/CatalogItemInitialization or ServiceProvisionRequestApproval/Default the requests are getting auto approved.

When you override the method you must create a new user domain and keep the same path structure as in ManageIQ. Make sure the user domain is enabled. Can you take a screenshot of the Automate Datastore or upload the log?

1 Like

Bill - Thanks for the tip on creating a new user domain. After i created a new user domain and copied the class and methods from ManageIQ, i saw i could edit them from the UI and set the approval_type to require_approval and that did the trick. I found this and it has a section called Custom Worflows which is nice so i will spend some time reading through this book.

Thanks again for quick responses.