Files
xen-orchestra/packages/xen-api
2015-11-11 15:52:06 +01:00
..
2015-10-23 16:53:42 +02:00
2015-11-11 15:52:06 +01:00
2015-04-02 18:44:16 +02:00
2015-11-11 15:52:06 +01:00
2015-10-23 15:33:02 +02:00
2015-06-18 13:15:27 +02:00
2015-06-17 17:09:46 +02:00
2015-09-10 15:22:09 +02:00
2015-11-11 15:52:06 +01:00
2015-10-23 14:51:25 +02:00

xen-api Build Status

Connector to the Xen API

Tested with:

  • Xen Server 5.6
  • Xen Server 6.2
  • Xen Server 6.5

Install

Installation of the npm package:

> npm install --save xen-api

Usage

Library

var createClient = require('xen-api').createClient

var xapi = createClient({
  url: 'https://xen1.company.net',
  auth: {
    user: 'root',
    password: 'important secret password'
  },
  readOnly: false
})

Options:

  • url: address of a host in the pool we are trying to connect to
  • auth: credentials used to sign in
  • readOnly = false: if true, no methods with side-effects can be called
// Force connection.
xapi.connect().catch(error => {
  console.error(error)
})

// Watch objects.
xapi.objects.on('add', function (objects) {
  console.log('new objects:', objects)
})

Note: all objects are frozen and cannot be altered!

Custom fields on objects (hidden ie. non enumerable):

  • $type: the type of the object (VM, task, …);
  • $ref: the (opaque) reference of the object;
  • $id: the identifier of this object (its UUID if any, otherwise its reference);
  • $pool: the pool object this object belongs to.

Furthermore, any field containing a reference (or references if an array) can be resolved by prepending the field name with a $:

console.log(xapi.pool.$master.$resident_VMs[0].name_label)
// vm1

CLI

A CLI is provided to help exploration and discovery of the XAPI.

> xen-api https://xen1.company.net root
Password: ******
root@xen1.company.net> xapi.status
'connected'
root@xen1.company.net> xapi.pool.master
'OpaqueRef:ec7c5147-8aee-990f-c70b-0de916a8e993'
root@xen1.company.net> xapi.pool.$master.name_label
'xen1'

To ease searches, find() and findAll() functions are available:

root@xen1.company.net> findAll({ $type: 'VM' }).length
183

Development

Installing dependencies

> npm install

Compilation

The sources files are watched and automatically recompiled on changes.

> npm run dev

Tests

> npm run test-dev

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet