Skip to content

Commit 43eb380

Browse files
added information describing more paramaters on the devguid/howtos/add-function page.
Signed-off-by: James Hensman <[email protected]>
1 parent db64b4f commit 43eb380

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

devguide/howtos/add-function.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ The function to describe the new message will look something like the following:
2424
~name:"price_of"
2525
~in_oss_since:None
2626
~in_product_since:rel_orlando
27-
~params:[Ref _host, "host", "The host containing the price information";
28-
String, "item", "The item whose price is queried"]
27+
~params:[(Ref _host, "host", "The host containing the price information");
28+
(String, "item", "The item whose price is queried")]
2929
~result:(Float, "The price of the item")
3030
~doc:"Returns the price of a named item."
3131
~allowed_roles:_R_POOL_OP
@@ -49,22 +49,33 @@ The parameters passed to call are all optional (except ~name and ~in_product_sin
4949
presence of an existing session.
5050

5151
- The value of the ~in_product_since parameter is a string taken from
52-
`idl/datamodel_types.ml` indicating the XenServer release in which this
52+
`idl/datamodel_types.ml` indicates the XenServer release in which this
5353
message was first introduced.
5454

5555
- The ~params parameter describes a list of the formal parameters of the message.
5656
Each parameter is described by a triple. The first component of the triple is
5757
the type (from type ty in `idl/datamodel_types.ml`); the second is the name
58-
of the parameter; the third is a human-readable description of the parameter.
58+
of the parameter, and the third is a human-readable description of the parameter.
5959
The first triple in the list is conventionally the instance of the class on
6060
which the message will operate. In the example, this is a reference to the host.
6161

6262
- Similarly, the ~result describes the message's return type, although this is
6363
permitted to merely be a single value rather than a list of values. If no
6464
~result is specified, the default is unit.
6565

66+
- The ~doc parameter describes what the message is doing.
67+
68+
- The bool ~hide_from_docs parameter prevents the message from being included in the documentation when generated.
69+
70+
- The bool ~pool_internal parameter is used to indicate if the message should be callable by external systems or only internal hosts.
71+
72+
- The ~errs parameter is a list of possible exceptions that the message can raise.
73+
74+
- The parameter ~lifecycle takes in an array of (Status, version, doc) to indicate the lifecycle of the message type. This takes over from ~in_oss_since which indicated the release that the message type was introduced. NOTE: Leave this parameter empty, it will be populated on build.
75+
6676
- The ~allowed_roles parameter is used for access control (see below).
6777

78+
6879
Compiling `xen-api.(hg|git)` will cause the code corresponding to this message
6980
to be generated and output in `ocaml/xapi/server.ml`. In the example above, a
7081
section handling an incoming call host.price_of appeared in `ocaml/xapi/server.ml`.
@@ -190,7 +201,7 @@ the Host module:
190201
info "Host.price_of for item %s" item;
191202
let local_fn = Local.Host.price_of ~host ~item in
192203
do_op_on ~local_fn ~__context ~host
193-
(fun session_id rpc -> Client.Host.price_of rpc session_id host item)
204+
(fun session_id rpc -> Client.Host.price_of ~rpc ~session_id ~host ~item)
194205

195206
After the ~__context parameter, the parameters of this new function should
196207
match the parameters we specified for the message. In this case, that is the
@@ -220,7 +231,7 @@ Congratulations, you've added a function to the API!
220231
Add the operation to the CLI
221232
----------------------------
222233

223-
Edit `xapi/cli_frontend.ml`. Add a block to the definition of cmdtable_data as
234+
Edit `xapi-cli-server/cli_frontend.ml`. Add a block to the definition of cmdtable_data as
224235
in the following example:
225236

226237
"host-price-of",
@@ -249,14 +260,14 @@ Include here the following:
249260
- *Deprecated of string list:*
250261

251262
Now we must implement `Cli_operations.host_price_of`. This is done in
252-
`xapi/cli_operations.ml`. This function typically extracts the parameters and
263+
`xapi-cli-server/cli_operations.ml`. This function typically extracts the parameters and
253264
forwards them to the internal implementation of the function. Other arbitrary
254265
code is permitted. For example:
255266

256267
let host_price_of printer rpc session_id params =
257268
let host = Client.Host.get_by_uuid rpc session_id (List.assoc "host-uuid" params) in
258269
let item = List.assoc "item" params in
259-
let price = string_of_float (Client.Host.price_of rpc session_id host item) in
270+
let price = string_of_float (Client.Host.price_of ~rpc ~session_id ~host ~item) in
260271
printer (Cli_printer.PList [price])
261272

262273
Tab Completion in the CLI

0 commit comments

Comments
 (0)