[racktables-users] RESTful API for RackTables

  • From: Philip Durbin <philipdurbin@xxxxxxxxx>
  • To: racktables-users@xxxxxxxxxxxxx
  • Date: Fri, 01 Jun 2012 10:29:55 -0400

Hello!

I wanted to point out a new blog post that demonstrates a RESTful API for RackTables:

http://blog.mattynick.com/blog/2012/05/31/getting-racktables-location-info-into-puppet/

It boils down to being able to retrieve the location of a server, described in YAML. . .

---
ru: "16"
row: "DataCenterB Row 6"
rack: "1"
height: "1"
asset: "326859"

. . . by a script called rack2yaml.rb. . .

#!/usr/bin/env ruby
require 'yaml'
require 'mysql'
path="/var/www/rackfacts/"

my = Mysql::new("racktables","rackuser","rackpass","racktables")

rackobjs=my.query("select distinct RackObject.name,RackSpace.unit_no,Rack.name,RackRow.name,RackObject.asset_no,RackObject.id from RackObject,RackSpace,Rack,RackRow where RackObject.id = RackSpace.object_id AND Rack.id = RackSpace.rack_id AND RackRow.id = Rack.row_id AND RackObject.objtype_id = 4;")

objects=Array.new
rackobjs.each do |row|
        obj=Hash.new
obj["name"] = row[0].to_s.downcase.strip.delete(' ').delete('#').delete('/').delete('"')
        obj["ru"] = row[1].to_s.strip.delete('"')
        obj["rack"] = row[2].to_s.strip
        obj["row"] = row[3].to_s.strip
        obj["asset"] = row[4].to_s.strip
        obj["id"] = row[5]
        objects.push(obj)
end

#Need to get the height of a given system...
objects.each do |obj|
height=my.query("SELECT COUNT(distinct unit_no) FROM `RackSpace` WHERE object_id #{obj['id']};")
        obj["height"] = height
end
#Writing Systems, so lets do this in /systems/

path = path + "systems/"

#Lets clean the existing ones, so stale thigns are removed.
clean = "rm -rf #{path} && mkdir #{path}"
%x[ #{clean} ]
objects.each do |thing|
        fpath = path+thing["name"]
        yobj=Hash.new
        yobj["ru"]=thing["ru"]
        yobj["rack"]=thing["rack"]
        yobj["row"]=thing["row"]
        yobj["asset"]=thing["asset"]
        yobj["height"]=thing["height"]
        f=File.open(fpath,'w')
        f.write(yobj.to_yaml)
end

allpath=path + "index.html"
all=File.open(allpath,'w')
all.write(objects.to_yaml)

. . . which you can find at https://github.com/sjoeboo/sjoeboo.github.com/blob/source/source/downloads/code/rack2yaml.rb via https://github.com/sjoeboo/sjoeboo.github.com/blob/source/source/_posts/2012-05-31-getting-racktables-location-info-into-puppet.markdown

I've been collecting other information about the RackTables community's desire for a RESTful API at https://projects.cs50.net/project/97/build-a-restful-api-for-racktables-at-philip-durbin/ but I'll include some of the links below.

I understand that there is documentation for developing against RackTables in PHP at http://sourceforge.net/apps/mediawiki/racktables/index.php?title=RackTablesDevelGuide#API but members of the RackTables community have expressed a desire for a RESTful API at //www.freelists.org/post/racktables-users/api-question and //www.freelists.org/post/racktables-users/Simple-HTML-interface-for-APIbased-calls

The latter thread lead to a patch for a "quiet mode". . . "This mode is useful for API calls from external apps" -- 0000544: Quiet modes support - Mantis - http://sourceforge.net/apps/mantisbt/racktables/view.php?id=544

Anyway, I'm attempting to gather all the discussion about a RESTful API for RackTables in one place. I hope this is useful.

Thanks for RackTables.  It helps us visualize our data centers.

Phil

Other related posts: