APIPythonOpen-Source Solutions

  • 1.  API create environment: Host Environment Type not recognised

    Posted 09-14-2017 07:34:00 AM

    I am trying to create a new source environment, via a call to the API.

    It Looks like I’m getting my API call rejected because of the engine not recognising the WindowsHostEnvironment Type. I checked the documentation and this seems to be the corect type to use. Our API version is 1.8.1

    I was able to successfully make the call to create the environment using the CLI.
    What I saw from the json tracking of a successful create via the CLI:

    === POST /resources/json/delphix/environment ===
    {
        "type": "HostEnvironmentCreateParameters",
        "primaryUser": {
            "type": "EnvironmentUser",
            "name": "REDACTED",
            "credential": {
                "type": "PasswordCredential",
                "password": "REDACTED"
            }
        },
        "hostEnvironment": {
            "type": "WindowsHostEnvironment",
            "name": "REDACTED",
            "proxy": "WINDOWS_HOST-13"
        },
        "hostParameters": {
            "type": "WindowsHostCreateParameters",
            "host": {
                "type": "WindowsHost",
                "address": "REDACTED"
            }
        }
    }


    Using the API I issued a post request to ‘https://SERVERNAME/resources/json/delphix/environment
    {
        "type":  "HostEnvironmentCreateParameters",
       "primaryUser":  {
                            "type":  "EnvironmentUser",
                            "name":  "REDACTED",
                            "credential":  {
                                               "type":  "PasswordCredential",
                                               "password":  "REDACTED"
                                           }
                        },
        "hostEnvironment":  {
                                "type": "WindowsHostEnvironment",
                                "name":  "REDACTED",
                                "proxy":  "WINDOWS_HOST_ENVIRONMENT-81"
                            },
        "hostParameters":  {
                               "type":  "WindowsHostCreateParameters",
                               "host":  {
                                            "type":  "WindowsHost",
                                            "address":  "REDACTED"
                                        }
                           }
    }

    And got the following response:
    {
        "type": "ErrorResult",
        "status": "ERROR",
        "error": {
            "type": "APIError",
            "details": {
                "hostEnvironment": {
                    "proxy": {
                        "details": "Reference to invalid object type \"WindowsHostEnvironment\". Expected \"Host\" or sub type.",
                        "action": null,
                        "id": "exception.validation.referenceto.invalid",
                        "commandOutput": null,
                        "diagnoses": null
                    }
                }
            },
            "action": "Check your input parameters and try again.",
            "id": "exception.validation.bad.input",
            "commandOutput": null,
            "diagnoses": null
        }
    }


    I have tried settting it as the parent class "HostEnvironment" but this was also not recognised. I also tried as 'Host' and ommitting the type  but these calls also failed.

    I'd appreciate any pointers to what I should try next.


    #Virtualization
    #dxToolkit


  • 2.  RE: API create environment: Host Environment Type not recognised

    Posted 09-14-2017 07:40:00 AM
    Hi Jonathan,

    This looks like an API version issue. Are you specifying a particular version in your API script when you establish the session? If so, what is the script setting it to?

    Best Regards,

    Scott.


  • 3.  RE: API create environment: Host Environment Type not recognised

    Posted 09-14-2017 07:49:00 AM
    Hi Scott, I specify 1.8.1 when I create the session. That's the version I read from the engine


  • 4.  RE: API create environment: Host Environment Type not recognised
    Best Answer

    Posted 09-14-2017 08:26:00 AM
    Hi Jonathan,

    Ok, think I've got it, your definition for "proxy" points to a host environment (WINDOWS_HOST_ENVIRONMENT-81), but it should be a host reference instead.
    Try using the corresponding host reference for that environment and let me know if that works.

    Best Regards,

    Scott.



  • 5.  RE: API create environment: Host Environment Type not recognised
    Best Answer

    Posted 09-14-2017 08:32:00 AM
    I believe the problem is that for the "proxy" property you've specified the object reference of the windows host environment instead of the windows host. In the working CLI example the value "WINDOWS_HOST-13" was set, but in your example you passed "WINDOWS_HOST_ENVIRONMENT-81". You can use the CLI to find the object reference of the host that is contained in the "WINDOWS_HOST_ENVIRONMENT-81" environment, for instance on my machine:

    cli> /environment select UNIX_HOST_ENVIRONMENT-2; get host     test-host-name cli> /host select test-host-name; get reference     UNIX_HOST-2


  • 6.  RE: API create environment: Host Environment Type not recognised

    Posted 09-14-2017 08:38:00 AM
    Yep. That was it alright.

    Thanks a heap, I wouldn't have spotted that in my own code for ages. Thanks Scott & Eyal