guestfs-lua(3)

НАЗВА
guestfs-lua - How to use libguestfs from Lua

КОРОТКИЙ ОПИС
 local G = require "guestfs"
 g = G.create ()
 g:add_drive ("test.img", { format = "raw", readonly = true })
 g:launch ()
 devices = g:list_devices ()
 g:close ()

ОПИС
This manual page documents how to call libguestfs from the Lua programming language. This page just documents the differences from the C API and gives some examples. If you are not familiar with using libguestfs, you also need to read guestfs(3).

  REQUIRING THE MODULE
"require "guestfs"" returns the module, so you have to assign it to a local variable. Typical usage is:

 local G = require "guestfs"

(you can use any name you want instead of "G", but in the examples in this man page we always use "G").

  OPENING AND CLOSING THE HANDLE
To create a new handle, call:

 g = G.create ()

You can also use the optional arguments:

 g = G.create { environment = 0, close_on_exit = 0 }

to set the flags "GUESTFS_CREATE_NO_ENVIRONMENT" and/or "GUESTFS_CREATE_NO_CLOSE_ON_EXIT".

The handle will be closed by the garbage collector, but you can also close it explicitly by doing:

 g:close ()

  ЯК ВИКЛИКАТИ МЕТОДИ
Use the ordinary Lua convention for calling methods on the handle. For example:

 g:set_verbose (true)

  ФУНКЦІЇ І ДОДАТКОВІ ПАРАМЕТРИ
For functions that take optional arguments, the first arguments are the non-optional ones. The optional final argument is a table supplying the optional arguments.

 g:add_drive ("test.img")

або:

 g:add_drive ("test.img", { format = "raw", readonly = true })

  64-БІТОВІ ЗНАЧЕННЯ
Currently 64 bit values must be passed as strings, and are returned as strings. This is because 32 bit Lua cannot handle 64 bit integers properly. We hope to come up with a better solution later.

  ПОМИЛКИ
Most (but not all) errors are converted into objects (ie. tables) containing the following fields:

msg The error message (corresponding to "guestfs_last_error" in guestfs(3)).

code
    The "errno" (corresponding to "guestfs_last_errno" in guestfs(3)).

These objects also have "__tostring" functions attached to them so you can use "tostring" (or implicit conversion) to convert them into printable strings.

Note that the library also throws some errors as plain strings. You may need to check the type.

  ПОДІЇ
Реєструвати події можна за допомогою викликів "set_event_callback":

 eh = g:set_event_callback (cb, "close")

or to register a single callback for multiple events make the second argument a list:

 eh = g:set_event_callback (cb, { "appliance", "library", "trace" })

A list of all valid event types (strings) is in the global variable "G.event_all".

The callback ("cb") is called with the following parameters:

 function cb (g, event, eh, flags, buf, array)
   -- g is the guestfs handle
   -- event is a string which is the name of the event that fired
   -- flags is always zero
   -- buf is the data buffer (eg. log message etc)
   -- array is the array of 64 bit ints (eg. progress bar status etc)
   ...
 end

You can also remove a callback using the event handle ("eh") that was returned when you registered the callback:

 g:delete_event_callback (eh)

ПРИКЛАД 1. СТВОРЕННЯ ОБРАЗУ ДИСКА
@EXAMPLE1@

ПРИКЛАД 2. ПЕРЕВІРКА ОБРАЗУ ДИСКА ВІРТУАЛЬНОЇ МАШИНИ
@EXAMPLE2@

ТАКОЖ ПЕРЕГЛЯНЬТЕ
guestfs(3), guestfs-examples(3), guestfs-erlang(3), guestfs-golang(3), guestfs-java(3), guestfs-ocaml(3), guestfs-perl(3), guestfs-python(3), guestfs-recipes(1), guestfs-ruby(3), http://www.lua.org/, http://libguestfs.org/.

АВТОРИ
Richard W.M. Jones ("rjones at redhat dot com")

АВТОРСЬКІ ПРАВА
© Red Hat Inc., 2012

LICENSE

BUGS
To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools

To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools

When reporting a bug, please supply:

•   The version of libguestfs.

•   Where you got libguestfs (eg. which Linux distro, compiled from source, etc)

•   Describe the bug accurately and give a way to reproduce it.

•   Run libguestfs-test-tool(1) and paste the complete, unedited output into the bug report.