APIPythonOpen-Source Solutions

Expand all | Collapse all

How to start with delphix API

Swathy Sukumar

Swathy Sukumar05-17-2017 11:19:00 AM

Swathy Sukumar

Swathy Sukumar05-23-2017 09:49:00 AM

Mouhssine Saidi

Mouhssine Saidi05-23-2017 10:47:00 AM

  • 1.  How to start with delphix API

    Posted 05-17-2017 04:24:00 AM

    Hi Guys,

    I am new to delphix API. Can anyone suggest how to start with the API?




  • 2.  RE: How to start with delphix API

    Posted 05-17-2017 05:50:00 AM
    Hi, Good starting point is the documentation :) https://docs.delphix.com/docs/reference/web-service-api-guide/so-you-want-to-work-with-delphix-apis/delphix-restful-apis-command-line-basics Once you are ready to go with some lines coding try the delphixpy module tutos by Adam Bowen or go to github and look for dxtoolkit Delphix's PS developed tool. Regards, Mouhssine


  • 3.  RE: How to start with delphix API



  • 4.  RE: How to start with delphix API

    Posted 05-17-2017 11:18:00 AM

    Thanks for your response,

    actually we want to use curl here. We are unable to create session with the curl. We got post command from CLI. Now we stuck here how I can use that post command with the curl.

    It is very useful if you can suggest some basics steps.

    Thanks

    Swathy



  • 5.  RE: How to start with delphix API

    Posted 05-17-2017 11:19:00 AM

    Thanks for your response



  • 6.  RE: How to start with delphix API

    Posted 05-17-2017 11:22:00 AM


  • 7.  RE: How to start with delphix API



  • 8.  RE: How to start with delphix API

    Posted 05-17-2017 11:34:00 AM

    Adam,

    I have seen these examples and have curl as well but cant able to authenticate. I  am new to curl also.

    Here examples I have read what I have understood that we are using the restAPI url in the post command and then we are using curl to invoke the seesion.

    For eg we have done VDB provision with CLI so we got the restapi URL for the same. Now i want to know how i can bind with that.

    We downloaded CURL as well.

    Your help is much appreciated.

    Regards,

    Swathy




  • 9.  RE: How to start with delphix API

    Posted 05-17-2017 12:00:00 PM
    Use these examples to create a session and authenticate. This stores the information in the cookies.txt file. 
    https://docs.delphix.com/docs/reference/web-service-api-guide/api-cookbook-common-tasks-workflows-an...


  • 10.  RE: How to start with delphix API

    Posted 05-17-2017 12:04:00 PM
    Full example:

    DEIP="10.0.1.10"
    USER="delphix_admin"
    PASS="landshark"


    # 1) Create Delphix API Session

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


    # 2) Delphix Login

    curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/login \
        -b ~/cookies.txt -H "Content-Type: application/json" <{
        "type": "LoginRequest",
        "username": "${USER}",
        "password": "${PASS}"
    }
    EOF


    echo "+++++++++++++++++++++++++++++++++++"

    # 3) Provision VDB

    curl -X POST -k --data @- http://${DEIP}/resources/json/delphix/database/provision \
        -b cookies.txt -H "Content-Type: application/json" <{ 
        "container": {
            "group": "GROUP-2",
            "name": "EGVDB", 
            "type": "OracleDatabaseContainer"
        },
        "source": {
            "type": "OracleVirtualSource",
            "mountBase": "/mnt/provision",
            "allowAutoVDBRestartOnHostReboot": true
        },
        "sourceConfig": {
            "type": "OracleSIConfig",
            "databaseName": "EGVDB", 
            "uniqueName": "EGVDB", 
            "repository": "ORACLE_INSTALL-3",
            "instance": {
                "type": "OracleInstance",
                "instanceName": "EGVDB",
                "instanceNumber": 1
            }
        },
        "timeflowPointParameters": {
            "type": "TimeflowPointLocation",
            "timeflow": "ORACLE_TIMEFLOW-123",
            "location": "3043123"
        },
        "type": "OracleProvisionParameters"
    }
    EOF


  • 11.  RE: How to start with delphix API

    Posted 05-17-2017 12:07:00 PM
    Hi,

    To complete Adam's answer

    The sample i've provided detailed the values each param used , but you may need to install one more tool like jq to extract specific values out of the engine jason's answer you will need to feed your api call with to achive an action (eg: in the provisioning one you need for example group ref, repository ref ...)

    Regards,

    Mouhssine


  • 12.  RE: How to start with delphix API

    Posted 05-18-2017 09:18:00 AM

    Thanks for your response.

    Do you have any demo with cURL?If you have could share with us. Still I am unable to work.

    Regards,

    Swathy



  • 13.  RE: How to start with delphix API
    Best Answer

    Posted 05-18-2017 09:39:00 AM
    Here is a complete working example. I just tested it.

    #!/bin/bash
    DEIP="10.0.1.10"
    USER="delphix_admin"
    PASS="delphix"

    # 1) Create Delphix API Session
    echo -e "\n\nCreating Session\n"
    curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/session \
        -c ~/cookies.txt -H "Content-Type: application/json" <<EOF
    {
        "type": "APISession",
        "version": {
            "type": "APIVersion",
            "major": 1,
            "minor": 8,
            "micro": 0
        }
    }
    EOF

    # 2) Delphix Login
    echo -e "\n\nLogging in\n"
    curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/login \
        -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
    {
        "type": "LoginRequest",
        "username": "${USER}",
        "password": "${PASS}"
    }
    EOF
    #3) List Databases
    echo -e "\n\nGrabbing list of databases\n"
    curl -X GET -k http://${DEIP}/resources/json/delphix/database  \
        -b ~/cookies.txt -H "Content-Type: application/json"
    echo -e "\n\nCurl Script Complete\n"


  • 14.  RE: How to start with delphix API

    Posted 05-18-2017 09:41:00 AM
    Hi,

    Here is an example i wrot in the past, that need some work to sweet you.

    But please check it befor just copy/past/run it, you will have to change the APIversion and check if you have to add new params itroduced with the new version on the API level 
    #!/bin/bash  DE="192.168.247.XXX"  DELPHIX_ADMIN="delphix_admin"  DELPHIX_PASS="landshark"  VDB=$1  OPT=$2    get_session() {  curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/session \      -c ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "APISession",      "version": {          "type": "APIVersion",          "major": 1,          "minor": 4,          "micro": 3      }  }  EOF  }    do_login() {  curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/login \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "LoginRequest",      "username": "${DELPHIX_ADMIN}",      "password": "${DELPHIX_PASS}"  }  EOF  }    get_params() {  ref='curl -s -X GET -k http://${DE}/resources/json/delphix/database  \      -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .reference''  cont='curl -s -X GET -k http://${DE}/resources/json/delphix/database  \      -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .provisionContainer''  vsrc='curl -s -X GET -k http://${DE}/resources/json/delphix/source  \      -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .reference''  }    do_refresh() {  curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/database/$ref/refresh  \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {         "type": "OracleRefreshParameters",         "timeflowPointParameters": {                 "type": "TimeflowPointSemantic",                 "container": "$cont",                 "location": "LATEST_SNAPSHOT"         }  }    EOF  }    do_snapsync() {  curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/database/$ref/sync  \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {         "type": "OracleSyncParameters"  }    EOF  }    do_start() {    curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/start \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "OracleStartParameters"  }    EOF  }    do_stop() {    curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/stop \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "OracleStopParameters"  }    EOF  }    do_delete() {    curl -s -X POST -k http://${DE}/resources/json/delphix/database/$ref/delete \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "OraclDeleteeParameters"  }    EOF  }    do_enable() {    curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/enable \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "OracleEnableParameters"  }    EOF  }    do_disable() {    curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/disable \      -b ~/cookies.txt -H "Content-Type: application/json" <<EOF  {      "type": "OracleDisableParameters"  }    EOF  }    get_session  do_login  get_params  case $OPT in  start)  do_start  ;;  stop)  do_stop  ;;  refresh)  do_refresh  ;;  snapsync)  do_snapsync  ;;  delete)  do_delete  ;;  enable)  do_enable  ;;  disable)  do_disable  ;;  *)    echo "Unknown option: $OPT"  ;; 
    esac



    Regards,

    Mouhssine


  • 15.  RE: How to start with delphix API

    Posted 05-18-2017 09:43:00 AM
    Hi,

    Make a mixe of both for my base script it will need jq to be installed.


    Regards,

    Mouhssine


  • 16.  RE: How to start with delphix API

    Posted 05-23-2017 09:49:00 AM

    Thank you so much




  • 17.  RE: How to start with delphix API

    Posted 05-23-2017 09:51:00 AM

    Hi Adam,

    Thanks for your response.

    Yes I can able to work with API.

    Here when I want to provision my VDB through API I am getting the below error. Could you suggest the workaround for this:


    {"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":{"source":{"allowAutoVDBRestartOnHostReboot":{"details":"This field is required.","action":null,"id":"exception.validation.field.missing","commandOutput":null,"diagnoses":null}}},"action":"Check your input parameters and try again.","id":"exception.validation.bad.input","commandOutput":null,"diagnoses":null}}

    Thanks in advance

    Regards,

    Swathy




  • 18.  RE: How to start with delphix API

    Posted 05-23-2017 10:47:00 AM
    welcome


  • 19.  RE: How to start with delphix API

    Posted 05-23-2017 10:54:00 AM
    Sure, no problem. You were just missing the parameter specified in the log. It accepts a true or false value. for example: "allowAutoVDBRestartOnHostReboot": true

    I updated my example above to reflect this parameter (it is a new parameter, which is why it was missing from the example)


  • 20.  RE: How to start with delphix API

    Posted 05-23-2017 10:59:00 AM
    Hi Swathy,

    As the error message indecates, you need to add "allowAutoVDBRestartOnHostReboot" as one of the vdb provision parameters and set it to true or false.

    Regards,

    Mouhssine


  • 21.  RE: How to start with delphix API

    Posted 05-24-2017 08:42:00 AM

    Hi Adam,

    I am using the same code still not getting the output


    curl -X POST -k --data @- http://10.130.25.228/resources/json/delphix/database/provision" href="http://$DE/resources/json/delphix/database/provision">http://$DE/resources/json/delphix/database/provision \
        -b cookies.txt -H "Content-Type: application/json" <{
        "container": {
            "group": "GROUP-34",
            "name": "EGVDB",
            "type": "OracleDatabaseContainer"
        },
        "source": {
            "type": "OracleVirtualSource",
            "mountBase": "/mnt/provision",
            "allowAutoVDBRestartOnHostReboot": true
        },
        "sourceConfig": {
            "type": "OracleSIConfig",
            "databaseName": "EGVDB",
            "uniqueName": "EGVDB",
            "repository": "ORACLE_INSTALL-6",
            "instance": {
                "type": "OracleInstance",
                "instanceName": "EGVDB",
                "instanceNumber": 1
            }
        },
        "timeflowPointParameters": {
            "type": "TimeflowPointLocation",
            "timeflow": "ORACLE_TIMEFLOW-38",
            "location": "LATEST_SNAPSHOT"
        },
        "type": "OracleProvisionParameters"
    }
    EOF



  • 22.  RE: How to start with delphix API

    Posted 05-24-2017 09:08:00 AM
    Hi,

    Would you do the following please

    1) Open a browser
    2) open a tab and connect to the admin intefrace of the engine
    3) open a second tab on the same browser and connect tyo this url "http://$DEIP/resources/json/delphix/database" replace $DEIP with the ip of your engine
    4) Search for the ligne with "GROUP-34" and copy/pat the out put pleas from the json output or upload the full output to the community website

    Regards,

    Mouhssine


  • 23.  RE: How to start with delphix API

    Posted 05-24-2017 10:50:00 AM

    Hi Mouhssine

    below error we got it:

    {"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":"The reference \"Group-34\" is invalid or of the incorrect type.","action":"Check the source of the reference and the documentation for the requested API. Try again with the correct reference type.","id":"exception.webservices.api.invalid.reference","commandOutput":null,"diagnoses":[]}}

    Thanks
    Regards,
    Swathy


  • 24.  RE: How to start with delphix API

    Posted 05-24-2017 11:08:00 AM
    May be there was a miss

    Please connect copy/past the content of this url to the community

    "http://$DEIP/resources/json/delphix/database">http://%24deip/resources/json/delphix/database">http://$DEIP/resources/json/delphix/database" replace $DEIP with the ip of your engine

    Regards,

    Mouhssine


  • 25.  RE: How to start with delphix API

    Posted 05-26-2017 04:07:00 AM

    Hi

    Still error is not resolved I have tried the same still getting the same error.

    Thanks

    Regards

    Swathy



  • 26.  RE: How to start with delphix API

    Posted 05-26-2017 04:26:00 AM
    Hi Swathy, I ha be to check if you got any group with this number in your engine, to do so I need the output elsewhere it will be hard to help. Can you ensure please that you followed this plan. 1) open browser 2) open a first tab and connect to the admin console 3) open a second tab in the same browser and go to this url "http://DEIP/resources/json/delphix/group" replace DEIP with the up of your engine 4) past the output to the community website Regards, Mouhssine


  • 27.  RE: How to start with delphix API

    Posted 05-26-2017 06:22:00 AM
    Hi,

    Let's try another plan please if you face problems to get the first one done.

    Connect to your engine via ssh as delphix_admin and do the following please.

    1) cd group
    2) setopt trace=true
    3) ls
    4 past the output of the latest command in the community website

    Regards,

    Mouhssine



  • 28.  RE: How to start with delphix API

    Posted 05-26-2017 07:41:00 AM

    Hi

    This output I got after ls command:

    Objects
    === GET /resources/json/delphix/group ===
    === RESPONSE ===
    {
        "type": "ListResult",
        "status": "OK",
        "result": [
            {
                "type": "Group",
                "reference": "GROUP-34",
                "namespace": null,
                "name": "Source-Oracle-174",
                "description": "",
                "dataNode": "DATA_NODE-1"
            },
            {
                "type": "Group",
                "reference": "GROUP-37",
                "namespace": null,
                "name": "virtual-Oralce-138",
                "description": "",
                "dataNode": "DATA_NODE-1"
            }
        ],
        "job": null,
        "action": null,
        "total": 2,
        "overflow": false


    Thanks,

    Swathy



  • 29.  RE: How to start with delphix API

    Posted 05-26-2017 01:43:00 PM
    Hi Swathy,

    Finally figured it out.

    You are using "TimeflowPointLocation" as time flow point this means that location parameter should have an scn value, but in your case you set is to "LATEST_SNAPSHOT" and this is only supported for "TimeflowPointSemantic" time flow point.

    Please update the "timeflowPointParameters" in your script and set it type to "TimeflowPointSemantic" and you will be fine.

    eg:
    ...
     "timeflowPointParameters": {
            "type": "TimeflowPointSemanticTimeflowPointLocation",
            "timeflow": "ORACLE_TIMEFLOW-38",
            "location": "LATEST_SNAPSHOT"
        },
    ...

    Regards,

    Mouhssine