Prerequisites:
- Have Delphix Self-Service user privileges.
- Know the branch you would like to create the bookmark on.
- Know the container or template that the branch belongs to.
- (Optional) Know when you would like the bookmark to expire.
Delphix Self-Service administrators can use this CLI cookbook recipe to create a bookmark 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.
This script can be downloaded by selecting createBookmark.sh.
Creating a bookmark in Delphix Self-Service
#!/bin/bash # A sample script for calls to the CLI. This one creates a Jet Stream bookmark. # # VERY IMPORTANT: In order for this to work, you need to go through the steps here: # https://docs.delphix.com/display/DOCS43/CLI+Cookbook%3A+Configuring+Key-Based+SSH+Authentication+for+Automation # 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. # ##example## #./createBookmark.sh -e "2016-07-27T23:38:56.453Z" -t "2016-07-27T01:45:56.453Z" -T [tag1,tag2,tag3,tag4,tag5] bkmrk3 JS_BRANCH-41 ##### Constants # Describes a Delphix software revision. VERSION="1.11.10" ##### Default Values. These can be overwriten with optional arguments. engine="ars-6010.dlpxdc.co" username="admin" ##### Functions # Help Menu function usage { echo "Usage: createBookmark.sh [[-h] | options...] <bookmark name> <branch name format JS_BRANCH-n>" echo "Create a Jet Stream Bookmark on the given branch." echo "" echo "Positional arguments" echo " <bookmark name> " echo " <branch name>" 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 " -D Description of this bookmark. Type: string" echo " -s Pass [-s true] if need to make bookmark in shared mode" echo " -e The time at which the bookmark should be expired" echo " -t The time at which the bookmark should be created. If no time is included, the bookmark will be created at the latest point in time. Type: date, must be in ISO 8601 extended format [yyyy]-[MM]-[dd]T[HH]:[mm]:[ss].[SSS]Z" echo " -T A set of user-defined labels for this bookmark. No spaces allowed. Array of Type: string. In format, [tag1,tag2,..] " } # 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 get_branch { echo "retrieveing branch $branchRef to find Source Data Layout..." result=$(${SSH_CMD} "selfservice branch; ls; select ${branchRef}; ls") # Get everything in the result that comes after dataLayout. temp=${result#*dataLayout: } # Get rid of everything after dataLayout=${temp%% *} } function create_bookmark { get_branch echo "creating bookmark..." # If there is not creation time, we need to use JSTimelinePointLatestTimeInput. if [ -z $creationTime ] then pointParams="set timelinePointParameters.sourceDataLayout=$dataLayout;" pointParams="$pointParams set timelinePointParameters.type=JSTimelinePointLatestTimeInput;" else pointParams="set timelinePointParameters.sourceDataLayout=$dataLayout;" pointParams="$pointParams set timelinePointParameters.type=JSTimelinePointTimeInput;" pointParams="$pointParams set timelinePointParameters.time=\"$creationTime\";" pointParams="$pointParams set timelinePointParameters.branch=\"$branchRef\";" fi if [[ -n $expirationTime ]] then pointParams="$pointParams set bookmark.expiration=\"$expirationTime\";" fi # These are the required parameters. paramString=" \"bookmark\": { \"branch\": \"${branchRef}\", \"name\": \"${bookmarkName}\"," paramString="selfservice bookmark; create; set bookmark.name=$bookmarkName; set bookmark.branch=$branchRef;" paramString="$paramString $pointParams" # Fill in optional parameters if there are any. if [[ -n $description ]] then paramString="$paramString set bookmark.description=\"$description\";" fi if [[ -n $shared ]] then paramString="$paramString set bookmark.shared=$shared;" fi if [[ -n $tags ]] then # Add quotes back to the passed in tags so they are processed correctly. tags=${tags//[/[\"} tags=${tags//,/\",\"} tags=${tags//]/\"]} paramString="$paramString set bookmark.tags=$tags;" fi paramString="$paramString commit;" result=$(${SSH_CMD} $paramString) check_result echo "Verifying job status..." # Get everything in the result that comes after job. temp=${result#*job} # Get rid of everything after resultArray=($temp) jobRef=($resultArray) jobString="job;select $jobRef;ls" result=$(${SSH_CMD} $jobString) check_result # Get everything in the result that comes after job. temp=${result#*jobState:} # Get rid of everything after resultArray=($temp) jobState=($resultArray) if [ $jobState = "COMPLETED" ] then echo "successfully created bookmark $bookmarkName" else echo "unable to create bookmark" echo result fi } ##### Main while getopts "u:d:D:s:e:t:T:h" flag; do case "$flag" in u ) username=${OPTARG%:*} ;; d ) engine=$OPTARG ;; D ) description=$OPTARG ;; s ) shared=true ;; t ) creationTime=$OPTARG ;; e ) expirationTime=$OPTARG ;; T ) tags=$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 bookmarkName=$1 shift branchRef=$1 create_session create_bookmark