Skip to content

Commit 39fe2d1

Browse files
committed
Merge pull request #167 from djs55/add-api-extensions
Add XenAPI extension doc to the XenAPI guide
2 parents efb096f + 76d4505 commit 39fe2d1

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

_data/navbar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
docs:
7272
- devguide/howtos/add-field.md
7373
- devguide/howtos/add-function.md
74+
- devguide/howtos/add-api-extension.md
7475
-
7576
- title: Design Docs
7677
docs:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Adding a XenAPI extension
3+
layout: default
4+
---
5+
6+
A XenAPI extension is a new RPC which is implemented as a separate executable
7+
(i.e. it is not part of `xapi`)
8+
but which still benefits from `xapi` parameter type-checking, multi-language
9+
stub generation, documentation generation, authentication etc.
10+
An extension can be backported to previous versions by simply adding the
11+
implementation, without having to recompile `xapi` itself.
12+
13+
A XenAPI extension is in two parts:
14+
15+
1. a declaration in the [xapi datamodel](https://github.com/xapi-project/xen-api/blob/07056d661bbf58b652e1da59d9adf67a778a5626/ocaml/idl/datamodel.ml#L5608).
16+
This must use the `~forward_to:(Extension "filename")` parameter. The filename must be unique, and
17+
should be the same as the XenAPI call name.
18+
2. an implementation executable in the dom0 filesystem with path `/etc/xapi.d/extensions/filename`
19+
20+
To define an extension
21+
----------------------
22+
23+
First write the declaration in the datamodel. The act of specifying the
24+
types and writing the documentation will help clarify the intended meaning
25+
of the call.
26+
27+
Second create a prototype of your implementation and put an executable file
28+
in `/etc/xapi.d/extensions/filename`. The calling convention is:
29+
30+
- the file must be executable
31+
- `xapi` will parse the XMLRPC call arguments received over the network and check the `session_id` is
32+
valid
33+
- `xapi` will execute the named executable
34+
- the XMLRPC call arguments will be sent to the executable on `stdin` and
35+
`stdin` will be closed afterwards
36+
- the executable will run and print an XMLRPC response on `stdout`
37+
- `xapi` will read the response and return it to the client.
38+
39+
See the [basic example](https://github.com/xapi-project/xen-api/blob/07056d661bbf58b652e1da59d9adf67a778a5626/scripts/extensions/Test.test).
40+
41+
Second make a [pull request](https://github.com/xapi-project/xen-api/pulls)
42+
containing only the datamodel definitions (it is not necessary to include the
43+
prototype too).
44+
This will attract review comments which will help you improve your API further.
45+
Once the pull request is merged, then the API call name and extension are officially
46+
yours and you may use them on any xapi version which supports the extension mechanism.
47+
48+
Packaging your extension
49+
------------------------
50+
51+
Your extension `/etc/xapi.d/extensions/filename` (and dependencies) should be
52+
packaged for your target distribution (for XenServer dom0 this would be a CentOS
53+
RPM). Once the package is unpacked on the target machine, the extension should
54+
be immediately callable via the XenAPI, provided the `xapi` version supports
55+
the extension mechanism. Note the `xapi` version does not need to know about
56+
the specific extension in advance: it will always look in `/etc/xapi.d/extensions/` for
57+
all RPC calls whose name it does not recognise.
58+
59+
Limitations
60+
-----------
61+
62+
On type-checking
63+
64+
- if the `xapi` version is new enough to know about your specific extension:
65+
`xapi` will type-check the call arguments for you
66+
- if the `xapi` version is too old to know about your specific extension:
67+
the extension will still be callable but the arguments will not be type-checked.
68+
69+
On access control
70+
71+
- if the `xapi` version is new enough to know about your specific extension:
72+
you can declare that a user must have a particular role (e.g. 'VM admin')
73+
- if the `xapi` version is too old to know about your specific extension:
74+
the extension will still be callable but the client must have the 'Pool admin' role.
75+
76+
Since a `xapi` which knows about your specific extension is stricter than an older
77+
`xapi`, it's a good idea to develop against the new `xapi` and then test older
78+
`xapi` versions later.
79+
80+

0 commit comments

Comments
 (0)