import virtinst
from virtinst import VirtualDisk as vd
from virtinst.Storage import StoragePool as sp
from virtinst.Storage import StorageVolume as sv

import logging
import sys
import libvirt

# Set debug logging to print
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler(sys.stderr)
streamHandler.setLevel(logging.DEBUG)
root_logger.addHandler(streamHandler)

LOCAL_CONN  = "qemu:///system"
REMOTE_CONN = "qemu+ssh://localhost/system"

POOL = "default"
VOL  = "test.img"
GUESTNAME="testguest"

GOODSIZE=5*1024*1024*1024
BADSIZE=10000*1024*1024*1024

print "open conn"
localconn = libvirt.open(LOCAL_CONN)
print "get pool"
pool = localconn.storagePoolLookupByName(POOL)
print "get vol"
vol = pool.storageVolLookupByName(VOL)

print "get pooltype"
pooltype = virtinst.util.get_xml_path(pool.XMLDesc(0), "/pool/@type")
print "get volclass"
volclass = sp.get_volume_for_pool(pooltype)

print "create volclass instance"
volinst = volclass(name="testguest", pool=pool, capacity=GOODSIZE)

def check_disk(disk):

    print "\nis_conflict_disk:"
    print d.is_conflict_disk(localconn)

    print "\nis_size_conflict:"
    print d.is_size_conflict()

    print "\nget_xml_config()"
    print d.get_xml_config("hda")
    print "\n"

print "\n\nCreating volobj disk:"
d = vd(volobj=vol)
check_disk(d)

print "\n\nCreating volinst disk:"
d = vd(volinstall=volinst)
check_disk(d)
