Jet Stream administrators can use this api cookbook recipe to create a database template on Jet Stream using the Delphix Engine API.

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

The following script can be downloaded by selecting createDBTemplate.sh.

Create Jet Stream Database Template

#!/bin/bash

# A sample script for calls to the API. This one creates a Jet Stream Template.

##### Constants

# Describes a Delphix software revision.
# Please change version are per your Delphix Engine CLI, if different
VERSION="1.8.0"

##### Default Values. These can be overwriten with optional arguments.
engine="172.16.151.154"
username="delphix_admin"
password="landshark"

##examples##
# Create template with mandatory params
#./createBranch.sh -d 172.16.151.154 -u delphix_admin:landshark -n <sourceName> <templateName> <containerName>
#Ex ./createBranch.sh -d 172.16.151.154 -u delphix_admin:landshark -n oraclesrc template1 ORACLE_DB_CONTAINER-191
# 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 USER:PASSWORD  Server user and password, 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
{
	# Pulling the version into parts. The {} are necessary for string manipulation.
	# Strip out longest match following "."  This leaves only the major version.
	major=${VERSION%%.*}
	# Strip out the shortest match preceding "." This leaves minor.micro.
	minorMicro=${VERSION#*.}
	# Strip out the shortest match followint "." This leaves the minor version.
	minor=${minorMicro%.*}
	# Strip out the longest match preceding "." This leaves the micro version.
	micro=${VERSION##*.}

	# Quick note about the <<-. If the redirection operator << is followed by a - (dash), all leading TAB from the document data will be 
	# ignored. This is useful to have optical nice code also when using here-documents. Otherwise you must have the EOF be on a line by itself, 
	# no parens, no tabs or anything.

	echo "creating session..."
	result=$(curl -s -S -X POST -k --data @- http://${engine}/resources/json/delphix/session \
		-c ~/cookies.txt -H "Content-Type: application/json" <<-EOF
	{
		"type": "APISession",
		"version": {
			"type": "APIVersion",
			"major": $major,
			"minor": $minor,
			"micro": $micro
		}
	}
	EOF)

	check_result
}

# Authenticate the DE for the provided user.
function authenticate_de
{
	echo "authenticating delphix engine..."
	echo ${engine}
    echo ${username}
    echo ${password}
	result=$(curl -s -S -X POST -k --data @- http://${engine}/resources/json/delphix/login \
		-b ~/cookies.txt -H "Content-Type: application/json" <<-EOF
	{
		"type": "LoginRequest",
		"username": "${username}",
		"password": "${password}"
	}
	EOF)	

	check_result
}

function create_template
{       
   
   paramString="\"type\": \"JSDataTemplateCreateParameters\",\"name\": \"$templateName\","
   
   if [[ -n $templatenotes ]]
    then
       paramString="$paramString \"notes\": \"$templatenotes\","    
   fi         
                
    paramString="$paramString \"dataSources\": [{\"type\": \"JSDataSourceCreateParameters\",
                              \"container\": \"$sourceContainer\",
                              \"source\": {\"type\": \"JSDataSource\",
                              \"priority\": 1,
                              \"name\": \"$sourcename\""    
                                    
   if [[ -n $sourcedesc ]]
    then
       paramString="$paramString ,\"description\": \"$sourcedesc\"}}]"  
    else 
       paramString="$paramString }}]"
   fi         
       
	result=$(curl -s -X POST -k --data @- http://${engine}/resources/json/delphix/jetstream/template \
	    -b ~/cookies.txt -H "Content-Type: application/json" <<-EOF
	{
	    $paramString
	}
	EOF)
	
	check_result
	
	echo "New JetStream template $templateName successfully created"
	
}

# 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"
	    exit 1
	elif [[ $result != *"OKResult"* ]]
	then
		echo ""
		echo $result
		exit 1
	fi
}

##### Main

while getopts "u:d:n:N:D:h" flag; do
	case "$flag" in
    	u )             username=${OPTARG%:*}
						password=${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
  echo "usage1"
	usage
	exit 1
fi

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

create_session
authenticate_de
create_template