curl-tutorial.sh |
|
---|---|
|
|
This tutorial will show you how to use the cURL command-line tool to issue one-shot requests against the Grid'5000 API. |
|
Prerequisites |
|
You’ll need the cURL command-line tool. If it’s not already installed, use your package manager to fetch it. E.g.:
|
|
Let’s do some cURLing |
|
Test that you can access the Grid'5000 API. Replace
|
HTTP/1.1 200 OK
Date: Mon, 04 Apr 2011 09:22:37 GMT
Vary: Accept,Accept-Encoding
ETag: "f1930ff4bc894f7fa076ce8f2e029e1c6a4adfe7"
Allow: GET
Cache-Control: public, must-revalidate, proxy-revalidate, max-age=60, s-maxage=60
Last-Modified: Fri, 01 Apr 2011 15:38:10 GMT
Content-Length: 2366
Status: 200
Content-Type: application/vnd.fr.grid5000.api.site+json;level=1
{
"name": "Rennes",
"latitude": 48.1,
"location": "Rennes, France",
"security_contact": "rennes-staff@lists.grid5000.fr",
"uid": "rennes",
"type": "site",
"user_support_contact": "rennes-staff@lists.grid5000.fr",
"version": "a650e837fbc8a4fbcc403ad25aa82cceab7babe4",
"links": [
{
"href": "/2.0/grid5000/sites/rennes/versions/a650e837fbc8a4fbcc403ad25aa82cceab7babe4",
"title": "version",
"rel": "member",
"type": "application/vnd.fr.grid5000.api.Version+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/versions",
"title": "versions",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes",
"rel": "self",
"type": "application/vnd.fr.grid5000.api.Site+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/clusters",
"title": "clusters",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/environments",
"title": "environments",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000",
"rel": "parent",
"type": "application/vnd.fr.grid5000.api.Grid+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/status",
"title": "status",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/metrics",
"title": "metrics",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/jobs",
"title": "jobs",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes/deployments",
"title": "deployments",
"rel": "collection",
"type": "application/vnd.fr.grid5000.api.Collection+json;level=1"
}
],
"description": "",
"longitude": -1.6667,
"compilation_server": false,
"email_contact": "rennes-staff@lists.grid5000.fr",
"web": "http://www.irisa.fr",
"sys_admin_contact": "rennes-staff@lists.grid5000.fr"
} |
What you just did was getting the description of the |
|
If you want to avoid entering your credentials for every request, |
cat <<EOF >> ~/.netrc
machine api.grid5000.fr
login your-grid5000-login
password your-grid5000-password
EOF
chmod 600 ~/.netrc |
Retry the previous request with the
|
|
If you want to see the full details of how the HTTP request is made, add the
|
|
Looking at the list of
|
|
You can also fetch the list of scheduled jobs on the
|
|
At this point, you may want to add your very own job to the previous list.
Use the |
curl -kni -X POST https://api.grid5000.fr/2.0/grid5000/sites/rennes/jobs -d "command=sleep 1800" |
You should get back a response like the following: |
HTTP/1.1 201 Created
Date: Mon, 04 Apr 2011 09:51:39 GMT
Location: /2.0/grid5000/sites/rennes/jobs/381093
Content-Type: application/json
Content-Length: 337
Vary: Accept-Encoding
{
"uid": 381093,
"links": [
{
"href": "/2.0/grid5000/sites/rennes/jobs/381093",
"rel": "self",
"type": "application/vnd.fr.grid5000.api.Job+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes",
"rel": "parent",
"type": "application/vnd.fr.grid5000.api.Site+json;level=1"
}
]
} |
Have a look at the Jobs API documentation to see the full list of available parameters and usage. |
|
Notice the
|
HTTP/1.1 200 OK
Date: Mon, 04 Apr 2011 09:55:00 GMT
Content-Type: application/json
Content-Length: 790
Expires: Mon, 04 Apr 2011 09:55:30 GMT
Allow: GET, DELETE
Vary: Accept-Encoding
{
"assigned_nodes": [
"paramount-7.rennes.grid5000.fr"
],
"directory": "/home/crohr",
"command": "sleep 1800",
"mode": "PASSIVE",
"walltime": 3600,
"submitted_at": 1301910701,
"project": "default",
"events": [
],
"uid": 381093,
"user_uid": "crohr",
"links": [
{
"href": "/2.0/grid5000/sites/rennes/jobs/381093",
"rel": "self",
"type": "application/vnd.fr.grid5000.api.Job+json;level=1"
},
{
"href": "/2.0/grid5000/sites/rennes",
"rel": "parent",
"type": "application/vnd.fr.grid5000.api.Site+json;level=1"
}
],
"types": [
],
"queue": "default",
"started_at": 1301910702,
"message": "FIFO scheduling OK",
"scheduled_at": 1301910702,
"state": "running",
"properties": "maintenance = 'NO'"
} |
We can see that our job is
|
HTTP/1.1 202 Accepted
Date: Mon, 04 Apr 2011 09:57:11 GMT
Content-Type: application/json
Content-Length: 0
X-Oar-Info: Deleting the job = 381093 ...REGISTERED. The job(s) [ 381093 ] will be deleted in a near future.
Vary: Accept-Encoding |
This concludes our short tour of using the Grid'5000 API with cURL. You will find many more examples in the respective documentation of each API. See https://api.grid5000.fr for links to the documentation. |
|