Hi all,
how to create a catalog stack using API?
I would like to deploy Rancher NFS directly after setting up the system using API but can’t find how to do that.
Could someone please help?
Hi all,
how to create a catalog stack using API?
I would like to deploy Rancher NFS directly after setting up the system using API but can’t find how to do that.
Could someone please help?
There is not a specific API for this; the UI gets the compose files from the catalog (/v1-catalog/templates/
, find the specific catalog/templateversion you want) and then sends it to create stack (POST /v2-beta/projects/1a5/stacks
with those file contents as the compose files. Detecting it as a catalog item and the upgrade checking and all that is done by setting the stack’s externalId
to catalog://
+ the ID of the templateVersion.
Thanks Vincent,
it works like a charm. Just wondering why API endpoint is v1-catalog. Are there any plans to move it to v2-beta?
There are several things that are run as separate microservices and not part of cattle itself, each have their own version number and suffix. /v1-auth
, /v1-webhooks
, /v1-telemetry
(if enabled), etc.
We are trying to use the above mentioned Method to create stack from catalog.
When we try to send the files that we get from /v1-catalog/templateversions for the POST of /v2-beta/projects/1a5/stacks we get the following response.
{“id”:“7d414b26-d7dc-4f76-8259-04e4bd66ce14”,“type”:“error”,“links”:{},“actions”:{},“status”:400,“code”:“InvalidBodyContent”,“message”:“InvalidBodyContent”,“detail”:null,“baseType”:“error”}
How to debug this kind of response. Not much information available
Can you post the actual request body & headers?
I am trying to integrate Create catalog API using python requests…
Code:
import requests, json
/* Getting the docker-compose and rancher-compose content from mysql catalog */
resp = requests.get('http://x.x.x.x:x/v1-catalog/templateversions/community:mysql:0', auth=('E492D67A8E8C221CCABC', 'xb6qsZQFegcydwmvX4axvnnXLAXi4eMoMuzFmYos'), headers={"Content-Type":"application/json"})
var = json.loads(resp.text)
docker_compose = var['files']['docker-compose.yml.tpl']
rancher_compose = var['files']['rancher-compose.yml']
/* Creating the payload(request body) for creating stack */
post_data = {"system":False,"type":"stack","name":"mysql","startOnCreate":True,"environment":{"mysql_lb_port":"3306","mysql_root_password":"next","mysql_image":"mysql:latest","mysql_database":"","mysql_user":"","mysql_password":"","mysql_allow_empty_password":"no","mysql_random_root_password":"no","mysql_onetime_password":"no"},"dockerCompose":docker_compose,"rancherCompose":rancher_compose,"externalId":"catalog://community:mysql:0"}
/* Catalog create post request */
data = requests.post('http://x.x.x.x:x/v2-beta/projects/1a5/stacks', auth=('E492D67A8E8C221CCABC', 'xb6qsZQFegcydwmvX4axvnnXLAXi4eMoMuzFmYos'), headers={"Content-Type":"application/json"}, data=post_data)
print data.text
Output (Error):
{“id”:“7d414b26-d7dc-4f76-8259-04e4bd66ce14”,“type”:“error”,“links”:{},“actions”:{},“status”:400,“code”:“InvalidBodyContent”,“message”:“InvalidBodyContent”,“detail”:null,“baseType”:“error”}
How to debug this kind of response. Not much information available.
That looks like you’re trying to post the raw dictionary instead of encoding it to a JSON string. So you’re probably sending whatever the “toString” of a dictionary is, which isn’t JSON and the server has no idea how to parse it.
Thanks @vincent. Tried your solution. Its working fine now.