XenAPI.rb¶
Description¶
A Ruby port of the XenAPI.py API client of Citrix XenServer.
This library was developed and tested on MRI Ruby 1.8.7. But as it let's Ruby's XMLRPC library handle the heavy lifting, I would expect it to run on most other Ruby implementations too. If you find a bug, just create a new ticket.
Note: This library is in no way endorsed or supported by Citrix or XenSource and is provided as is. It is probably useful, but might also neuter your dog, sleep with your wife, and sell your house on eBay. So don't blame me.
Restrictions¶
Due to restrictions of Ruby's XMLRPC client library and ultimately net/http, this library currently only support the TCP transport. Local sockets are thus not supported for now. But you can always connect to http://localhost to avoid the SSL overhead locally.
Usage Examples¶
Getting started¶
For general information about how to use the XenServer API, see the Citrix XenServer SDK documentation. The complete XenAPI specification is also available.
To download other variants of the SDK or additional information, go to the Citrix's Downlopad SDKs page.
List all VMs on a server¶
1 require 'xenapi'
2
3 # first create a connection and login
4 session = XenAPI::Session.new('https://xen-server.example.com')
5 begin
6 session.login_with_password('root', 'supersecret')
7
8 # Now we can use the whole API directly via the session object.
9 # In this example, we just list all available VMs on the server
10 vms = session.VM.get_all
11 vms.each do |vm|
12 record = session.VM.get_record(vm)
13 unless record['is_a_template'] || record['is_control_domain']
14 name = record['name_label']
15 puts "Found VM uuid #{record['uuid']} called #{name}"
16 end
17 end
18 ensure
19 # make sure we clean up after us
20 session.logout
21 end
License¶
Short version¶
take my code with you
and do whatever you want
but please don’t blame me
Legal version¶
Copyright (c) 2009–2011 Holger Just
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.