ibettinger / racktables

RackTables source code
http://racktables.org/
GNU General Public License v2.0
20 stars 11 forks source link

Basic Example #5

Open kylebrandt opened 11 years ago

kylebrandt commented 11 years ago

Any chance of a basic usage example, for example, authenticating, listing some stuff, and adding something with curl or something like that?

ibettinger commented 11 years ago

Hi Kyle,

I actually have a pretty complete Python client library I'm hoping to publish here by mid-January.

Regarding authentication, the API just depends on the authentication configuration you have set up for your Racktables installation generally. In the case of my employer, Topsy, we use LDAP and HTTP basic auth. If a user can get to the UI, they can use the API.

Here are some example URLs, which you'll need to put together in whatever way suits your particular situation. For testing I'll often use Firefox and the JSONovich extension (http://lackoftalent.org/michael/blog/json-in-firefox/) to see what comes back from a given URL.

Get object id 889, including set and unset attributes: https://racktables.example.com/api.php?method=get_object&object_id=889&include_attrs=1&include_unset_attrs=1

Add an object: https://racktables.example.com/api.php?method=add_object&object_name=my-new-server&object_type_id=4&object_label=some_label&object_asset_no=some_asset_number

Change object id 100's allocation to: rack ID 10, position 4, front middle and rear: https://racktables.example.com/api.php?method=update_object_allocation&object_id=100&allocate_to[]=atom_10_4_0&allocate_to[]=atom_10_4_1&allocate_to[]=atom_10_4_2

Assign tags with ids 40 and 50 to object id 100 (replaces the existing ones): https://racktables.example.com/api.php?method=update_object_tags&object_id=100&taglist[]=40&taglist[]=50

Get the overall rackspace layout (comes back as a list of rows, within which are found the racks): https://racktables.example.com/api.php?method=get_rackspace

Get all objects: https://racktables.example.com/api.php?method=get_depot

Get all servers (servers have object type id 4): https://racktables.example.com/api.php?method=get_depot&cfe={$typeid_4}

Get all VMs (type 1504), including their attributes (this significantly increases the amount of data that comes back, so be careful with large installations): https://racktables.example.com/api.php?method=get_depot&cfe={$typeid_1504}&include_attrs=1

Get all objects that have tag id 131 and attribute ID 2 set to 50018 (happens to be "HW type" == "HP ProLiant DL360 G5" in our case) https://racktables.example.com/api.php?method=get_depot&object_details=1&andor=and&cft[]=131&cfe={$attr_2_50004} (this follows Racktables' own UI semantics for filtering objects, which is admittedly cryptic)

Hope that helps!

Cheers, Ian

kylebrandt commented 11 years ago

And I just started writing a python library for this :-P Any chance you might be willing to share it? I'll accept that it might change a lot....

On Thu, Dec 20, 2012 at 1:19 PM, ibettinger notifications@github.comwrote:

Hi Kyle,

I actually have a pretty complete Python client library I'm hoping to publish here by mid-January.

Regarding authentication, the API just depends on the authentication configuration you have set up for your Racktables installation generally. In the case of my employer, Topsy, we use LDAP and HTTP basic auth. If a user can get to the UI, they can use the API.

Here are some example URLs, which you'll need to put together in whatever way suits your particular situation. For testing I'll often use Firefox and the JSONovich extension ( http://lackoftalent.org/michael/blog/json-in-firefox/) to see what comes back from a given URL.

Get object id 889, including set and unset attributes:

https://racktables.example.com/api.php?method=get_object&object_id=889&include_attrs=1&include_unset_attrs=1

Add an object:

https://racktables.example.com/api.php?method=add_object&object_name=my-new-server&object_type_id=4&object_label=some_label&object_asset_no=some_asset_number

Change object id 100's allocation to: rack ID 10, position 4, front middle and rear:

https://racktables.example.com/api.php?method=update_object_allocation&object_id=100&allocate_to[]=atom_10_4_0&allocate_to[]=atom_10_4_1&allocate_to[]=atom_10_4_2

Assign tags with ids 40 and 50 to object id 100 (replaces the existing ones):

https://racktables.example.com/api.php?method=update_object_tags&object_id=100&taglist[]=40&taglist[]=50

Get the overall rackspace layout (comes back as a list of rows, within which are found the racks): https://racktables.example.com/api.php?method=get_rackspace

Get all objects: https://racktables.example.com/api.php?method=get_depot

Get all servers (servers have object type id 4): https://racktables.example.com/api.php?method=get_depot&cfe={$typeid_4}

Get all VMs (type 1504), including their attributes (this _significantly_increases the amount of data that comes back, so be careful with large installations):

https://racktables.example.com/api.php?method=get_depot&cfe={$typeid_1504}&include_attrs=1

Get all objects that have tag id 131 and attribute ID 2 set to 50018 (happens to be "HW type" == "HP ProLiant DL360 G5" in our case)

https://racktables.example.com/api.php?method=get_depot&object_details=1&andor=and&cft[]=131&cfe={$attr_2_50004} (this follows Racktables' own UI semantics for filtering objects, which is admittedly cryptic)

Hope that helps!

Cheers, Ian

— Reply to this email directly or view it on GitHubhttps://github.com/ibettinger/racktables/issues/5#issuecomment-11584481.

ibettinger commented 11 years ago

Just put it up. :)

https://github.com/ibettinger/racktables-py-client/blob/master/lib/racktables/client.py

I'll change but should be 99% compatible with the current API.

Once I set up the upstream branching it will track the API published here much more closely. That'll be post holidays for sure though.

Enjoy!

--Ian