Which version of api? to CREATE/DELETE

Running rancher 1.14 using marathon on mesos, added vamp/consul/elastic search as well. Been creating hosts in rancher manually. Been using catalogs in rancher UI to start container services listed above. NOW started building a microservice in node.js to hit marathon and rancher and vamp with CRUD. The reading of rancher endpoints works great, thx. Using /V1 api endpoints that come up in rancher 1.14 API->> advanced -->> account keys endpoint.

Now I want to CREATE and DELETE hosts from Rancher API. Instructions online not for /V1 but for /V2-beta???
http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/host/
Have been trying to use examples and nothing is working. Been aiming at /V1 version of endpoints that work perfectly for reads.I am using account account keys BTW for security.

  1. Does V2-beta work with Rancher 1.1.4? Or do I have to upgrade to 1.2 to have those work?
  2. Does api version /V1 NOT support host/create and host/delete?
  3. DELETE /V1 endpoints are returning an error that METHOD is not supported. Is that an api version issue or is there a special syntax required for deleting hosts (or physical hosts)? or do I delete Instances?
  4. CREATE POST continues to tell me that there is a format error in my json file I created to hopefully create a fifth identical host in the mesos cluster under rancher. Is there a working file I can download to test to build an AWS instance that you know works correctly?

Thanks

v2-beta is available only in 1.2.x (starting around -pre2 or -pre3). There are separate docs pages for v1.1.

In 1.1/API v1, you would create a machine resource with POST /v1/projects/<project id>/machines. That creates the virtual machine in the provider and starts the rancher agent, which eventually reports in and causes a host resource to show up. The UI displays both machines and hosts on the same screen to make them look like one thing.

In 1.2/API v2-beta, machine and host are combined together so you create a host resource directly and do not have to track the 2 separate but related resources.

DELETE is correct but not always available. The host must first be first deactivated using the deactivate action.

Try pasting your JSON into a linter like http://jsonlint.com/ . It must be actually valid JSON that conforms to the standard, which is stricter than some other parsers allow. For example map keys must be quoted strings, strings in general must be double quoted (not single), an extra comma after the last item in an array or map is not allowed, etc.

excellent thanks

whats the url for the V1.14 v1 api docs?

http://docs.rancher.com/rancher/v1.0/en/api/v1/api-resources/host/#deactivate
so for v1 to delete is host/deactivate then machine/delete, correct?

Yes; there may be a bug with using v1 in 1.2 to create a machine never showing up as a host; @sangeethah was trying to reproduce it yesterday.

I am just running 1.14 and api v1, not mixing them (as I saw issues on upgrading for the moment).

Thanks again for answering my questions,

1)So the deactivation id is the INTEGER returned by GET /machines or GET /hosts?
2) Deactivation is a POST and Remove is a DELETE, correct?
3)The base URL is /V! or /V1/Project/{projectid}?

(so far have not gotten the combo right :frowning:

when I was trying to remove a host I would get a 405 error
now when I try and deactivate a host I get 404 errors

  1. IDs are all strings; you should treat them as arbitrary data, but in the normal config they are of the form “1”+“one or more letters denoting the resource type”+auto incrementing number. So “1h1” is a host", “1m1” is a machine, etc.

  2. The clean way to do things is to GET the resource you’re interested in first. Then Actions (like deactivate) are a POST to the URL listed in the actions map, and delete is the DELETE method to the links map -> self entry.

  3. “Environment” in the UI === project in the API. If you’re using an API key tied to the specific environment (you probably are in 1.1.x) then the project ID is already known so you can use /v1/hosts. If you have a key tied to a user (or access control is off and you’re doing no authentication) then you have access to multiple environmnets and need to specify which one you’re referring to by using /v1/projects/<project id>/hosts.

Thanks, you saved me.

I looked at the schemas and they said Integer not string for ID.
When I used strings for GET filters they bombed
When I removed the 1 + prefix the GET filters (QS) they worked correctly
So I assumed that you wanted all IDs as number/integers
My bad/ So now I use Integers for QS id filters and strings for ids for deactivate and remove.

Next I work on the formating of the Create POST Json.

Thanks again Vincent :slight_smile:

Yeah the schema is wrong for IDs… it’s because they are actually integers. If you run a public cloud you probably don’t want everyone to know exactly how many hosts, containers, accounts, etc there are, so there’s a hook there to allow transforming the IDs to something that isn’t guessable/auto-incrementing. And to exercise that the default transform is “1”+“type letter”+num.

What filter are you trying to do on an ID? If you want a particular record by ID, then it’s just /v1/projects/<project id>/<type>/<record ID> and you’ll get back a single record (or 404). You don’t need to do /v1/project//type?id= (and get back a list of 0/1 thing). If you’re doing less than/greater than/etc then I’m surprised that even works…

Use this tool to validate: json formatter https://jsonformatter-online.com
Hope this help!