API: Difference between revisions
m (→Planned) |
|||
| Line 27: | Line 27: | ||
require 'rest_client' # sudo gem install rest-client | require 'rest_client' # sudo gem install rest-client | ||
require 'json' # sudo gem install json | require 'json' # sudo gem install json | ||
api = RestClient::Resource.new('https://helpdesk.grid5000.fr/api/rennes', ' | api = RestClient::Resource.new('https://helpdesk.grid5000.fr/api/rennes', 'crohr', 'pmtppe1m') | ||
begin | begin | ||
# get the list of sites | # get the list of sites | ||
sites_response = JSON.parse api['/sites'].get(:accept => 'application/json') # or api['/sites.json'].get | |||
sites_response['items'].each do |site| | |||
puts "------------------ #{site['uid']} ------------------" | puts "------------------ #{site['uid']} ------------------" | ||
puts "Clusters = [#{site['clusters'].map{|cluster| cluster['uid']}.join(", ")}]" | puts "Clusters = [#{site['clusters'].map{|cluster| cluster['uid']}.join(", ")}]" | ||
# get the site's nodes. we use the URI contained in the response to locate and get new information. | # get the site's nodes. we use the URI contained in the response to locate and get new information. | ||
nodes_response = JSON.parse api["#{site['uri']}/nodes"].get(:accept => 'application/json') | |||
puts "Dead nodes = [#{ | puts "Dead nodes = [#{nodes_response['items'].select{|node| node['state'] == 'dead'}.collect{|node| node['uid']}.join(", ")}]" | ||
end | |||
# display errors if any | |||
sites_response['errors'].each do |error| | |||
puts error | |||
end | end | ||
rescue RestClient::ResourceNotFound | rescue RestClient::ResourceNotFound | ||
| Line 54: | Line 58: | ||
puts e.message | puts e.message | ||
end | end | ||
Run with: | Run with: | ||
Revision as of 17:09, 21 November 2008
Current State
An early prototype of the upcoming API is available at: https://helpdesk.grid5000.fr/api/rennes. Not stable, only a subset of sites are included (grenoble, bordeaux, rennes, sophia).
Enhancements are planned on a regular basis. Backwards-compatibility is not assured. Servers might be down at any time. Please refer to this page to get the main entry-point of the API as it may change.
The API is totally distributed. That is, the data is pulled from local datasets (OAR2) without the need for a centralized database.
Available Resources
API entry-point: https://helpdesk.grid5000.fr/api/rennes
The availability of an HTML format means that you can use your browser as a native API client (e.g. click on https://helpdesk.grid5000.fr/api/rennes/sites).
- GET /sites [html | json]
- list of sites (cached for 1 hour)
- GET /nodes [html | json]
- list of all nodes (cached for 90 seconds)
- GET /sites/
{site_uid}[html | json] - site's details
- GET /sites/
{site_uid}/nodes [html | json] - list of site's nodes (cached for 90 seconds)
- GET /sites/
{site_uid}/clusters [html | json] - list of site's clusters (cached for 1 hour)
Getting Started
Ruby client
Put this code in a g5k-client.rb file. It will output the current list of sites and, for each one, the list of its clusters and dead nodes:
require 'rubygems' require 'rest_client' # sudo gem install rest-client require 'json' # sudo gem install json
api = RestClient::Resource.new('https://helpdesk.grid5000.fr/api/rennes', 'crohr', 'pmtppe1m')
begin
# get the list of sites
sites_response = JSON.parse api['/sites'].get(:accept => 'application/json') # or api['/sites.json'].get
sites_response['items'].each do |site|
puts "------------------ #{site['uid']} ------------------"
puts "Clusters = [#{site['clusters'].map{|cluster| cluster['uid']}.join(", ")}]"
# get the site's nodes. we use the URI contained in the response to locate and get new information.
nodes_response = JSON.parse api["#{site['uri']}/nodes"].get(:accept => 'application/json')
puts "Dead nodes = [#{nodes_response['items'].select{|node| node['state'] == 'dead'}.collect{|node| node['uid']}.join(", ")}]"
end
# display errors if any
sites_response['errors'].each do |error|
puts error
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:
ruby g5k-client.rb
Planned
- details responses
- make available the node's attributes (cpu, memory, etc.)
- choice: do we settle on using a REST architectural style ?
- experiment submission