API/Python/Open-Source Solutions

Expand all | Collapse all

Delphix automation using REST

  • 1.  Delphix automation using REST

    Posted 02-14-2019 04:39:00 PM
    Hi,
    I am new to using REST.  I am confortable using delphix CLI to sutomate. However , can't see what is wrong with my rest program. 

    Here is the code :

    ---------------------------------------------------------------------------------------------------------------
    #!/bin/ksh

    # Create API session
    echo "Initiate Session "

    curl -s -S -X POST -k --data @- http://10.64.148.77/resources/json/delphix/session \
    -c ~/cookies.txt -H "Content-Type: application/json" <<EOF
    {
     "type": "APISession",
     "version": {
     "type": "APIVersion",
     "major": 1,
     "minor": 7,
     "micro": 0
     }
    }
    EOF


    echo "Initiated Session"

    # login
    curl -s -S -X POST -k --data @- http://10.64.148.77/resources/json/delphix/login \
     -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
    {
     "type": "LoginRequest",
     "username": "amathe01",
     "password": djsdlfjdo_23"
    }
    EOF


    # List ENV
    echo "\n\n List Env Information"
    curl -S -X GET -k http://10.64.148.77/resources/json/delphix/environment \
     -b ~/cookies.txt -H "Content-Type: application/json"

    ---------------------------------------------------------------------------------------------------------
    Problem:
    ------------

    When executing the script it only executed the first CURL and returns to command prompt. 
    However, I can execute each command from the script on the command line and get the 
    expected output. What am I missing?

    Here is the output :
    Initiate Session
    {"type":"OKResult","status":"OK","result":{"type":"APISession","version":{"type":"APIVersion","major":1,"minor":7,"micro":0},"locale":null,"client":null},"job":null,"action":null}


    A second question. Is there way not to send clear test password to the login request? Delphix CLI provides an encryption mecahnism. 

    Thanks in advance !


    #Virtualization


  • 2.  RE: Delphix automation using REST

    Posted 02-14-2019 05:04:00 PM
    Start by looking at my example here:https://community.delphix.com/delphix/topics/provision-a-oracle-vdb-through-api-call

    To your second question, you are using curl in your rest calls. Here is an article that speaks to how to pass passwords to curl commands: https://stackoverflow.com/questions/2594880/using-curl-with-a-username-and-password

    You would also need toResearch how toUse SSL with curl If you don't want to transmit information in plaintext.

    If you're just doing some ad hoc scripts for yourself,Then maybe this is worthwhile.But, if you're going to do actual enterprise automation,You should really look into using a robust programming language like Python or golang


  • 3.  RE: Delphix automation using REST

    Posted 02-14-2019 05:47:00 PM
    Thank you Adam ! Perfect !!