Getting started with Action Scripts

Document created by raven Expert on Jul 29, 2015Last modified by fran.schwarzmann on Aug 15, 2016
Version 2Show Document
  • View in full screen mode

Action scripts allow you to hook into the process of control. You can run a script before, instead of, and after any given action that VMTurbo generates.

 

To enable action scripts, check your license for the following key:

pic.png

If you don't have that key in your license file then drop an email to support@vmturbo.com to have them regenerate your license keys and then apply the new set.

Action scripts can be enabled/disabled on a per-group basis, but where do you set the script name to execute?

The answer.. you don't! VMTurbo will automatically call a script based on the following naming convention for a script placed in the /srv/tomcat/script/control directory:

PRE|POST_ACTION_EntityType.sh

Where ACTION is one of:

START
MOVE
SUSPEND
TERMINATE
SPAWN
ADD_PROVIDER
CHANGE
REMOVE_PROVIDER
PROVISION
RECONFIGURE
RESIZE
RESIZE_CAPACITY
WARN
RECONFIGURE_THRESHOLD
DELETE
RIGHT_SIZE
RESERVE_ON_PM
RESERVE_ON_DS

And EntityType is one of

VirtualApplication
Application
VirtualMachine
PhysicalMachine
Storage
DiskArray
StorageController
Switch
VirtualDatacenter
DataCenter

Examples:
PRE_MOVE_VirtualMachine.sh will be called prior to the move action on a Virtual Machine.
POST_SUSPEND_PhysicalMachine.sh will be called after a suspend action on a Physical Machine

The scripts receive information about the action through the following environment variables:

VMT_TARGET_INTERNAL - The action target internal name.
VMT_TARGET_NAME - The action target display name.
VMT_CURRENT_INTERNAL - The current configuration or placement internal name.
VMT_CURRENT_NAME - The current configuration or placement display name.
VMT_NEW_INTERNAL - The new configuration or placement internal name.
VMT_NEW_NAME - The new configuration or placement display name.
VMT_ACTION_INTERNAL - The action UUID.
VMT_ACTION_NAME - The action name.

You can refer to these variables inside the script using the "$" sign. For example, to get the action target display name, use $VMT_TARGET_NAME.

The following is an example of the content of a MOVE_VirtualMachine.sh script. This script will be executed instead of a virtual machine move action.

It checks if the if the virtual machine to move is hosted on a specific physical machine. If it does then it rejects the action, otherwise it accepts it:

 

#!/bin/bash

OUT=$(curl -s -X GET http://<admin-user>:<admin-password>@localhost/vmturbo/api/markets/Market/virtualmachines/$VMT_TARGET_INTERNAL/resources?resource=CPU.* | grep -E 'provider="<physical-machine-name>"')

if [ "X$OUT" = "X" ]; then

curl -X POST http://<admin-user>:<admin-password>@localhost/vmturbo/api/actionlogs/Market_ActionLog/actionitems/$VMT_ACTION_INTERNAL --data "action=accept" > /dev/null

else

curl -X POST http://<admin-user>:<admin-password>@localhost/vmturbo/api/actionlogs/Market_ActionLog/actionitems/$VMT_ACTION_INTERNAL --data "action=reject" > /dev/null

fi

Attachments

    Outcomes