2018-01-27 23:46:39 +03:00
#!/usr/bin/env python3
2018-01-21 23:07:31 +03:00
import argparse
import os
import sys
2020-02-02 16:49:06 +03:00
sys . path . insert ( 0 , os . path . dirname ( os . path . dirname ( __file__ ) ) )
from virtinst import URI
2018-01-21 23:07:31 +03:00
def parse_options ( ) :
description = ( " Generate a fake URI for use with virt-manager/virtinst "
" that wraps a standard test:/// URI but pretends to be a different "
" hypervisor. See virtinst/uri.py MagicURI for format details. "
2020-02-02 16:49:06 +03:00
" Example: magicuri.py qemu+tcp://fakeuri.example.com/system " )
2018-01-21 23:07:31 +03:00
parser = argparse . ArgumentParser ( description = description )
2020-02-02 16:49:06 +03:00
parser . add_argument ( " fakeuri " ,
help = " The libvirt URI we should fake " )
2018-01-21 23:07:31 +03:00
parser . add_argument ( " --capsfile " ,
help = " Path to file to use for capabilities XML " )
parser . add_argument ( " --domcapsfile " ,
help = " Path to file to use for domain capabilities XML " )
parser . add_argument ( " --driverxml " ,
help = " Path to driver xml (defaults to testdriver.xml) " )
options = parser . parse_args ( )
2018-09-02 17:06:44 +03:00
testdir = os . path . abspath ( os . path . dirname ( __file__ ) )
2020-01-27 02:11:43 +03:00
capsdir = os . path . join ( testdir , " data/capabilities/ " )
2018-01-21 23:07:31 +03:00
2020-02-02 16:49:06 +03:00
uriobj = URI ( options . fakeuri )
hv = uriobj . scheme
2018-01-21 23:07:31 +03:00
capsfile = None
domcapsfile = None
if hv == " qemu " :
capsfile = capsdir + " kvm-x86_64.xml "
domcapsfile = capsdir + " kvm-x86_64-domcaps.xml "
elif hv == " xen " :
capsfile = capsdir + " xen-rhel5.4.xml "
elif hv == " lxc " :
capsfile = capsdir + " lxc.xml "
elif hv == " vz " :
capsfile = capsdir + " vz.xml "
if options . capsfile :
capsfile = os . path . abspath ( options . capsfile )
if options . domcapsfile :
domcapsfile = os . path . abspath ( options . domcapsfile )
driverxml = os . path . join ( testdir , " testdriver.xml " )
if options . driverxml :
driverxml = os . path . abspath ( options . driverxml )
2020-02-02 16:49:06 +03:00
return options . fakeuri , capsfile , domcapsfile , driverxml
2018-01-21 23:07:31 +03:00
def main ( ) :
2020-02-02 16:49:06 +03:00
fakeuri , capsfile , domcapsfile , driverxml = parse_options ( )
2018-01-21 23:07:31 +03:00
uri = " __virtinst_test__test:// %s " % driverxml
2020-02-02 16:49:06 +03:00
uri + = " ,fakeuri= %s " % fakeuri
2018-01-21 23:07:31 +03:00
if capsfile :
uri + = " ,caps= %s " % capsfile
if domcapsfile :
uri + = " ,domcaps= %s " % domcapsfile
if driverxml and not os . path . exists ( driverxml ) :
print ( " %s does not exist " % capsfile )
return 1
if capsfile and not os . path . exists ( capsfile ) :
print ( " %s does not exist " % capsfile )
return 1
if domcapsfile and not os . path . exists ( domcapsfile ) :
print ( " %s does not exist " % domcapsfile )
return 1
print ( uri )
return 0
if __name__ == " __main__ " :
sys . exit ( main ( ) )