How to provision Rancher host in openstack using rancher API?

Hello, I have been testing rancher with openstack and I could successfully launch rancher host on openstack through rancher UI. However, I’m unable to launch a rancher host when tried it through the rancher API.
Below is the request I tried:

HTTP Request:
HTTP/1.1 POST /v1/projects/1a5/openstackconfigs
Host: x.x.x.x
Accept: application/json
Content-Type: application/json
Content-Length: 319

{
“authUrl”: “http://x.x.x.x:5000/v2.0”,
“flavorName”: “custom.1.1.10”,
“imageName”: “ubuntu”,
“keypairName”: “adaikal_ssh_2”,
“netName”: “public”,
“password”: “*****”,
“privateKeyFile”: “/.ssh/adaikal_ssh_2”,
“region”: “RegionOne”,
“secGroups”: “default”,
“sshPort”: “22”,
“sshUser”: “ubuntu”,
“tenantName”: “demo”,
“username”: “demo”,
}

Posting the above JSON is giving the below error:

HTTP Response:
HTTP/1.1 500
Date: Mon, 28 Mar 2016 10:45:17 GMT
X-Api-Client-Ip: x.x.x.x
Server: Jetty(9.2.11.v20150529)
X-Api-Account-Id: 1a5
Content-Type: application/json; charset=utf-8
X-Api-Schemas: http://x.x.x.x/v1/projects/1a5/schemas
Content-Length: 176
Expires: Thu, 01 Jan 1970 00:00:00 GMT

{
“id”: “7effbd5e-0943-4292-b6f4-b21c11a1be79”,
“type”: “error”,
“links”: { },
“actions”: { },
“status”: 500,
“code”: “Internal Server Error”,
“message”: “Internal Server Error”,
“detail”: null,
}

And below is the error log I got from rancher server:

2016-03-28 10:24:02,545 ERROR [:] [] [] [] [p423436977-1224] [i.g.i.g.r.handler.ExceptionHandler ] Exception in API for request [io.github.ibuildthecloud.gdapi.request.ApiRequest@79d65d63] java.lang.IllegalArgumentException: Class [class io.cattle.platform.docker.machine.api.addon.BaseMachineConfig] is not an instanceof UpdatableRecord

Could you please advise how to fix this?!

And I also have been wondering, while I configured the openstack-rancher host in rancher UI, it asked me a host name for the host but there is no key as “name” in the API, why so?

You want POST /v1/projects/1a5/machines… It takes an object that has the name (among other things), and a driver-specific config field for every driver where you populate any one of them (this is the body you’re currently sending).

The error handling in this situation is unfortunate, but openstackConfig is only used as an embedded object, so trying to use it as a collection should have just said 404 or 405.

Thank you Vincent, really appreciate your help.

I could post the JSON on /v1/projects/1a5/machines and the machine started to create but it got teared down because of the following error:

time=“2016-03-28T12:20:07Z” level=info msg=“stderr: Error setting machine configuration from flags provided: Authentication URL must be specified either using the environment variable OS_AUTH_URL or the CLI option --openstack-auth-url” resourceId=1ph26

As you can see from the below JSON, I provided the AUTH_URL but yet it is asking to specify it.

{
“authUrl”: “http://x.x.x.x:5000/v2.0”,
“flavorName”: “custom.1.1.10”,
“imageName”: “ubuntu”,
“keypairName”: “adaikal_ssh_2”,
“netName”: “public”,
“password”: “*****”,
“privateKeyFile”: “/.ssh/adaikal_ssh_2”,
“region”: “RegionOne”,
“secGroups”: “default”,
“sshPort”: “22”,
“sshUser”: “ubuntu”,
“tenantName”: “demo”,
“username”: “demo”,
}

Could you please advise.

If you look just above that you can see the “Cmd slice:” which is the arguments passed to docker-machine. This whole API is just a thin wrapper around machine. I don’t have a running OpenStack setup handy but it seems to me that everything is getting passed through. There are 24 fields (+1 bool):

{
  "type": "machine",
  "name": "openstack",
  "openstackConfig": {
    "type": "openstackConfig",
    "activeTimeout": "1",
    "authUrl": "2",
    "availabilityZone": "3",
    "domainId": "4",
    "domainName": "5",
    "endpointType": "6",
    "flavorId": "7",
    "flavorName": "8",
    "floatingipPool": "9",
    "imageId": "10",
    "imageName": "11",
    "ipVersion": "12",
    "keypairName": "13",
    "netId": "14",
    "netName": "15",
    "password": "16",
    "novaNetwork": true,
    "privateKeyFile": "17",
    "region": "18",
    "secGroups": "19",
    "sshPort": "20",
    "sshUser": "21",
    "tenantId": "22",
    "tenantName": "23",
    "username": "24"
  }
}

Produces:

time="2016-03-28T16:47:07Z" level=info msg="Creating Machine" eventId=bde55603-826b-499d-9ab6-9484dbe4ec67 resourceId=1ph7
time="2016-03-28T16:47:07Z" level=info msg="Cmd slice: [create -d openstack --openstack-active-timeout 1 --openstack-auth-url 2 --openstack-availability-zone 3 --openstack-domain-id 4 --openstack-domain-name 5 --openstack-endpoint-type 6 --openstack-flavor-id 7 --openstack-flavor-name 8 --openstack-floatingip-pool 9 --openstack-image-id 10 --openstack-image-name 11 --openstack-ip-version 12 --openstack-keypair-name 13 --openstack-net-id 14 --openstack-net-name 15 --openstack-nova-network --openstack-password 16 --openstack-private-key-file 17 --openstack-region 18 --openstack-sec-groups 19 --openstack-ssh-port 20 --openstack-ssh-user 21 --openstack-tenant-id 22 --openstack-tenant-name 23 --openstack-username 24 openstack]"

Vincent thanks again. I can provision the hosts through API now.