API use case commands and scripts
Sample script parsers
The Delphix Use Cases scripts provided use the native operating system "curl" command and then a JSON parser, depending on the engine on which you are runnning the scripts.
For Unix/Linux/Mac, the scripts provided use both native shell commands and/or the jq parser program commands. Subroutines have been provided for both methods:
Native Shell commands: parseJSON_subroutines.sh
jq Parser commands: jqJSON_subroutines.sh
For Windows, the scripts are for Powershell 2.0 and utilitze the custom ConvertFrom-Json20
and ConvertTo-Json20
functions provided. As noted, with Powershell 3.0, there are ConvertFrom-Json
and ConvertTo-Json
command-lets provided by Powershell.
Using the jq parser
These are some of the jq commands used within the scripts. The first is a shell script subroutine which is used for finding and returning a single item value.
Filename: jqJSON_subroutines.sh
Subroutines
This code requires the jq Linux/Mac JSON parser program
jqParse() {
STR=$1 # json string
FND=$2 # name to find
RESULTS="" # returned name value
RESULTS=`echo $STR | jq --raw-output '.'"$FND"''`
#echo "Results: ${RESULTS}"
if [ "${FND}" == "status" ] && [ "${RESULTS}" != "OK" ]
then
echo "Error: Invalid Satus, please check code ... ${STR}"
exit 1;
elif [ "${RESULTS}" == "" ]
then
echo "Error: No Results ${FND}, please check code ... ${STR}"
exit 1;
fi
echo "${RESULTS}"
}
The subroutine is called from the shell script to return values based on the key (or name) value provided.
Usage – After every curl command, check that the returned status value is "OK".
RESULTS=$( jqParse "${STATUS}" "status" )
Call the jqParse subroutine, where
${STATUS} is the returned JSON string from the curl command, and
the value we want returned is where the name/key is equal to "status"
Usage – Get a single value within the returned nested result object:
JOBSTATE=$( jqParse "${JOB_STATUS}" "result.jobState" )
Call the jqParse subroutine, where
${JOB_STATUS} is the returned JSON string from the cURL command, and
the value we want returned is where the name/key is equal to "jobState" with the nested ".result" object.
Usage – Find name/value result object and return another value within the select result object:
Use jq to parse out container reference for name of $SOURCE_SID ...
CONTAINER_REFERENCE=`echo ${STATUS} | jq --raw-output '.result[] | select(.name=="'"${SOURCE_SID}"'") | .reference '`
where
${STATUS} is the returned JSON string from the cURL command, and
the value we want returned is based on the selected nested result object where the .result[].name is equal to "${SOURCE_SID}" and return the .reference value for the selected result object.
Delphix engine use cases
Delphix user session timeout
Some activities can take longer than the default 30 minute session timeout value. Therefore, the following script allows you to change the timeout value using the RESTFul API. As always, you can change it easily through the CLI.
This code is the first example showing how object references are used for input (either JSON or URL) into API calls. The name will be the DE_USER variable value delphix_admin. The object reference that the code identifies is USER-2, which in this case is passed into the API URL to update the user parameters passed via the JSON string.
Filename: user_timeout.sh
Edit the file to update the parameters as required for your environment.
#####################
# DELPHIX CORP #
#####################
#Parameter Initialization
DMIP=172.16.160.195
#DMPORT=8282
DMUSER=delphix_admin
DMPASS=delphix
COOKIE="~/cookies.txt"
COOKIE=`eval echo $COOKIE`
CONTENT_TYPE="Content-Type: application/json"
BaseURL="http://${DMIP}/resources/json/delphix"
#
Required for user timeout ...
#
DE_USER="delphix_admin" # Delphix Engine User
DE_TIMEOUT=120 # Timeout integer in minutes
#############################################
# NO CHANGES REQUIRED BELOW THIS POINT #
#############################################
Sample Output
$ ./user_timeout.sh # or ./user_timeout_jq.sh
Authenticating on http://172.16.160.195/resources/json/delphix
Session and Login Successful ...
user reference: USER-2
Update delphix_admin session timeout value to 120 minutes ...
Returned JSON: {"type":"OKResult","status":"OK","result":"","job":null,"action":"ACTION-423"}
Results: OK
Done ...
$
VDB Init (start | stop | enable | disable | status | delete)
This script is used to start, stop, enable, disable, and delete a Delphix platform source object. Typically, this is done on a virtual databases (VDBs), but you can use it for dSources as well.
The vdb_init.sh
and vdb_operations.sh
require the "jq" command line json parser.
Filename: vdb_init.sh
The vdb_init.sh
supports the start, stop, enable, disable, status, and delete command line options.
$ ./vdb_init.sh something VBITT
. . .
Unknown option (start | stop | enable | disable | status | delete): something
Exiting ...
$ ./vdb_init.sh status VBITT
database container reference: ORACLE_DB_CONTAINER-121
source reference: ORACLE_VIRTUAL_SOURCE-25
Runtime Status: "INACTIVE"
Enabled: true
Done ...
$ ./vdb_init.sh start VBITT
database container reference: ORACLE_DB_CONTAINER-121
source reference: ORACLE_VIRTUAL_SOURCE-25
Job: JOB-894
Current status as of Wed Sep 7 16:04:04 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 7 16:04:14 EDT 2016 : RUNNING 25% Completed
Current status as of Wed Sep 7 16:04:24 EDT 2016 : RUNNING 45% Completed
Job: JOB-894 COMPLETED 100% Completed ...
Done ...
$ ./vdb_init.sh delete VBITT
database container reference: ORACLE_DB_CONTAINER-123
source reference: ORACLE_VIRTUAL_SOURCE-27
vendor source: OracleVirtualSource
delete parameters type: OracleDeleteParameters
Job: JOB-927
Current status as of Sat Sep 10 12:55:32 EDT 2016 : RUNNING 0% Completed
Current status as of Sat Sep 10 12:55:32 EDT 2016 : RUNNING 0% Completed
Job: JOB-927 COMPLETED 100% Completed ...
Done ...
VDB operations (sync, refresh, rollback)
This script is used to perform a sync (snapshot), refresh, or rollback (reset) on the Delphix Engine source object. All these work on a virtual databases (VDBs), but only a sync operation can be used on dSources.
The vdb_init.sh
and vdb_operations.sh
require the "jq" command line json parser.
Filename: vdb_operations.sh
$ ./vdb_operations.sh sync VBITT
Session and Login Successful ...
database container reference: ORACLE_DB_CONTAINER-131
provision source container: ORACLE_DB_CONTAINER-129
json> {
"type": "OracleSyncParameters"
}
Job: JOB-998
Current status as of Wed Sep 14 17:05:00 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 14 17:05:24 EDT 2016 : RUNNING 97% Completed
Job: JOB-998 COMPLETED 100% Completed ...
Done ...
Rollback rewinds the virtual database back to the last point in time within the source TimeFlow.
$ ./vdb_operations.sh rollback VBITT
Session and Login Successful ...
database container reference: ORACLE_DB_CONTAINER-131
provision source container: ORACLE_DB_CONTAINER-129
json> {
"type": "OracleRollbackParameters",
"timeflowPointParameters": {
"type": "TimeflowPointSemantic",
"container": "ORACLE_DB_CONTAINER-131"
}
}
Job: JOB-1000
Current status as of Wed Sep 14 17:06:33 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 14 17:06:43 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 14 17:06:53 EDT 2016 : RUNNING 34% Completed
Current status as of Wed Sep 14 17:07:03 EDT 2016 : RUNNING 34% Completed
Current status as of Wed Sep 14 17:07:13 EDT 2016 : RUNNING 58% Completed
Current status as of Wed Sep 14 17:07:23 EDT 2016 : RUNNING 67% Completed
Current status as of Wed Sep 14 17:07:33 EDT 2016 : RUNNING 70% Completed
Current status as of Wed Sep 14 17:07:43 EDT 2016 : RUNNING 70% Completed
Current status as of Wed Sep 14 17:07:53 EDT 2016 : RUNNING 71% Completed
Current status as of Wed Sep 14 17:08:03 EDT 2016 : RUNNING 72% Completed
Current status as of Wed Sep 14 17:08:13 EDT 2016 : RUNNING 73% Completed
Current status as of Wed Sep 14 17:08:23 EDT 2016 : RUNNING 94% Completed
Current status as of Wed Sep 14 17:08:33 EDT 2016 : RUNNING 96% Completed
Current status as of Wed Sep 14 17:08:43 EDT 2016 : RUNNING 96% Completed
Current status as of Wed Sep 14 17:08:53 EDT 2016 : RUNNING 96% Completed
Job: JOB-1000 COMPLETED 100% Completed ...
Done ...
Refresh recreates the virtual database to the last point in time in the respective parent, provision source TimeFlow.
$ ./vdb_operations.sh refresh VBITT
Session and Login Successful ...
database container reference: ORACLE_DB_CONTAINER-131
provision source container: ORACLE_DB_CONTAINER-129
json> {
"type": "OracleRefreshParameters",
"timeflowPointParameters": {
"type": "TimeflowPointSemantic",
"container": "ORACLE_DB_CONTAINER-129"
}
}
Job: JOB-1005
Current status as of Wed Sep 14 17:10:11 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 14 17:10:21 EDT 2016 : RUNNING 0% Completed
Current status as of Wed Sep 14 17:10:31 EDT 2016 : RUNNING 34% Completed
Current status as of Wed Sep 14 17:10:41 EDT 2016 : RUNNING 35% Completed
Current status as of Wed Sep 14 17:10:51 EDT 2016 : RUNNING 70% Completed
Current status as of Wed Sep 14 17:11:01 EDT 2016 : RUNNING 70% Completed
Current status as of Wed Sep 14 17:11:20 EDT 2016 : RUNNING 72% Completed
Current status as of Wed Sep 14 17:11:31 EDT 2016 : RUNNING 73% Completed
Current status as of Wed Sep 14 17:11:41 EDT 2016 : RUNNING 73% Completed
Job: JOB-1005 COMPLETED 100% Completed ...
Done ...