CLI cookbook: how to create a Delphix self-service database template

Delphix Self-Service administrators can use this CLI cookbook recipe to create a database template on Delphix Self-Service using the Delphix Engine CLI.

The following script is for educational and demonstration purposes only and is not supported by Delphix.

Download script:

Creating a database template in Delphix Self-Service

Copy
#!/bin/bash

# A sample script for calls to the CLI. This one creates a Jet Stream Template.
#
# VERY IMPORTANT: In order for this to work, you need to go through the steps here:
# https://help.delphix.com/cd/current/content/CLI_cookbook_configuring_key_based_SSH_authentication_for_automation.htm
# After this you will not need to use a username and password to log into the delphix engine. If you do not
# setup the SSH authentication you will have to manually enter the password.
#

##### Constants

# Describes a Delphix software revision.
VERSION="1.11.10"  # Default Values. These can be overwritten with optional arguments.
engine="ars-6010.dlpxdc.co"
username="admin"
# Examples
# Create template with mandatory params
# Create template with adding optional params, Notes and Description
# ./createDBTemplate.sh -n <sourceName> -N "<templateNotes>" -D "<AnyDescription>" <templateName> <containerName>
## NOTE: This script is to add one source per template and it will not add any properties for template, container or source.

##### Functions

# Help Menu
function usage {
    echo "Usage: createDBTemplate.sh [[-h] | options...] <template_name> <source_container>"
    echo "Create a Jet Stream Dat Template."
    echo ""
    echo "Positional arguments"
    echo "  <template_name>"
    echo "  <source_container>"
    echo ""
    echo "Optional Arguments:"
    echo "  -h                Show this message and exit"
    echo "  -d                Delphix engine IP address or host name, otherwise revert to default"
    echo "  -u        Server user. Password needs to manually provide at run time, otherwise revert to default"
    echo "  -n                source name to display on JS template screen" 
    echo "  -N                template notes, if any. Type: String"
    echo "  -D                source description, if any. Type: String"}

# Create Our Session, including establishing the API version.
function create_session
{
    echo "creating session..."    SSH_CMD="ssh ${username}@${engine}"    ${SSH_CMD}  "version $VERSION"    check_result
}

# Check the result of the curl. If there are problems, inform the user then exit.
function check_result
{
    exitStatus=$?
    if [ $exitStatus -ne 0 ]
    then
        echo "command failed with exit status $exitStatus"        echo $result    
        exit 1
    fi
}

function create_template
{  
    paramString="selfservice template create;set name=$templateName;"    if [[ -n $templatenotes ]]
        then
           paramString="$paramString set notes=\"$templatenotes\";"    fi
    paramString="$paramString edit dataSources;add;"    
    paramString="$paramString set container=$sourceContainer;set source.name=$sourcename;set source.priority=1;"
    if [[ -n $sourcedesc ]]
    then
       paramString="$paramString set source.description=\"$sourcedesc\";"  
    fi
    paramString="$paramString commit;"    #echo $paramString
    echo "Creating Data Template..."    result=$(${SSH_CMD}  $paramString)
    check_result
    echo "New JetStream template $templateName successfully created"    
}

##### Main

while getopts "u:d:n:N:D:h" flag; do
    case "$flag" in
        u )             username=${OPTARG%:*}
                        ;;
        d )             engine=$OPTARG
                        ;;
        n )             sourcename=$OPTARG
                        ;;
        N )             templatenotes=$OPTARG
                        ;;                                                              
        D )             sourcedesc=$OPTARG
                        ;;             
        h )             usage
                        exit
                        ;;
        * )             usage
                        exit 1
                    
    esac
done

# Shift the parameters so we only have the positional arguments left
shift $((OPTIND-1))

# Check that there are 2 positional arguments
if [ $# != 2 ]
then
    usage
    exit 1
fi

# Get the two positional arguments
templateName=$1
shift
sourceContainer=$1


create_session
        create_template