Custom Hostname Generation using ABX in vRealize Automation 8

 

 To accomplish this, first, add the following to the “inputs” section of your blueprint’s YAML: 

"For new naming requirements, we will implement custom scripting code to generate our hostname. vRealize Automation provides us with the ability to subscribe to events that allow us to execute code during various lifecycle events. In this particular case, we will use this capability to execute a custom Python-based ABX function during the “Compute allocation” event of the provisioning lifecycle. This event triggers before the allocation of the compute resource."

inputs:
  Hostname:
    type: string 

Then pass the input as a Cloud Machine property

  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      hostname: '${input.Hostname}'

Now for ABX use below code and Create Event Subscription for Compute Allocation:-

" click on Extensibility from the top of the screen, then select Subscriptions from the left side. Click the + NEW SUBSCRIPTION button.Provide a name for the subscription such as “Resource Name Customization on Compute Allocation”. For the Event Topic field, click on the + ADD button, select the “Compute allocation” event from the list of event topics, then click the SELECT button. Next, for the Runnable Item field, click the + ADD button, select the ABX action that you created, then click the SELECT button. Next, ensure that you enable the Blocking option so that Cloud Assembly won’t move forward until the new name is generated. For the Recovery runnable item, select your ABX action again. Finally, click the CREATE button to create our new event subscription."

def handler(context, inputs):
    outputs = {}
    new_name = inputs["customProperties"]["hostname"]
    outputs["resourceNames"] = inputs["resourceNames"]
    outputs["resourceNames"][0] = new_name

    return outputs