API: Difference between revisions

From Grid5000
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(133 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{Status|Draft}}
{{Author|Cyril Rohr}}
{{Maintainer|Cyril Rohr}}
{{Portal|User}}
{{Portal|Tutorial}}
{{Pages|API}}
{{TutorialHeader}}


== ReferenceAPI ==
== Introduction ==
=== Synopsis ===
The reference API provides the reference data of Grid5000. Information such as the list of sites, clusters, nodes, environments, etc. can be queried using this API.
You can also obtain a specific version of any data, list all the versions of a given information, and get an archive of all or part of the data.


=== REST API ===
Until 2009, Grid'5000 was mainly accessed and operated via shell commands executed from frontend machines. To ease scripting and provide better access to the functionalities of the instrument (Grid'5000), an '''API''' has been developed on top of most of the Grid'5000 tools by the development team and is available to users since November 2009.
* API entry-point: http://localhost:8080/reference/0_1
 
* note on formats: it is not required to explicitly insert the format in the URL, e.g.:
To achieve ''ease of use'' and ''large accessibility'', we use the '''HTTP protocol''' ([http://www.w3.org/Protocols/rfc2616/rfc2616.html RFC2616]). As a consequence of using the HTTP protocol as an application protocol, any HTTP client can be used to query the API: command-line tools (cURL), browsers,  and the numerous HTTP libraries available in your favorite programming language.
   GET /resource.json
 
You may prefer to set the Accept HTTP header to the correct mime type, e.g.:
We have chosen to be as close as possible to the principles of a [http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm REST] (REpresentational State Transfer) architecture, which recommends to define the semantics of an operation on a '''resource''' by means of the '''standard HTTP operations''' (e.g. POST, GET, PUT, DELETE) and the '''standard HTTP status codes''' (e.g. 200, 401, 404, 500). REST usages include, but are not limited to, implementing CRUD (Create, Read, Update, Delete) semantics over the network. We also implement the concept of "Hypermedia as the Engine of Application State" (HATEOAS), by specifying a set of hyperlinks in all responses returned by the API, which allows a user agent to discover at runtime the set of available resources as well as their semantics and content types, and transition from one resource to another.
   GET /resource
 
''Security'' is ensured by encrypting the traffic using HTTP over SSL/TLS (HTTPS, [http://tools.ietf.org/html/rfc5246 RFC5246]), and requesting login:password credentials using the HTTP Basic Authentication ([http://www.ietf.org/rfc/rfc2617.txt RFC2617]) scheme. A mutual authentication scheme using SSL Client Certificates has been envisioned, but not implemented due to lack of resources.
 
Finally, ''fault tolerance'' and ''scalability'' are ensured by distributing all the APIs over the Grid'5000 sites, and using proven HTTP technology such as load balancers and proxies to monitor the application servers and route the traffic to alive servers.
 
== Overview of the Current API Landscape ==
 
[[Image:Api_Overview.png]]
 
== Using the API ==
The API entry-point is (both from within Grid'5000 and outside):
 
  https://api.grid5000.fr/
 
As the API is a REST API over HTTP, there is no library and language dependencies to use it. A command line tool like <code>curl</code> can be used, and any programming language can help you automating stuff around Grid'5000's API.
 
=== HTTP ===
To understand how the API works, it is important to know how the HTTP protocol works. For an in-depth view, please refer to [http://www.ietf.org/rfc/rfc2616.txt RFC 2616]
 
In short, a client sends a request to the server, with control metadata added as HTTP headers, and the server sends back a response. For instance:
 
Example of '''HTTP Request''' (we <code>Accept</code> any kind of content, and we provide <code>Authorization</code> credentials):
 
  <code class="replace">GET</code> <code class="replace">/stable/sites/rennes</code> HTTP/1.1
  <code class="replace">Authorization: Basic xxx</code>
  User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0a zlib/1.2.5 libidn/1.19
  Host: api.grid5000.fr
  <code class="replace">Accept: */*</code>
 
Example of '''HTTP Response''':
HTTP/1.1  <code class="replace">200 OK</code>
Date: Fri, 04 Dec 2020 09:42:50 GMT
Server: thin
Allow: GET
Vary: accept,Accept-Encoding
Last-Modified: Thu, 03 Dec 2020 17:31:21 GMT
ETag: W/"3b0ebf623e5b58991c056d75fcd37fa9"
<code class="replace">Content-Type: application/json;chartset=utf-8</code>
Cache-Control: max-age=60, public, must-revalidate=true, proxy-revalidate=true, s-maxage=60
Content-Length: 3789
X-Request-Id: a1087546-3d47-4140-b8f4-0c7a0e05fd5f
X-Runtime: 0.004494
Via: 1.1 api-server-v3.rennes.grid5000.fr:4444
X-Api-Auth-Type: IDENT
X-Api-User-CN: auser
X-Remote-Ident: auser
X-Kadeploy-User: auser
{
  "compilation_server": false,
  "description": "Grid5000 Rennes site",
  "email_contact": "support-staff@lists.grid5000.fr",
  "frontend_ip": "172.16.111.106",
  "g5ksubnet": {
    "gateway": "10.159.255.254",
    "network": "10.156.0.0/14"
  },
  "ipv6": {
    "prefix": "2001:660:4406:07",
    "site_global_kavlan": 16,
    "site_index": 7
  },
  "kavlan_ip_range": "10.24.0.0/14",
  "kavlans": {
    "1": {
      "gateway": "192.168.207.254",
      "network": "192.168.192.0/20"
    },
    "16": {
      "gateway": "10.27.255.254",
      "network": "10.27.192.0/18"
    },
    "2": {
      "gateway": "192.168.223.254",
      "network": "192.168.208.0/20"
    },
    "3": {
      "gateway": "192.168.239.254",
      "network": "192.168.224.0/20"
    },
    "4": {
      "gateway": "10.24.63.254",
      "network": "10.24.0.0/18"
    },
    "5": {
      "gateway": "10.24.127.254",
      "network": "10.24.64.0/18"
    },
    "6": {
      "gateway": "10.24.191.254",
      "network": "10.24.128.0/18"
    },
    "7": {
      "gateway": "10.24.255.254",
      "network": "10.24.192.0/18"
    },
    "8": {
      "gateway": "10.25.63.254",
      "network": "10.25.0.0/18"
    },
    "9": {
      "gateway": "10.25.127.254",
      "network": "10.25.64.0/18"
    },
    "default": {
      "gateway": "172.16.111.254",
      "network": "172.16.96.0/20"
    }
  },
  "latitude": 48.1,
  "location": "Rennes, France",
  "longitude": -1.6667,
  "name": "Rennes",
  "production": true,
  "renater_ip": "192.168.4.19",
  "security_contact": "support-staff@lists.grid5000.fr",
  "sys_admin_contact": "support-staff@lists.grid5000.fr",
  "type": "site",
  "uid": "rennes",
  "user_support_contact": "support-staff@lists.grid5000.fr",
  "virt_ip_range": "10.156.0.0/14",
  "web": "http://www.irisa.fr",
  "version": "44a8812238067115b482b283b38c44d7d55ec585",
  "links": [
    {
      "rel": "clusters",
      "href": "/stable/sites/rennes/clusters",
      "type": "application/vnd.grid5000.collection+json"
    },
    {
      "rel": "network_equipments",
      "href": "/stable/sites/rennes/network_equipments",
      "type": "application/vnd.grid5000.collection+json"
    },
    {
      "rel": "pdus",
      "href": "/stable/sites/rennes/pdus",
      "type": "application/vnd.grid5000.collection+json"
    },
    {
      "rel": "servers",
      "href": "/stable/sites/rennes/servers",
      "type": "application/vnd.grid5000.collection+json"
    },
    {
      "rel": "self",
      "type": "application/vnd.grid5000.item+json",
      "href": "/stable/sites/rennes"
    },
    {
      "rel": "parent",
      "type": "application/vnd.grid5000.item+json",
      "href": "/stable/"
    },
    {
      "rel": "version",
      "type": "application/vnd.grid5000.item+json",
      "href": "/stable/sites/rennes/versions/44a8812238067115b482b283b38c44d7d55ec585"
    },
    {
      "rel": "versions",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/versions"
    },
    {
      "rel": "jobs",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/jobs"
    },
    {
      "rel": "deployments",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/deployments"
    },
    {
      "rel": "vlans",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/vlans"
    },
    {
      "rel": "metrics",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/metrics"
    },
    {
      "rel": "storage",
      "type": "application/vnd.grid5000.collection+json",
      "href": "/stable/sites/rennes/storage"
    },
    {
      "rel": "status",
      "type": "application/vnd.grid5000.item+json",
      "href": "/stable/sites/rennes/status"
    }
  ]
}
 
=== Authentication ===
 
==== From outside Grid'5000 ====
 
* When accessing the API from outside Grid'5000, you MUST send your Grid'5000 credentials (login and password) via the use of the HTTP Basic Authentication mechanism (every browser and the vast majority of HTTP libraries support this mechanism). Example with '''cURL''':
 
  auser@machine:~$ curl -u mylogin:mypassword -X POST https://api.grid5000.fr/stable/sites/rennes/jobs -d "command=sleep 100"
 
* You may also choose to set up an SSH tunnel with one of the <i>access</i> machines available from the Internet, so that the authentication of your requests is handled transparently for you (see below [[#How to set up an SSH Tunnel]]).
 
==== From within Grid'5000 ====
 
* From within Grid'5000, you are transparently authenticated IF AND ONLY IF you connect from a frontend or access machine.
 
  auser@frontend:~$ curl -X POST https://api.grid5000.fr/stable/sites/rennes/jobs -d "command=sleep 100"
 
* Connections from other Grid'5000 machines require setting up an SSH tunnel between your node and a <i>frontend</i> machine (see [[#How to set up an SSH Tunnel]]).
 
=== Media Type ===
 
A Media Type (also called MIME Type, or Content-Type) is an identifier for file formats on the Internet. When a Client (we’ll call it a User-Agent in the rest of the documentation) receives an HTTP response from a Server, it needs to know the content-type of the response to be able to interpret it, and make use of it. For instance, your browser knows how to deal with formats such as <code>text/html</code> (HTML source file), <code>image/jpeg</code> (JPEG Image), <code>application/pdf</code> (PDF Document), etc.
 
In Grid‘5000 API, we are using two custom media types:
* one to represent a resource ''item'': <code>application/vnd.grid5000.item+json</code>
* one to represent a resource collection (having references to multiple ''items'') : <code>application/vnd.grid5000.collection+json</code>
 
Those two media types are based on the JSON format, but using properties with specific semantics that are described below.
 
A User-Agent that knows about these specifics will then be able to handle that kind of payload, and interact with the Grid‘5000 API.
 
==== Properties ====
 
Every <code>application/vnd.grid5000.item+json</code> or <code>application/vnd.grid5000.collection+json</code> payload is a JSON object (also called hash or dictionary), which comes with the following mandatory properties:
* links, which is an array of link elements that define the relationship between the current resource and other resources of the API. Each link element is an object, which will have at least <code>rel</code>, <code>href</code> and <code>type</code> keys defined. <code>rel</code> specifies the link relationship between the current and the target resource, <code>href</code> specifies the URI of the target resource and <code>type</code> if the target resource is a ''collection'' or an ''item'' (using the media types).
 
The <code>application/vnd.grid5000.item+json</code> media type has the additional mandatory properties:
* a unique <code>id (uid)</code> property will be returned, that uniquely identify the item within the collection.
 
The application/vnd.grid5000.collection+json media type has the additional mandatory properties:
* an <code>items</code> property containing an array of item elements will be returned. Each item element is an object that contains a (possibly partial) description of the item. An item element may or may not have a links property.
* a <code>total</code> property, specifying what is the total number of items in the collection. This number is always greater or equal to the number of items returned. This is especially useful for paginating collections.
* an <code>offset</code> property, specifying what is the current offset of the first item that appears in the collection, among the total number of items in the collection. This is especially useful for paginating collections.
 
==== Link Relations ====
 
===== Valid link attributes =====
 
Each <code>link</code> element has three properties:
* <code>rel</code> specifies the relationship between the current resource, and the resource targeted by the link
* <code>href</code> specifies the URI at which the target resource can be accessed. This is most of the time an HTTP URI (<code>http:</code> scheme), but it could based on other schemes (<code>xmpp:</code>, <code>mailto:</code>, …)
* <code>type</code> specifies the content-type of the target resource
 
===== Link Relationships =====
 
Some of link relation values for the <code>rel</code> property of a link element that can be found:
* <code>self</code>: refers to the current resource
* <code>parent</code>: refers to the first parent resource in the resource hierarchy
* <code>sites</code>: refers to the list of Sites
* <code>jobs</code>: refers to the list of Jobs
* <code>vlans</code>: refers to the list of Vlans
* …
 
Depending on the part of the API, some specifics relation values can be found. For example, in the vlan part, a <code>dhcpd</code> relationship can be found to start or stop a dhcp server.
 
=== Content Negotiation ===
When you query a resource, you ask for a representation of an object. Depending on the resource you are requesting, there could be multiple representations (of different content types) available (e.g. XML, JSON, PDF, HTML, etc.). It is the responsibility of the user to indicate which representation (or format) it wants.
 
To set the format that you accept, the Grid'5000 APIs support two methods:
* you could either explicitly insert the format at the end of the URL, e.g.:
 
   GET <code class="replace">entry-point</code>/<code class="replace">global-version-id</code>/<code class="replace">resource</code>.json
 
* or, you may prefer to set the Accept HTTP header to the correct mime type, e.g.:
 
   GET <code class="replace">entry-point</code>/<code class="replace">global-version-id</code>/<code class="replace">resource</code>
   Accept: application/json
   Accept: application/json
If you put both, the Accept HTTP header will be ignored.


==== Get a specific version of a resource ====
If you put '''both''', the <code>Accept</code> HTTP header will be ignored.
   GET /<code class="replace">%resource%</code>.<code class="replace">%format%</code>?version=<code class="replace">%version%</code>
 
* Accepted formats: json, zip
=== API Version ===
* Version parameter: can be omitted (latest version is returned), or it can be: a commit id (40 characters length) or a Unix UTC time (number of seconds since the Unix epoch: 1970-01-01 00:00:00 UTC)
 
* Comments: the zip format will return a zip archive containing the set of directories and files corresponding to the required data.
The Grid'5000 API is made up of multiple APIs that may evolve independently from each other.
* Examples:
Changes occurring in one API are reflected by a new version number for this particular API.
  GET /.json
In the long term, scripts or applications that are built upon multiple APIs may have to deal with multiple version numbers for each API, which is not a very enjoyable perspective.
will return the description of the "root" resource, which is Grid5000:
That's why the Grid'5000 API is globally versioned: a global version id will map to the specific API version numbers in a transparent manner.
   HTTP/1.1 200 OK
All you have to do is to suffix the API entry-point with the global version id of your choice:
  Etag: "d69bfd1891582824f5a192fa41a3f444a3d52854"
 
   Last-Modified: Wed, 28 Jan 2009 13:46:19 GMT
   https://api.grid5000.fr/<code class="replace">global-version-id</code>
  Content-Type: application/json;charset=utf-8
 
  Content-Length: 345
Stable version are using the form <code class="replace">major</code>.<code class="replace">minor</code>. The latest stable version is also available under the alias <code>stable</code>.
  Connection: close
 
 
See https://api.grid5000.fr for the list of available global version ids.
  {
 
    "environments": [
Scripts and applications that are programmed against a specific global version id of '''STABLE''' quality should never encounter problems due to changes in the APIs, until the official deprecation of the version.
      "\/environments\/sid-x64-base-1.0"
 
    ],
{{Note|text=Currently, only one version of the API is available, the <code>stable</code> version.}}
    "sites": [
 
      "\/sites\/bordeaux",
An unstable version, named <code>sid</code> is also available. You shouldn't have to use it, except if the Grid'5000 staff asked you to do so (for example if you encountered an issue while developing a library or an application, and a fix is available in <code>sid</code>).
      "\/sites\/grenoble",
 
      "\/sites\/lille",
=== Resources ===
      "\/sites\/lyon",
 
       "\/sites\/nancy",
The resources that can be queried are described in the documentation of each API.
      "\/sites\/orsay",
The resources are identified by a relative URI, which should be added to the end of the API entry-point to form the URL.
       "\/sites\/rennes",
 
      "\/sites\/sophia",
For example, <code>/sites/rennes</code> is a resource exposed by the Reference API. If you would like to get the representation of this resource as it is returned by the <code>stable</code> version of the Grid'5000 API, the URL to enter in your HTTP client would be:
       "\/sites\/toulouse"
 
    ],
   https://api.grid5000.fr/stable/sites/rennes
    "uid": "grid5000",
 
    "type": "grid",
As an other example, to get the list of sites, the URL will be:
    "uri": "\/"
 
  }
   https://api.grid5000.fr/stable/sites
 
 
From there, you can discover the composition of the grid by following the URIs to get more information about the sub-resources. For example, you can get more details about Bordeaux by querying:
For a particular cluster:
  GET /sites/bordeaux.json
 
this will return something like:
https://api.grid5000.fr/stable/sites/rennes/clusters/paravance/
  HTTP/1.1 200 OK
 
  Etag: "45f78b07665ed58f843a741d6927d60a4db35ba3"
==== Versioning ====
  Last-Modified: Wed, 28 Jan 2009 13:46:19 GMT
 
  Content-Type: application/json;charset=utf-8
The resources are described in the ''reference-repository'', which is a Git repository. Therefore, the API offers the possibility to list the latest changes in the Grid'5000 infrastructure, or to fetch resources description for a specific version or at a specific time.
  Content-Length: 604
 
  Connection: close
===== List versions =====
 
 
  {
Each URL resources can be suffixed with <code>/versions</code> to get a list of versions (Git commit). For example:
    "environments": [
 
      "\/sites\/bordeaux\/environments\/sid-x64-base-1.0"
$ curl https://api.grid5000.fr/stable/sites/rennes/clusters/versions?pretty
    ],
  "total": 392,
    "name": "Bordeaux",
  "offset": 0,
    "location": "Bordeaux, France",
  "items": [
    "latitude": null,
    {
    "security_contact": null,
       "uid": "68fdd053e6767ba2da1edf5105f57ff7b963f91f",
    "clusters": [
       "date": "Thu, 03 Dec 2020 09:56:38 GMT",
      "\/sites\/bordeaux\/clusters\/bordemer",
       "message": "[all] upgrade postinstall",
      "\/sites\/bordeaux\/clusters\/bordeplage",
      "author": "Author",
      "\/sites\/bordeaux\/clusters\/bordereau",
      "type": "version",
       "\/sites\/bordeaux\/clusters\/borderline"
      "links": [
     ],
        {
     "uid": "bordeaux",
          "rel": "self",
    "type": "site",
          "href": "/stable/sites/rennes/clusters/versions/68fdd053e6767ba2da1edf5105f57ff7b963f91f",
    "user_support_contact": null,
          "type": "application/vnd.grid5000.item+json"
    "description": "",
        },
    "longitude": null,
        {
    "email_contact": null,
          "rel": "parent",
    "web": null,
          "href": "/stable/sites/rennes/clusters",
    "uri": "\/sites\/bordeaux",
          "type": "application/vnd.grid5000.item+json"
    "sys_admin_contact": null
        }
  }
       ]
and so on.
     },
     {
      "uid": "5d9b32e3f6f0eb63608274d028994e99ea4c0698",
      "date": "Fri, 20 Nov 2020 17:20:33 GMT",
      "message": "[all] Add prometheus metrics to all clusters",
      "author": "Author",
      "type": "version",
 
And following the logic behind the API, each item can be accessed, like <code>https://api.grid5000.fr/stable/sites/rennes/clusters/versions/68fdd053e6767ba2da1edf5105f57ff7b963f91f</code>
 
===== Get resources for a version =====
 
To get a resource description for specific version of ''reference-repository'', the <code>version</code> *GET* parameter can be added to the request. For example, to get on old description of the node ''dahu-29'' on Grenoble:


==== Get the list of all versions of a resource ====
$ curl "https://api.grid5000.fr/stable/sites/grenoble/clusters/dahu/nodes/dahu-29?pretty&version=0c1396da414cca75faadd7b52fbb4fea11667213"
  GET /<code class="replace">%resource%</code>/versions.<code class="replace">%format%</code>
 
* Accepted formats: json
===== Get resources at a given time =====
* Response: the list of all changes that were made to the resource.
It is also possible to get the reference repository at a specific time, using the <code>date</code> or <code>timestamp</code> *GET* parameters.
With a UNIX timestamp:
 
$ curl "https://api.grid5000.fr/stable/sites/grenoble/clusters/dahu/nodes/dahu-29.json?pretty&timestamp=1606400407"
 
=== Status Codes ===
Every response that you'll get from the APIs will contain a status code. In Grid'5000 we use a subset of the standards HTTP status codes [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]. You may encounter one of the following:


==== Status codes ====
* A 200 status code is returned when the request is successful.  
* A 200 status code is returned when the request is successful.  
* A 201 status code is returned when the request has been fulfilled and resulted in a new resource being created.
* A 202 status code is returned when the request has been accepted. The real processing may happen later.
* A 304 status code is returned on a conditional GET request [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3] when the requested resource has not been modified since the last access.
* A 400 status code is returned when something in the request of the user agent is not correct.
* A 401 status code is returned when the user agent needs to authenticate.
* A 403 status code is returned when the access to the requested resource is forbidden to the currently logged user.
* A 404 status code is returned when a resource does not exist.  
* A 404 status code is returned when a resource does not exist.  
* A 405 status code is returned when the user agent uses an HTTP method not supported by the resource.
* A 406 status code is returned when the requested format is not available.
* A 406 status code is returned when the requested format is not available.
* A 415 status code is returned when the payload of the request uses an unsupported content-type (e.g. application/xml instead of application/json).
* A 422 status code is returned when the payload of the request uses a unsupported content-type, but the data structure is not valid.
* A 500 status code is returned when the server encountered an error.
* A 500 status code is returned when the server encountered an error.
* A 503 status code is returned when the service is not available.
* A 504 status code is returned if the request took too much time to complete.
The body of responses whose status code is 4xx or 5xx may contain additional information about the error.
=== Caching ===
{{Warning|text=On a first read, this section can be [[#APIs|skipped]] without any regrets. This section is targeted at advanced users/developers interested in improving the performance of their client applications.}}
As described in the [http://tools.ietf.org/html/rfc2616#section-13 RFC2616]:
  HTTP is typically used for distributed information systems, where
  performance can be improved by the use of response caches. The
  HTTP/1.1 protocol includes a number of elements intended to make
  caching work as well as possible.
Hence, client applications can (and should) cache the responses so that subsequent requests for the same information use the cached data. The use of caching strategies can dramatically reduce delays and save bandwidth.
That's why most of the responses returned by the Grid'5000 APIs include HTTP headers to support one or both of the caching models: expiration-based or validation-based. If you don't know what this means, read this article: http://tomayko.com/writings/things-caches-do.
Below are the different schemes that can exist when the API returns cacheable responses.
1. no caching
  O                          |-----|
  -|-  <-------internet------> | API |
  / \                          |-----|
2. the API builds the response once and stores it into cache for a certain amount of time.
  O                          |-----|      |-----|
  -|-  <-------internet------> |CACHE| <---> | API |
  / \                          |-----|      |-----|
3. the client receives the response once and stores it into cache for a certain amount of time.
  O        |-----|                        |-----|
  -|-  <---> |CACHE| <-------internet------> | API |
  / \        |-----|                        |-----|
4. both the client and the API have a cache in front of them.


=== Getting Started ===
  O        |-----|                        |-----|      |-----|
==== Creating an SSH tunnel ====
   -|- <---> |CACHE| <-------internet------> |CACHE| <---> | API |
The API is only available from the Grid5000 frontends. As a consequence, the first thing you have to do when trying to query an API is to create an SSH tunnel to the API server, via your site's access machine:
  / \        |-----|                        |-----|      |-----|
   ssh -N -L 8080:131.254.202.98:8080 <code class="replace">login</code>@access.<code class="replace">site</code>.grid5000.fr


Note: when you are done with your queries, you can hit CTRL-C to destroy the tunnel.
Most of the APIs of Grid'5000 will use some kind of caching strategies from their side (scheme 2). It is recommended that client applications include a caching strategy in their implementation (scheme 4): this will save bandwidth, reduce latency and may improve the tolerance of the client to network outages.


==== cURL example ====
Note that only a few HTTP libraries natively support client-side caching (e.g.: [http://code.google.com/p/httplib2/ httplib2] in Python). For ruby, the [http://github.com/crohr/rest-client-components rest-client-components] gem offer this functionality.
Get the latest version of the composition of the platform:
  $ curl -i http://localhost:8080/reference/0_1/.json


  HTTP/1.1 200 OK
== FAQ ==
  Date: Thu, 29 Jan 2009 15:23:10 GMT
=== "Certificate verification failed" ===
  Server: Apache
Your HTTP client may produce a warning or refuses to connect if your client does not trust the certification authority (CA) that has signed our certificate. We are using a widely deployed CA (TERENA), so this should not happen. Please check your configuration before disabling certificate validation.
  X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.6
  Etag: "2e16727e9012f1d12e25010921a6a5fe71bda895"
  Last-Modified: Wed, 28 Jan 2009 13:46:19 GMT
  Content-Length: 345
  Connection: close
  Content-Type: application/json;charset=utf-8
 
  {
    "environments": [
      "\/environments\/sid-x64-base-1.0"
    ],
    "uri": "\/",
    "type": "grid",
    "sites": [
      "\/sites\/bordeaux",
      "\/sites\/grenoble",
      "\/sites\/lille",
      "\/sites\/lyon",
      "\/sites\/nancy",
      "\/sites\/orsay",
      "\/sites\/rennes",
      "\/sites\/sophia",
      "\/sites\/toulouse"
    ],
    "uid": "grid5000"
  }


Get the composition of the platform as it was on Wed Jan 28 12:11:36 +0100 2009:
=== How to set up an SSH Tunnel ===
  $ curl -i http://localhost:8080/reference/0_1/.json?version=1233141096
Replace <code>login</code>, <code>machine</code> and <code>site</code> in the following command:


   HTTP/1.1 200 OK
   $ ssh -NL 3443:api.grid5000.fr:443 <code class="replace">login</code>@<code class="replace">machine</code>.<code class="replace">site</code>.grid5000.fr
  Date: Thu, 29 Jan 2009 15:22:20 GMT
  Server: Apache
  X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.6
  Etag: "7a518f34482cd7a898b8428bac26eb9a6e457379"
  Last-Modified: Wed, 28 Jan 2009 11:11:36 GMT
  Content-Length: 299
  Connection: close
  Content-Type: application/json;charset=utf-8
 
  {
    "environments": [
      "\/environments\/sid-x64-base-1.0"
    ],
    "uri": "\/",
    "type": "grid",
    "sites": [
      "\/sites\/grenoble",
      "\/sites\/lille",
      "\/sites\/nancy",
      "\/sites\/orsay",
      "\/sites\/rennes",
      "\/sites\/sophia",
      "\/sites\/toulouse"
    ],
    "uid": "grid5000"
  }


For example, if you want to access the API from a Grid'5000 node (<b>within Grid'5000</b>), you might set up an SSH tunnel as follows:


Get the composition of the platform as it was after the change #30dc4c4fa25ee63c86a093cf6108259a128561b1
   grid5000-node $ ssh -NL 3443:api.grid5000.fr:443 your_user@frontend
   $ curl -i http://localhost:8080/reference/0_1/.json?version=30dc4c4fa25ee63c86a093cf6108259a128561b1


  HTTP/1.1 200 OK
On the contrary, from <b>outside Grid'5000</b> you would set up an SSH tunnel as follows:
  Date: Fri, 30 Jan 2009 08:48:39 GMT
  Server: Apache
  X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.0.6
  Etag: "c6beebf69985bb57642defb4a3e6c0a3a1491783"
  Last-Modified: Wed, 28 Jan 2009 10:27:37 GMT
  Content-Length: 255
  Connection: close
  Content-Type: application/json;charset=utf-8
 
  {
    "environments": [
      "\/environments\/sid-x64-base-1.0"
    ],
    "uri": "\/",
    "type": "grid",
    "sites": [
      "\/sites\/grenoble",
      "\/sites\/orsay",
      "\/sites\/rennes",
      "\/sites\/sophia",
      "\/sites\/toulouse"
    ],
    "uid": "grid5000"
  }


Get all the versions of the platform:
   your-machine $ ssh -NL 3443:api.grid5000.fr:443 your_user@access.grid5000.fr
   $ curl -i http://localhost:8080/reference/0_1/versions.json


Get all the versions of a cluster:
As a consequence, the API entry-point, as seen from your machine, will become:
  $ curl -i http://localhost:8080/reference/0_1/sites/rennes/clusters/paramount/versions.json


Get the zip archive of containing the files describing the rennes platform:
   https://localhost:3443
   $ curl http://localhost:8080/reference/0_1/sites/rennes.zip > rennes.zip


etc.
Thus, an example of request would be:


==== Ruby example ====
   $ curl -k -X POST https://localhost:3443/sid/sites/rennes/jobs -d "command=sleep 100"
First, make sure you've got *Ruby* and *Rubygems* installed. Then install the required gems:
   sudo gem install rest-client json --no-ri --no-rdoc
Put this code in a g5k-reference-api-client.rb file. It will output the current list of sites and, for each one, the list of its clusters:
  require 'pp'
  require 'rubygems'
  require 'rest_client' # sudo gem install rest-client
  require 'json'        # sudo gem install json
 
  api = RestClient::Resource.new('http://localhost:8080/reference/0_1')
  begin
    puts "---- Getting Grid5000"
    # start at the root of the reference data (= grid5000)
    grid5000 = JSON.parse api['/'].get(:accept => 'application/json')
    pp grid5000
    puts "\n---- Getting sites"
    grid5000['sites'].each do |site_uri|
      site = JSON.parse api[site_uri].get(:accept => 'application/json')
      pp site
      puts "\n---- Getting #{site['uid']} clusters"
      site['clusters'].each do |cluster_uri|
        cluster = JSON.parse api[cluster_uri].get(:accept => 'application/json')
        pp cluster
      end
    end
  rescue RestClient::ResourceNotFound
    puts 'Resource not found.'
  rescue RestClient::RequestTimeout
    puts 'Timeout.'
  rescue RestClient::Unauthorized
    puts 'Unauthorized.'
  rescue RestClient::RequestFailed
    puts 'Request failed.'
  rescue RestClient::ServerBrokeConnection
    puts 'Connection broken.'
  rescue Exception => e
    puts e.message
  end


Run with:
When you're done with the API, hit CTRL-C to destroy the tunnel, unless you added the -f flag to run it in the background.
  ruby g5k-reference-api-client.rb


=== Planned ===
== Tools and libraries ==
* Refine node description scheme;
* [http://man.cx/curl cURL], the recommended tool for command-line access to the API.
* Add missing data (environments, nodes);
* [https://github.com/rest-client/rest-client RestClient], a Ruby HTTP client.
* Add XML format
* [http://github.com/grid5000/restfully Restfully], a Ruby wrapper for REST APIs.
* [http://g5k-campaign.gforge.inria.fr g5k-campaign], a tool to launch campaigns on Grid'5000.


== Links of interest ==
== References ==
* [https://api.grid5000.fr API entry point]
* [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html HTTP Header Field Definition]
* [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP Status Code Definition]
* http://json.org/ Introducing JSON
* http://json.org/ Introducing JSON
* http://rest-client.heroku.com/rdoc/ The RestClient Ruby gem documentation

Latest revision as of 15:49, 12 October 2022

Note.png Note

This page is actively maintained by the Grid'5000 team. If you encounter problems, please report them (see the Support page). Additionally, as it is a wiki page, you are free to make minor corrections yourself if needed. If you would like to suggest a more fundamental change, please contact the Grid'5000 team.

Introduction

Until 2009, Grid'5000 was mainly accessed and operated via shell commands executed from frontend machines. To ease scripting and provide better access to the functionalities of the instrument (Grid'5000), an API has been developed on top of most of the Grid'5000 tools by the development team and is available to users since November 2009.

To achieve ease of use and large accessibility, we use the HTTP protocol (RFC2616). As a consequence of using the HTTP protocol as an application protocol, any HTTP client can be used to query the API: command-line tools (cURL), browsers, and the numerous HTTP libraries available in your favorite programming language.

We have chosen to be as close as possible to the principles of a REST (REpresentational State Transfer) architecture, which recommends to define the semantics of an operation on a resource by means of the standard HTTP operations (e.g. POST, GET, PUT, DELETE) and the standard HTTP status codes (e.g. 200, 401, 404, 500). REST usages include, but are not limited to, implementing CRUD (Create, Read, Update, Delete) semantics over the network. We also implement the concept of "Hypermedia as the Engine of Application State" (HATEOAS), by specifying a set of hyperlinks in all responses returned by the API, which allows a user agent to discover at runtime the set of available resources as well as their semantics and content types, and transition from one resource to another.

Security is ensured by encrypting the traffic using HTTP over SSL/TLS (HTTPS, RFC5246), and requesting login:password credentials using the HTTP Basic Authentication (RFC2617) scheme. A mutual authentication scheme using SSL Client Certificates has been envisioned, but not implemented due to lack of resources.

Finally, fault tolerance and scalability are ensured by distributing all the APIs over the Grid'5000 sites, and using proven HTTP technology such as load balancers and proxies to monitor the application servers and route the traffic to alive servers.

Overview of the Current API Landscape

Api Overview.png

Using the API

The API entry-point is (both from within Grid'5000 and outside):

 https://api.grid5000.fr/

As the API is a REST API over HTTP, there is no library and language dependencies to use it. A command line tool like curl can be used, and any programming language can help you automating stuff around Grid'5000's API.

HTTP

To understand how the API works, it is important to know how the HTTP protocol works. For an in-depth view, please refer to RFC 2616

In short, a client sends a request to the server, with control metadata added as HTTP headers, and the server sends back a response. For instance:

Example of HTTP Request (we Accept any kind of content, and we provide Authorization credentials):

 GET /stable/sites/rennes HTTP/1.1
 Authorization: Basic xxx
 User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0a zlib/1.2.5 libidn/1.19
 Host: api.grid5000.fr
 Accept: */*

Example of HTTP Response:

HTTP/1.1  200 OK
Date: Fri, 04 Dec 2020 09:42:50 GMT
Server: thin
Allow: GET
Vary: accept,Accept-Encoding
Last-Modified: Thu, 03 Dec 2020 17:31:21 GMT
ETag: W/"3b0ebf623e5b58991c056d75fcd37fa9"
Content-Type: application/json;chartset=utf-8
Cache-Control: max-age=60, public, must-revalidate=true, proxy-revalidate=true, s-maxage=60
Content-Length: 3789
X-Request-Id: a1087546-3d47-4140-b8f4-0c7a0e05fd5f
X-Runtime: 0.004494
Via: 1.1 api-server-v3.rennes.grid5000.fr:4444
X-Api-Auth-Type: IDENT
X-Api-User-CN: auser
X-Remote-Ident: auser
X-Kadeploy-User: auser

{
 "compilation_server": false,
 "description": "Grid5000 Rennes site",
 "email_contact": "support-staff@lists.grid5000.fr",
 "frontend_ip": "172.16.111.106",
 "g5ksubnet": {
   "gateway": "10.159.255.254",
   "network": "10.156.0.0/14"
 },
 "ipv6": {
   "prefix": "2001:660:4406:07",
   "site_global_kavlan": 16,
   "site_index": 7
 },
 "kavlan_ip_range": "10.24.0.0/14",
 "kavlans": {
   "1": {
     "gateway": "192.168.207.254",
     "network": "192.168.192.0/20"
   },
   "16": {
     "gateway": "10.27.255.254",
     "network": "10.27.192.0/18"
   },
   "2": {
     "gateway": "192.168.223.254",
     "network": "192.168.208.0/20"
   },
   "3": {
     "gateway": "192.168.239.254",
     "network": "192.168.224.0/20"
   },
   "4": {
     "gateway": "10.24.63.254",
     "network": "10.24.0.0/18"
   },
   "5": {
     "gateway": "10.24.127.254",
     "network": "10.24.64.0/18"
   },
   "6": {
     "gateway": "10.24.191.254",
     "network": "10.24.128.0/18"
   },
   "7": {
     "gateway": "10.24.255.254",
     "network": "10.24.192.0/18"
   },
   "8": {
     "gateway": "10.25.63.254",
     "network": "10.25.0.0/18"
   },
   "9": {
     "gateway": "10.25.127.254",
     "network": "10.25.64.0/18"
   },
   "default": {
     "gateway": "172.16.111.254",
     "network": "172.16.96.0/20"
   }
 },
 "latitude": 48.1,
 "location": "Rennes, France",
 "longitude": -1.6667,
 "name": "Rennes",
 "production": true,
 "renater_ip": "192.168.4.19",
 "security_contact": "support-staff@lists.grid5000.fr",
 "sys_admin_contact": "support-staff@lists.grid5000.fr",
 "type": "site",
 "uid": "rennes",
 "user_support_contact": "support-staff@lists.grid5000.fr",
 "virt_ip_range": "10.156.0.0/14",
 "web": "http://www.irisa.fr",
 "version": "44a8812238067115b482b283b38c44d7d55ec585",
 "links": [
   {
     "rel": "clusters",
     "href": "/stable/sites/rennes/clusters",
     "type": "application/vnd.grid5000.collection+json"
   },
   {
     "rel": "network_equipments",
     "href": "/stable/sites/rennes/network_equipments",
     "type": "application/vnd.grid5000.collection+json"
   },
   {
     "rel": "pdus",
     "href": "/stable/sites/rennes/pdus",
     "type": "application/vnd.grid5000.collection+json"
   },
   {
     "rel": "servers",
     "href": "/stable/sites/rennes/servers",
     "type": "application/vnd.grid5000.collection+json"
   },
   {
     "rel": "self",
     "type": "application/vnd.grid5000.item+json",
     "href": "/stable/sites/rennes"
   },
   {
     "rel": "parent",
     "type": "application/vnd.grid5000.item+json",
     "href": "/stable/"
   },
   {
     "rel": "version",
     "type": "application/vnd.grid5000.item+json",
     "href": "/stable/sites/rennes/versions/44a8812238067115b482b283b38c44d7d55ec585"
   },
   {
     "rel": "versions",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/versions"
   },
   {
     "rel": "jobs",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/jobs"
   },
   {
     "rel": "deployments",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/deployments"
   },
   {
     "rel": "vlans",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/vlans"
   },
   {
     "rel": "metrics",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/metrics"
   },
   {
     "rel": "storage",
     "type": "application/vnd.grid5000.collection+json",
     "href": "/stable/sites/rennes/storage"
   },
   {
     "rel": "status",
     "type": "application/vnd.grid5000.item+json",
     "href": "/stable/sites/rennes/status"
   }
 ]
}

Authentication

From outside Grid'5000

  • When accessing the API from outside Grid'5000, you MUST send your Grid'5000 credentials (login and password) via the use of the HTTP Basic Authentication mechanism (every browser and the vast majority of HTTP libraries support this mechanism). Example with cURL:
 auser@machine:~$ curl -u mylogin:mypassword -X POST https://api.grid5000.fr/stable/sites/rennes/jobs -d "command=sleep 100"
  • You may also choose to set up an SSH tunnel with one of the access machines available from the Internet, so that the authentication of your requests is handled transparently for you (see below #How to set up an SSH Tunnel).

From within Grid'5000

  • From within Grid'5000, you are transparently authenticated IF AND ONLY IF you connect from a frontend or access machine.
 auser@frontend:~$ curl -X POST https://api.grid5000.fr/stable/sites/rennes/jobs -d "command=sleep 100"
  • Connections from other Grid'5000 machines require setting up an SSH tunnel between your node and a frontend machine (see #How to set up an SSH Tunnel).

Media Type

A Media Type (also called MIME Type, or Content-Type) is an identifier for file formats on the Internet. When a Client (we’ll call it a User-Agent in the rest of the documentation) receives an HTTP response from a Server, it needs to know the content-type of the response to be able to interpret it, and make use of it. For instance, your browser knows how to deal with formats such as text/html (HTML source file), image/jpeg (JPEG Image), application/pdf (PDF Document), etc.

In Grid‘5000 API, we are using two custom media types:

  • one to represent a resource item: application/vnd.grid5000.item+json
  • one to represent a resource collection (having references to multiple items) : application/vnd.grid5000.collection+json

Those two media types are based on the JSON format, but using properties with specific semantics that are described below.

A User-Agent that knows about these specifics will then be able to handle that kind of payload, and interact with the Grid‘5000 API.

Properties

Every application/vnd.grid5000.item+json or application/vnd.grid5000.collection+json payload is a JSON object (also called hash or dictionary), which comes with the following mandatory properties:

  • links, which is an array of link elements that define the relationship between the current resource and other resources of the API. Each link element is an object, which will have at least rel, href and type keys defined. rel specifies the link relationship between the current and the target resource, href specifies the URI of the target resource and type if the target resource is a collection or an item (using the media types).

The application/vnd.grid5000.item+json media type has the additional mandatory properties:

  • a unique id (uid) property will be returned, that uniquely identify the item within the collection.

The application/vnd.grid5000.collection+json media type has the additional mandatory properties:

  • an items property containing an array of item elements will be returned. Each item element is an object that contains a (possibly partial) description of the item. An item element may or may not have a links property.
  • a total property, specifying what is the total number of items in the collection. This number is always greater or equal to the number of items returned. This is especially useful for paginating collections.
  • an offset property, specifying what is the current offset of the first item that appears in the collection, among the total number of items in the collection. This is especially useful for paginating collections.

Link Relations

Valid link attributes

Each link element has three properties:

  • rel specifies the relationship between the current resource, and the resource targeted by the link
  • href specifies the URI at which the target resource can be accessed. This is most of the time an HTTP URI (http: scheme), but it could based on other schemes (xmpp:, mailto:, …)
  • type specifies the content-type of the target resource
Link Relationships

Some of link relation values for the rel property of a link element that can be found:

  • self: refers to the current resource
  • parent: refers to the first parent resource in the resource hierarchy
  • sites: refers to the list of Sites
  • jobs: refers to the list of Jobs
  • vlans: refers to the list of Vlans

Depending on the part of the API, some specifics relation values can be found. For example, in the vlan part, a dhcpd relationship can be found to start or stop a dhcp server.

Content Negotiation

When you query a resource, you ask for a representation of an object. Depending on the resource you are requesting, there could be multiple representations (of different content types) available (e.g. XML, JSON, PDF, HTML, etc.). It is the responsibility of the user to indicate which representation (or format) it wants.

To set the format that you accept, the Grid'5000 APIs support two methods:

  • you could either explicitly insert the format at the end of the URL, e.g.:
 GET entry-point/global-version-id/resource.json
  • or, you may prefer to set the Accept HTTP header to the correct mime type, e.g.:
 GET entry-point/global-version-id/resource
 Accept: application/json

If you put both, the Accept HTTP header will be ignored.

API Version

The Grid'5000 API is made up of multiple APIs that may evolve independently from each other. Changes occurring in one API are reflected by a new version number for this particular API. In the long term, scripts or applications that are built upon multiple APIs may have to deal with multiple version numbers for each API, which is not a very enjoyable perspective. That's why the Grid'5000 API is globally versioned: a global version id will map to the specific API version numbers in a transparent manner. All you have to do is to suffix the API entry-point with the global version id of your choice:

 https://api.grid5000.fr/global-version-id

Stable version are using the form major.minor. The latest stable version is also available under the alias stable.

See https://api.grid5000.fr for the list of available global version ids.

Scripts and applications that are programmed against a specific global version id of STABLE quality should never encounter problems due to changes in the APIs, until the official deprecation of the version.

Note.png Note

Currently, only one version of the API is available, the stable version.

An unstable version, named sid is also available. You shouldn't have to use it, except if the Grid'5000 staff asked you to do so (for example if you encountered an issue while developing a library or an application, and a fix is available in sid).

Resources

The resources that can be queried are described in the documentation of each API. The resources are identified by a relative URI, which should be added to the end of the API entry-point to form the URL.

For example, /sites/rennes is a resource exposed by the Reference API. If you would like to get the representation of this resource as it is returned by the stable version of the Grid'5000 API, the URL to enter in your HTTP client would be:

 https://api.grid5000.fr/stable/sites/rennes

As an other example, to get the list of sites, the URL will be:

 https://api.grid5000.fr/stable/sites

For a particular cluster:

https://api.grid5000.fr/stable/sites/rennes/clusters/paravance/

Versioning

The resources are described in the reference-repository, which is a Git repository. Therefore, the API offers the possibility to list the latest changes in the Grid'5000 infrastructure, or to fetch resources description for a specific version or at a specific time.

List versions

Each URL resources can be suffixed with /versions to get a list of versions (Git commit). For example:

$ curl https://api.grid5000.fr/stable/sites/rennes/clusters/versions?pretty
 "total": 392,
 "offset": 0,
 "items": [
   {
     "uid": "68fdd053e6767ba2da1edf5105f57ff7b963f91f",
     "date": "Thu, 03 Dec 2020 09:56:38 GMT",
     "message": "[all] upgrade postinstall",
     "author": "Author",
     "type": "version",
     "links": [
       {
         "rel": "self",
         "href": "/stable/sites/rennes/clusters/versions/68fdd053e6767ba2da1edf5105f57ff7b963f91f",
         "type": "application/vnd.grid5000.item+json"
       },
       {
         "rel": "parent",
         "href": "/stable/sites/rennes/clusters",
         "type": "application/vnd.grid5000.item+json"
       }
     ]
   },
   {
     "uid": "5d9b32e3f6f0eb63608274d028994e99ea4c0698",
     "date": "Fri, 20 Nov 2020 17:20:33 GMT",
     "message": "[all] Add prometheus metrics to all clusters",
     "author": "Author",
     "type": "version",

And following the logic behind the API, each item can be accessed, like https://api.grid5000.fr/stable/sites/rennes/clusters/versions/68fdd053e6767ba2da1edf5105f57ff7b963f91f

Get resources for a version

To get a resource description for specific version of reference-repository, the version *GET* parameter can be added to the request. For example, to get on old description of the node dahu-29 on Grenoble:

$ curl "https://api.grid5000.fr/stable/sites/grenoble/clusters/dahu/nodes/dahu-29?pretty&version=0c1396da414cca75faadd7b52fbb4fea11667213"
Get resources at a given time

It is also possible to get the reference repository at a specific time, using the date or timestamp *GET* parameters. With a UNIX timestamp:

$ curl "https://api.grid5000.fr/stable/sites/grenoble/clusters/dahu/nodes/dahu-29.json?pretty&timestamp=1606400407"

Status Codes

Every response that you'll get from the APIs will contain a status code. In Grid'5000 we use a subset of the standards HTTP status codes [1]. You may encounter one of the following:

  • A 200 status code is returned when the request is successful.
  • A 201 status code is returned when the request has been fulfilled and resulted in a new resource being created.
  • A 202 status code is returned when the request has been accepted. The real processing may happen later.
  • A 304 status code is returned on a conditional GET request [2] when the requested resource has not been modified since the last access.
  • A 400 status code is returned when something in the request of the user agent is not correct.
  • A 401 status code is returned when the user agent needs to authenticate.
  • A 403 status code is returned when the access to the requested resource is forbidden to the currently logged user.
  • A 404 status code is returned when a resource does not exist.
  • A 405 status code is returned when the user agent uses an HTTP method not supported by the resource.
  • A 406 status code is returned when the requested format is not available.
  • A 415 status code is returned when the payload of the request uses an unsupported content-type (e.g. application/xml instead of application/json).
  • A 422 status code is returned when the payload of the request uses a unsupported content-type, but the data structure is not valid.
  • A 500 status code is returned when the server encountered an error.
  • A 503 status code is returned when the service is not available.
  • A 504 status code is returned if the request took too much time to complete.

The body of responses whose status code is 4xx or 5xx may contain additional information about the error.

Caching

Warning.png Warning

On a first read, this section can be skipped without any regrets. This section is targeted at advanced users/developers interested in improving the performance of their client applications.

As described in the RFC2616:

  HTTP is typically used for distributed information systems, where
  performance can be improved by the use of response caches. The
  HTTP/1.1 protocol includes a number of elements intended to make
  caching work as well as possible.

Hence, client applications can (and should) cache the responses so that subsequent requests for the same information use the cached data. The use of caching strategies can dramatically reduce delays and save bandwidth.

That's why most of the responses returned by the Grid'5000 APIs include HTTP headers to support one or both of the caching models: expiration-based or validation-based. If you don't know what this means, read this article: http://tomayko.com/writings/things-caches-do.

Below are the different schemes that can exist when the API returns cacheable responses.

1. no caching

  O                           |-----|
 -|-  <-------internet------> | API |
 / \                          |-----| 

2. the API builds the response once and stores it into cache for a certain amount of time.

  O                           |-----|       |-----|
 -|-  <-------internet------> |CACHE| <---> | API |
 / \                          |-----|       |-----|

3. the client receives the response once and stores it into cache for a certain amount of time.

  O         |-----|                         |-----|
 -|-  <---> |CACHE| <-------internet------> | API |
 / \        |-----|                         |-----|

4. both the client and the API have a cache in front of them.

  O         |-----|                         |-----|       |-----|
 -|-  <---> |CACHE| <-------internet------> |CACHE| <---> | API |
 / \        |-----|                         |-----|       |-----|

Most of the APIs of Grid'5000 will use some kind of caching strategies from their side (scheme 2). It is recommended that client applications include a caching strategy in their implementation (scheme 4): this will save bandwidth, reduce latency and may improve the tolerance of the client to network outages.

Note that only a few HTTP libraries natively support client-side caching (e.g.: httplib2 in Python). For ruby, the rest-client-components gem offer this functionality.

FAQ

"Certificate verification failed"

Your HTTP client may produce a warning or refuses to connect if your client does not trust the certification authority (CA) that has signed our certificate. We are using a widely deployed CA (TERENA), so this should not happen. Please check your configuration before disabling certificate validation.

How to set up an SSH Tunnel

Replace login, machine and site in the following command:

 $ ssh -NL 3443:api.grid5000.fr:443 login@machine.site.grid5000.fr

For example, if you want to access the API from a Grid'5000 node (within Grid'5000), you might set up an SSH tunnel as follows:

 grid5000-node $ ssh -NL 3443:api.grid5000.fr:443 your_user@frontend

On the contrary, from outside Grid'5000 you would set up an SSH tunnel as follows:

 your-machine $ ssh -NL 3443:api.grid5000.fr:443 your_user@access.grid5000.fr

As a consequence, the API entry-point, as seen from your machine, will become:

 https://localhost:3443

Thus, an example of request would be:

 $ curl -k -X POST https://localhost:3443/sid/sites/rennes/jobs -d "command=sleep 100"

When you're done with the API, hit CTRL-C to destroy the tunnel, unless you added the -f flag to run it in the background.

Tools and libraries

  • cURL, the recommended tool for command-line access to the API.
  • RestClient, a Ruby HTTP client.
  • Restfully, a Ruby wrapper for REST APIs.
  • g5k-campaign, a tool to launch campaigns on Grid'5000.

References