Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/01ac69ff3d5585052102 to your computer and use it in GitHub Desktop.
Save anonymous/01ac69ff3d5585052102 to your computer and use it in GitHub Desktop.
import System.LibVirt
import Control.Monad
main = do
c <- openConnection "qemu:///system"
putStrLn "opened connection"
void $ defineDomainXML c xml
putStrLn "defined domain"
void $ closeConnection c
putStrLn "closed connection"
xml = "<domain type=\"qemu\">\
\ <name>TEST-03</name>\
\ <title>test from wiki</title>\
\ <vcpu>1</vcpu>\
\ <memory unit='KiB'>83886</memory>\
\ <os>\
\ <type arch=\"x86_64\">hvm</type>\
\ </os>\
\ <clock sync=\"localtime\"/>\
\ <devices>\
\ <emulator>/usr/bin/qemu-system-x86_64</emulator>\
\ <disk type=\"file\" device=\"disk\">\
\ <source file=\"/var/lib/vm-mon/domains/TEST-03/IMAGE\"/>\
\ <target dev=\"hda\"/>\
\ </disk>\
\ </devices>\
\</domain>"
@qrilka
Copy link

qrilka commented Dec 21, 2012

C - no errors:

#include <stdlib.h>
#include <stdio.h>
#include <libvirt/libvirt.h>

int main(int argc, char **argv) {
    virConnectPtr conn = NULL;
    conn = virConnectOpenAuth("qemu:///system", virConnectAuthPtrDefault, 0);
    if (conn == NULL) {
            fprintf(stderr, "Failed to connect to hypervisor\n");
            goto error;
    }

    virDomainDefineXML(conn, "<domain type=\"kvm\">"
    "<name>TEST-03</name>"
    "<title>test from wiki</title>"
    "<vcpu>1</vcpu>"
    "<memory unit='KiB'>83886</memory>"
    "<os>"
    "   <type arch=\"x86_64\">hvm</type>"
    "</os>"
    "<clock sync=\"localtime\"/>"
    "<devices>"
    "   <emulator>/usr/bin/qemu-system-x86_64</emulator>"
    "   <disk type=\"file\" device=\"disk\">"
    "       <source file=\"/var/lib/vm-mon/files/hvmmuser/linux-0.2.img\"/>"
    "       <target dev=\"hda\"/>"
    "   </disk>"
    "</devices>"
    "</domain>");

error:
    if (conn != NULL)
        virConnectClose(conn);
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment