guestconv will be a new, re-usable library to perform guest OS conversions when moving between hypervisors.
I've attached 3 files to this email which are relevant to the proposed API. guestconv.h is the proposed C binding. example.c is the simplest possible usage of the API. It converts the first detected root of the guest, accepting all defaults. root.xml is an example description returned by inspection. The first 2 should be self-explanatory, but root.xml requires more explanation. /guestconv/info contains generic information about the detected guest OS. It can't be modified. /guestconv/devices contains a list of detected devices. It can be modified to affect the choice of driver for each device. Each element has an id which uniquely identifies the specific device of a particular type, and the selected driver. Available driver options are given as child elements. If an element is deleted from /guestconv/devices it will be unconfigured. There are a couple of potential issues I see with it myself: Firstly, modifying XML isn't the cleanest API ever. However, I can't think of a better solution which would be similarly flexible, and work well with language bindings. Secondly, it doesn't cover the case of an EC2->KVM conversion where you will need to do additional transformations before conversion. Specifically you'll need to add a partition table and boot loader. You could potentially argue that this kind of transformation is out of scope for the tool. However, it would introduce changes that you would have to take into account during conversion due to altered device names. I think we need to be able to support it without a major API change, even if we don't support it initially. I'll try to post an update which supports this, although ideas are welcome in the meantime. Matt
#include <guestconv.h>
int
main(int argc, char *argv[])
{
guestconv_err *err = NULL;
guestconv_h *h = guestconv_create(&err);
if (h == NULL) goto error;
if (guestconv_add_drive(h, "test.img", "sda", &err) != 0)
goto error;
guestconv_root **roots = guestconv_inspect(h, "rhev-3.1", &err);
if (roots == NULL) goto error;
if (roots[0] == NULL) {
fprintf(stderr, "Didn't find an OS\n");
return 1;
}
if (guestconv_convert(h, roots[0], &err) != 0)
goto error;
printf("Success\n");
return 0;
error:
fprintf(stderr, "%s\n", err->message);
return 1;
}
typedef struct guestconv_h guestconv_h;
typedef struct {
char *root;
char *desc;
} guestconv_root;
typedef struct {
int code;
char *message;
} guestconv_err;
guestconv_h *guestconv_create(guestconv_err **err);
guestconv_h *guestconv_create_uid(uid_t uid, gid_t gid, guestconv_err **err);
int guestconv_close(guestconv_h *h);
int guestconv_add_drive(guestconv_h *h, char *path, char *hint,
guestconv_err **err);
guestconv_root **guestconv_inspect(guestconv_h *h, char *target,
guestconv_err **err);
int guestconv_convert(guestconv_h *h, guestconv_root *root,
guestconv_err **err);
void guestconv_err_free(guestconv_err *err);
root.xml
Description: XML document
_______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
