mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-26 21:57:33 +03:00
Make conn required for all virtinst objects
This was the way the API had been heading, this just formalizes it.
This commit is contained in:
parent
be2d9ddcb4
commit
57e86259d8
@ -33,8 +33,6 @@ class TestImageParser(unittest.TestCase):
|
||||
basedir = "tests/image-xml/"
|
||||
conn = utils.open_testdefault()
|
||||
qemuconn = virtinst.cli.getConnection(qemuuri)
|
||||
caps = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
|
||||
qemucaps = virtinst.CapabilitiesParser.parse(qemuconn.getCapabilities())
|
||||
|
||||
def testImageParsing(self):
|
||||
f = open(os.path.join(self.basedir, "image.xml"), "r")
|
||||
@ -62,7 +60,7 @@ class TestImageParser(unittest.TestCase):
|
||||
"""Makes sure we sanitize i386->i686"""
|
||||
image = virtinst.ImageParser.parse_file(self.basedir +
|
||||
"image-bad-arch.xml")
|
||||
virtinst.ImageInstaller(image, self.caps, 0)
|
||||
virtinst.ImageInstaller(self.conn, image, 0)
|
||||
self.assertTrue(True)
|
||||
|
||||
def testStorageFormat(self):
|
||||
@ -76,13 +74,11 @@ class TestImageParser(unittest.TestCase):
|
||||
output_xmls = [output_xmls]
|
||||
|
||||
conn = qemu and self.qemuconn or self.conn
|
||||
caps = qemu and self.qemucaps or self.caps
|
||||
gtype = qemu and "qemu" or "xen"
|
||||
|
||||
for idx in range(len(output_xmls)):
|
||||
fname = output_xmls[idx]
|
||||
inst = virtinst.ImageInstaller(image, caps, boot_index=idx,
|
||||
conn=conn)
|
||||
inst = virtinst.ImageInstaller(conn, image, boot_index=idx)
|
||||
|
||||
utils.set_conn(conn)
|
||||
|
||||
|
@ -41,7 +41,7 @@ class TestInterfaces(unittest.TestCase):
|
||||
|
||||
def build_interface(self, interface_type, name):
|
||||
iclass = Interface.interface_class_for_type(interface_type)
|
||||
iobj = iclass(name, conn)
|
||||
iobj = iclass(conn, name)
|
||||
|
||||
return iobj
|
||||
|
||||
|
@ -176,7 +176,7 @@ def get_basic_paravirt_guest(installer=None):
|
||||
g.memory = int(200)
|
||||
g.maxmemory = int(400)
|
||||
g.uuid = "12345678-1234-1234-1234-123456789012"
|
||||
g.add_device(VirtualGraphics("vnc", keymap="ja"))
|
||||
g.add_device(VirtualGraphics(_conn, "vnc", keymap="ja"))
|
||||
g.vcpus = 5
|
||||
|
||||
if installer:
|
||||
@ -197,7 +197,7 @@ def get_basic_fullyvirt_guest(typ="xen", installer=None):
|
||||
g.maxmemory = int(400)
|
||||
g.uuid = "12345678-1234-1234-1234-123456789012"
|
||||
g.cdrom = "/dev/loop0"
|
||||
g.add_device(VirtualGraphics("sdl"))
|
||||
g.add_device(VirtualGraphics(_conn, "sdl"))
|
||||
g.features['pae'] = 0
|
||||
g.vcpus = 5
|
||||
if installer:
|
||||
@ -239,7 +239,7 @@ def build_win_kvm(path=None):
|
||||
g.add_device(get_filedisk(path))
|
||||
g.add_device(get_blkdisk())
|
||||
g.add_device(get_virtual_network())
|
||||
g.add_device(VirtualAudio())
|
||||
g.add_device(VirtualAudio(g.conn))
|
||||
g.add_device(VirtualVideoDevice(g.conn))
|
||||
|
||||
return g
|
||||
@ -248,21 +248,21 @@ def build_win_kvm(path=None):
|
||||
def get_floppy(path=None):
|
||||
if not path:
|
||||
path = "/default-pool/testvol1.img"
|
||||
return VirtualDisk(path, conn=_conn, device=VirtualDisk.DEVICE_FLOPPY)
|
||||
return VirtualDisk(_conn, path, device=VirtualDisk.DEVICE_FLOPPY)
|
||||
|
||||
|
||||
def get_filedisk(path=None):
|
||||
if not path:
|
||||
path = "/tmp/test.img"
|
||||
return VirtualDisk(path, size=.0001, conn=_conn)
|
||||
return VirtualDisk(_conn, path, size=.0001)
|
||||
|
||||
|
||||
def get_blkdisk(path="/dev/loop0"):
|
||||
return VirtualDisk(path, conn=_conn)
|
||||
return VirtualDisk(_conn, path)
|
||||
|
||||
|
||||
def get_virtual_network():
|
||||
dev = virtinst.VirtualNetworkInterface(conn=_conn)
|
||||
dev = virtinst.VirtualNetworkInterface(_conn)
|
||||
dev.macaddr = "22:22:33:44:55:66"
|
||||
dev.type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
|
||||
dev.network = "default"
|
||||
|
@ -107,15 +107,6 @@ args = {
|
||||
'__init__' : {
|
||||
|
||||
'invalid' : [
|
||||
{'path' : 0},
|
||||
{'path' : '/root'},
|
||||
{'path' : 'valid', 'size' : None},
|
||||
{'path' : "valid", 'size' : 'invalid'},
|
||||
{'path' : 'valid', 'size' : -1},
|
||||
{'path' : None},
|
||||
{'path' : "noexist1", 'size' : 900000, 'sparse' : False},
|
||||
{'path' : "noexist2", 'type' : VirtualDisk.DEVICE_CDROM},
|
||||
{'volName' : ("default-pool", "default-vol")},
|
||||
{'conn' : testconn, 'volName' : ("pool-noexist", "default-vol")},
|
||||
{'conn' : testconn, 'volName' : ("default-pool", "vol-noexist")},
|
||||
{'conn' : testconn, 'volName' : (1234, "vol-noexist")},
|
||||
@ -127,16 +118,10 @@ args = {
|
||||
],
|
||||
|
||||
'valid' : [
|
||||
{'path' : '/dev/loop0'},
|
||||
{'path' : 'nonexist', 'size' : 1},
|
||||
{'path' : '/dev/null'},
|
||||
{'path' : None, 'device' : VirtualDisk.DEVICE_CDROM},
|
||||
{'path' : None, 'device' : VirtualDisk.DEVICE_FLOPPY},
|
||||
{'conn' : testconn, 'volName' : ("default-pool", "default-vol")},
|
||||
{'conn' : testconn, 'path' : "/default-pool/default-vol"},
|
||||
{'conn' : testconn, 'path' : "/default-pool/vol-noexist", 'size' : 1},
|
||||
{'conn' : testconn, 'volInstall': volinst},
|
||||
{'path' : 'nonexist', 'size' : 1, 'driverCache' : 'writethrough'},
|
||||
# Full pool, but we are nonsparse
|
||||
{'conn' : testconn, "path" : "/full-pool/newvol.img", "size" : 1},
|
||||
]
|
||||
@ -148,8 +133,17 @@ args = {
|
||||
},
|
||||
},
|
||||
|
||||
'network' : {
|
||||
'init_conns' : [testconn],
|
||||
'__init__' : {
|
||||
'invalid' : [{'macaddr' : 0}, {'macaddr' : ''}, {'macaddr' : '$%XD'},
|
||||
{'type' : 'network'}],
|
||||
'valid' : []}
|
||||
},
|
||||
|
||||
|
||||
'installer' : {
|
||||
'init_conns' : [testconn, None],
|
||||
'init_conns' : [testconn],
|
||||
'extraargs' : {
|
||||
'invalid' : [],
|
||||
'valid' : ['someargs']},
|
||||
@ -160,7 +154,7 @@ args = {
|
||||
},
|
||||
|
||||
'distroinstaller' : {
|
||||
'init_conns' : [testconn, None],
|
||||
'init_conns' : [testconn],
|
||||
'location' : {
|
||||
'invalid' : ['nogood', 'http:/nogood', [], None,
|
||||
("pool-noexist", "default-vol"),
|
||||
@ -172,7 +166,7 @@ args = {
|
||||
},
|
||||
|
||||
'livecdinstaller' : {
|
||||
'init_conns' : [testconn, None],
|
||||
'init_conns' : [testconn],
|
||||
'location' : {
|
||||
'invalid' : ['path-noexist',
|
||||
("pool-noexist", "default-vol"),
|
||||
@ -182,26 +176,6 @@ args = {
|
||||
]}
|
||||
},
|
||||
|
||||
'imageinstaller' : {
|
||||
'__init__' : {
|
||||
'invalid' :
|
||||
[{'image' : virtimage, 'capabilities': testcaps, 'boot_index': 5},
|
||||
{'image' : virtimage, 'capabilities': "foo"}],
|
||||
'valid' :
|
||||
[{'image' : virtimage, 'capabilities': testcaps, 'boot_index': 1},
|
||||
{'image' : virtimage},
|
||||
{'image' : virtimage, 'capabilities': testcaps, 'conn': None}],
|
||||
}
|
||||
},
|
||||
|
||||
'network' : {
|
||||
'init_conns' : [testconn, None],
|
||||
'__init__' : {
|
||||
'invalid' : [{'macaddr' : 0}, {'macaddr' : ''}, {'macaddr' : '$%XD'},
|
||||
{'type' : 'network'}],
|
||||
'valid' : []}
|
||||
},
|
||||
|
||||
'clonedesign' : {
|
||||
'original_guest' : {
|
||||
'invalid' : ['idontexist'],
|
||||
@ -429,17 +403,17 @@ class TestValidation(unittest.TestCase):
|
||||
self._testArgs(g, virtinst.Guest, 'guest')
|
||||
|
||||
def testDiskValidation(self):
|
||||
disk = VirtualDisk("/dev/loop0")
|
||||
disk = VirtualDisk(testconn, "/dev/loop0")
|
||||
self._testArgs(disk, VirtualDisk, 'disk')
|
||||
|
||||
def testNetworkValidation(self):
|
||||
network = virtinst.VirtualNetworkInterface(conn=testconn)
|
||||
network = virtinst.VirtualNetworkInterface(testconn)
|
||||
self._testArgs(network, virtinst.VirtualNetworkInterface, 'network')
|
||||
|
||||
# Test dynamic MAC/Bridge success
|
||||
try:
|
||||
network = virtinst.VirtualNetworkInterface()
|
||||
network.setup(testconn)
|
||||
network = virtinst.VirtualNetworkInterface(testconn)
|
||||
network.setup()
|
||||
except Exception, e:
|
||||
raise AssertionError(
|
||||
"Network setup with no params failed, expected success." +
|
||||
@ -461,7 +435,7 @@ class TestValidation(unittest.TestCase):
|
||||
|
||||
label = 'distroinstaller'
|
||||
for conn in self._getInitConns(label):
|
||||
dinstall = virtinst.DistroInstaller(conn=conn)
|
||||
dinstall = virtinst.DistroInstaller(conn)
|
||||
self._testArgs(dinstall, virtinst.DistroInstaller, 'installer',
|
||||
exception_check)
|
||||
self._testArgs(dinstall, virtinst.DistroInstaller, label,
|
||||
@ -478,19 +452,12 @@ class TestValidation(unittest.TestCase):
|
||||
|
||||
label = 'livecdinstaller'
|
||||
for conn in self._getInitConns(label):
|
||||
dinstall = virtinst.LiveCDInstaller(conn=conn)
|
||||
dinstall = virtinst.LiveCDInstaller(conn)
|
||||
self._testArgs(dinstall, virtinst.LiveCDInstaller, 'installer',
|
||||
exception_check)
|
||||
self._testArgs(dinstall, virtinst.LiveCDInstaller, label,
|
||||
exception_check)
|
||||
|
||||
def testImageInstaller(self):
|
||||
label = 'imageinstaller'
|
||||
inst_obj = virtinst.ImageInstaller(image=virtimage,
|
||||
capabilities=testcaps)
|
||||
#self._testArgs(inst_obj, virtinst.ImageInstaller, 'installer')
|
||||
self._testArgs(inst_obj, virtinst.ImageInstaller, label)
|
||||
|
||||
def testCloner(self):
|
||||
label = 'clonedesign'
|
||||
for conn in self._getInitConns(label):
|
||||
@ -534,7 +501,7 @@ class TestValidation(unittest.TestCase):
|
||||
custom_dict[key] = paramdict[key]
|
||||
|
||||
for conn in self._getInitConns(label):
|
||||
iobj = iclass("foo-validation-test", conn)
|
||||
iobj = iclass(conn, "foo-validation-test")
|
||||
|
||||
self._testArgs(iobj, iclass, label, manual_dict=custom_dict)
|
||||
|
||||
|
@ -447,7 +447,7 @@ class TestXMLConfig(unittest.TestCase):
|
||||
g.add_device(utils.get_filedisk())
|
||||
g.add_device(utils.get_blkdisk())
|
||||
g.add_device(utils.get_virtual_network())
|
||||
g.add_device(VirtualAudio())
|
||||
g.add_device(VirtualAudio(g.conn))
|
||||
return g
|
||||
|
||||
utils.set_conn(utils.open_plainkvm(connver=11000))
|
||||
@ -468,11 +468,11 @@ class TestXMLConfig(unittest.TestCase):
|
||||
|
||||
def testKVMKeymap(self):
|
||||
conn = utils.open_plainkvm(connver=10000)
|
||||
g = virtinst.VirtualGraphics(conn=conn, type="vnc")
|
||||
g = virtinst.VirtualGraphics(conn, type="vnc")
|
||||
self.assertTrue(g.keymap is not None)
|
||||
|
||||
conn = utils.open_plainkvm(connver=11000)
|
||||
g = virtinst.VirtualGraphics(conn=conn, type="vnc")
|
||||
g = virtinst.VirtualGraphics(conn, type="vnc")
|
||||
self.assertTrue(g.keymap is None)
|
||||
|
||||
|
||||
@ -528,7 +528,7 @@ class TestXMLConfig(unittest.TestCase):
|
||||
g.add_device(utils.get_filedisk())
|
||||
g.add_device(utils.get_blkdisk())
|
||||
g.add_device(utils.get_virtual_network())
|
||||
g.add_device(VirtualAudio())
|
||||
g.add_device(VirtualAudio(g.conn))
|
||||
return g
|
||||
|
||||
utils.set_conn(utils.open_plainxen(connver=3000001))
|
||||
@ -546,21 +546,21 @@ class TestXMLConfig(unittest.TestCase):
|
||||
|
||||
g.add_device(utils.get_filedisk())
|
||||
g.add_device(utils.get_blkdisk())
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
g.add_device(VirtualDisk(g.conn, path="/dev/loop0",
|
||||
device=VirtualDisk.DEVICE_CDROM,
|
||||
driverType="raw"))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
g.add_device(VirtualDisk(g.conn, path="/dev/loop0",
|
||||
device=VirtualDisk.DEVICE_DISK,
|
||||
driverName="qemu", format="qcow2"))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path=None,
|
||||
g.add_device(VirtualDisk(g.conn, path=None,
|
||||
device=VirtualDisk.DEVICE_CDROM,
|
||||
bus="scsi"))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path=None,
|
||||
g.add_device(VirtualDisk(g.conn, path=None,
|
||||
device=VirtualDisk.DEVICE_FLOPPY))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
g.add_device(VirtualDisk(g.conn, path="/dev/loop0",
|
||||
device=VirtualDisk.DEVICE_FLOPPY,
|
||||
driverName="phy", driverCache="none"))
|
||||
disk = VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
disk = VirtualDisk(g.conn, path="/dev/loop0",
|
||||
bus="virtio", driverName="qemu",
|
||||
driverType="qcow2", driverCache="none")
|
||||
disk.driver_io = "threads"
|
||||
@ -572,15 +572,15 @@ class TestXMLConfig(unittest.TestCase):
|
||||
i = utils.make_pxe_installer()
|
||||
g = utils.get_basic_fullyvirt_guest(installer=i)
|
||||
|
||||
net1 = VirtualNetworkInterface(type="user",
|
||||
net1 = VirtualNetworkInterface(g.conn, type="user",
|
||||
macaddr="22:11:11:11:11:11")
|
||||
net2 = utils.get_virtual_network()
|
||||
net3 = utils.get_virtual_network()
|
||||
net3.model = "e1000"
|
||||
net4 = VirtualNetworkInterface(bridge="foobr0",
|
||||
net4 = VirtualNetworkInterface(g.conn, bridge="foobr0",
|
||||
macaddr="22:22:22:22:22:22")
|
||||
net4.target_dev = "foo1"
|
||||
net5 = VirtualNetworkInterface(type="ethernet",
|
||||
net5 = VirtualNetworkInterface(g.conn, type="ethernet",
|
||||
macaddr="00:11:00:22:00:33")
|
||||
net5.source_dev = "testeth1"
|
||||
|
||||
@ -612,10 +612,10 @@ class TestXMLConfig(unittest.TestCase):
|
||||
i = utils.make_pxe_installer()
|
||||
g = utils.get_basic_fullyvirt_guest(installer=i)
|
||||
|
||||
g.add_device(VirtualAudio("sb16", conn=g.conn))
|
||||
g.add_device(VirtualAudio("es1370", conn=g.conn))
|
||||
g.add_device(VirtualAudio("pcspk", conn=g.conn))
|
||||
g.add_device(VirtualAudio(conn=g.conn))
|
||||
g.add_device(VirtualAudio(g.conn, "sb16"))
|
||||
g.add_device(VirtualAudio(g.conn, "es1370"))
|
||||
g.add_device(VirtualAudio(g.conn, "pcspk"))
|
||||
g.add_device(VirtualAudio(g.conn))
|
||||
|
||||
self._compare(g, "boot-many-sounds", False)
|
||||
|
||||
@ -690,16 +690,15 @@ class TestXMLConfig(unittest.TestCase):
|
||||
g.add_device(dev1)
|
||||
|
||||
# Sound devices
|
||||
g.add_device(VirtualAudio("sb16", conn=g.conn))
|
||||
g.add_device(VirtualAudio("es1370", conn=g.conn))
|
||||
g.add_device(VirtualAudio(g.conn, "sb16"))
|
||||
g.add_device(VirtualAudio(g.conn, "es1370"))
|
||||
|
||||
# Disk devices
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
g.add_device(VirtualDisk(g.conn, path="/dev/loop0",
|
||||
device=VirtualDisk.DEVICE_FLOPPY))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/dev/loop0",
|
||||
bus="scsi"))
|
||||
g.add_device(VirtualDisk(conn=g.conn, path="/tmp", device="floppy"))
|
||||
d3 = VirtualDisk(conn=g.conn, path="/default-pool/testvol1.img",
|
||||
g.add_device(VirtualDisk(g.conn, path="/dev/loop0", bus="scsi"))
|
||||
g.add_device(VirtualDisk(g.conn, path="/tmp", device="floppy"))
|
||||
d3 = VirtualDisk(g.conn, path="/default-pool/testvol1.img",
|
||||
bus="scsi", driverName="qemu")
|
||||
d3.address.type = "spapr-vio"
|
||||
g.add_device(d3)
|
||||
@ -716,9 +715,10 @@ class TestXMLConfig(unittest.TestCase):
|
||||
# Network devices
|
||||
net1 = utils.get_virtual_network()
|
||||
net1.model = "e1000"
|
||||
net2 = VirtualNetworkInterface(type="user",
|
||||
net2 = VirtualNetworkInterface(g.conn, type="user",
|
||||
macaddr="22:11:11:11:11:11")
|
||||
net3 = VirtualNetworkInterface(type=virtinst.VirtualNetworkInterface.TYPE_VIRTUAL,
|
||||
net3 = VirtualNetworkInterface(g.conn,
|
||||
type=virtinst.VirtualNetworkInterface.TYPE_VIRTUAL,
|
||||
macaddr="22:22:22:22:22:22", network="default")
|
||||
net3.model = "spapr-vlan"
|
||||
net3.set_address("spapr-vio")
|
||||
@ -771,19 +771,19 @@ class TestXMLConfig(unittest.TestCase):
|
||||
g.add_device(mdev1)
|
||||
|
||||
# Check keymap autoconfig
|
||||
gdev1 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
|
||||
gdev1 = virtinst.VirtualGraphics(g.conn, type="vnc")
|
||||
self.assertTrue(gdev1.keymap is not None)
|
||||
gdev1.keymap = "en-us"
|
||||
|
||||
# Check keymap None
|
||||
gdev2 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
|
||||
gdev2 = virtinst.VirtualGraphics(g.conn, type="vnc")
|
||||
gdev2.keymap = None
|
||||
|
||||
gdev3 = virtinst.VirtualGraphics(conn=g.conn, type="sdl")
|
||||
gdev4 = virtinst.VirtualGraphics(conn=g.conn, type="spice")
|
||||
gdev3 = virtinst.VirtualGraphics(g.conn, type="sdl")
|
||||
gdev4 = virtinst.VirtualGraphics(g.conn, type="spice")
|
||||
gdev4.passwdValidTo = "foobar"
|
||||
|
||||
gdev5 = virtinst.VirtualGraphics(conn=g.conn, type="sdl")
|
||||
gdev5 = virtinst.VirtualGraphics(g.conn, type="sdl")
|
||||
gdev5.xauth = "fooxauth"
|
||||
gdev5.display = "foodisplay"
|
||||
g.add_device(gdev1)
|
||||
@ -870,7 +870,7 @@ class TestXMLConfig(unittest.TestCase):
|
||||
g.add_device(utils.get_filedisk("/default-pool/rhel6.img"))
|
||||
g.add_device(utils.get_blkdisk())
|
||||
g.add_device(utils.get_virtual_network())
|
||||
g.add_device(VirtualAudio())
|
||||
g.add_device(VirtualAudio(g.conn))
|
||||
g.add_device(VirtualVideoDevice(g.conn))
|
||||
g.os_autodetect = True
|
||||
|
||||
@ -899,7 +899,7 @@ class TestXMLConfig(unittest.TestCase):
|
||||
sizebytes = long(sizegigs * 1024L * 1024L * 1024L)
|
||||
|
||||
for sparse in [True, False]:
|
||||
disk = VirtualDisk(conn=utils.get_conn(), path=path, size=sizegigs,
|
||||
disk = VirtualDisk(utils.get_conn(), path=path, size=sizegigs,
|
||||
sparse=sparse)
|
||||
disk.setup()
|
||||
|
||||
@ -920,18 +920,18 @@ class TestXMLConfig(unittest.TestCase):
|
||||
return ["bridge", "br0"]
|
||||
util.default_bridge = newbridge
|
||||
|
||||
dev1 = virtinst.VirtualNetworkInterface(conn=g.conn)
|
||||
dev1 = virtinst.VirtualNetworkInterface(g.conn)
|
||||
dev1.macaddr = "22:22:33:44:55:66"
|
||||
g.add_device(dev1)
|
||||
|
||||
dev2 = virtinst.VirtualNetworkInterface(conn=g.conn,
|
||||
dev2 = virtinst.VirtualNetworkInterface(g.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
dev2.source = None
|
||||
dev2.source = "foobr0"
|
||||
dev2.macaddr = "22:22:33:44:55:67"
|
||||
g.add_device(dev2)
|
||||
|
||||
dev3 = virtinst.VirtualNetworkInterface(conn=g.conn,
|
||||
dev3 = virtinst.VirtualNetworkInterface(g.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
dev3.source = None
|
||||
dev3.macaddr = "22:22:33:44:55:68"
|
||||
@ -963,7 +963,7 @@ class TestXMLConfig(unittest.TestCase):
|
||||
conn, "16")
|
||||
|
||||
def testManyVirtio(self):
|
||||
d = VirtualDisk(conn=utils.get_conn(), bus="virtio",
|
||||
d = VirtualDisk(utils.get_conn(), bus="virtio",
|
||||
path="/default-pool/testvol1.img")
|
||||
|
||||
targetlist = []
|
||||
|
@ -292,7 +292,7 @@ class XMLParseTest(unittest.TestCase):
|
||||
def testSingleDisk(self):
|
||||
xml = ("""<disk type="file" device="disk"><source file="/a.img"/>"""
|
||||
"""<target dev="hda" bus="ide"/></disk>""")
|
||||
d = virtinst.VirtualDisk(parsexml=xml)
|
||||
d = virtinst.VirtualDisk(conn, parsexml=xml)
|
||||
self._set_and_check(d, "target", "hda", "hdb")
|
||||
self.assertEquals(xml.replace("hda", "hdb"), d.get_xml_config())
|
||||
|
||||
|
@ -151,10 +151,8 @@ def main(conn=None):
|
||||
|
||||
|
||||
# Build the Installer instance
|
||||
installer = virtinst.ImageInstaller(boot_index=options.boot,
|
||||
image=image,
|
||||
conn=conn)
|
||||
|
||||
installer = virtinst.ImageInstaller(conn, boot_index=options.boot,
|
||||
image=image)
|
||||
|
||||
# Get Guest instance from installer parameters.
|
||||
guest = installer.guest_from_installer()
|
||||
|
@ -1050,8 +1050,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
devtype = src.get_model()[src.get_active()][0]
|
||||
conn = self.conn.get_backend()
|
||||
|
||||
self._dev = VirtualTPMDevice.get_dev_instance(conn,
|
||||
devtype)
|
||||
self._dev = VirtualTPMDevice.get_dev_instance(conn, devtype)
|
||||
|
||||
show_something = False
|
||||
for param_name, widget_name in tpm_widget_mappings.items():
|
||||
@ -1075,9 +1074,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
devtype = src.get_model()[src.get_active()][0]
|
||||
conn = self.conn.get_backend()
|
||||
|
||||
self._dev = VirtualCharDevice.get_dev_instance(conn,
|
||||
chartype,
|
||||
devtype)
|
||||
self._dev = VirtualCharDevice.get_dev_instance(conn, chartype, devtype)
|
||||
|
||||
show_something = False
|
||||
for param_name, widget_name in char_widget_mappings.items():
|
||||
@ -1168,7 +1165,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
meter = asyncjob.get_meter()
|
||||
|
||||
logging.debug("Starting background file allocate process")
|
||||
disk.setup_dev(self.conn.get_backend(), meter=meter)
|
||||
disk.setup(meter=meter)
|
||||
logging.debug("Allocation completed")
|
||||
|
||||
progWin = vmmAsyncJob(do_file_allocate,
|
||||
@ -1185,7 +1182,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
self._dev.creating_storage()):
|
||||
return self._storage_progress()
|
||||
|
||||
return self._dev.setup_dev(self.conn.get_backend())
|
||||
return self._dev.setup()
|
||||
|
||||
def add_device(self):
|
||||
ret = self.setup_device()
|
||||
@ -1321,7 +1318,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
if do_use:
|
||||
diskpath = ideal
|
||||
|
||||
disk = virtinst.VirtualDisk(conn=conn,
|
||||
disk = virtinst.VirtualDisk(conn,
|
||||
path=diskpath,
|
||||
size=disksize,
|
||||
sparse=sparse,
|
||||
@ -1378,7 +1375,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
disk.vmm_controller = None
|
||||
if (controller_model == "virtio-scsi") and (bus == "scsi"):
|
||||
controllers = self.vm.get_controller_devices()
|
||||
controller = VirtualControllerSCSI(conn=conn)
|
||||
controller = VirtualControllerSCSI(conn)
|
||||
controller.set_model(controller_model)
|
||||
disk.vmm_controller = controller
|
||||
for d in controllers:
|
||||
@ -1430,8 +1427,8 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
"spice": virtinst.VirtualGraphics.TYPE_SPICE,
|
||||
"sdl": virtinst.VirtualGraphics.TYPE_SDL}[graphics]
|
||||
|
||||
self._dev = virtinst.VirtualGraphics(type=_type,
|
||||
conn=self.conn.get_backend())
|
||||
self._dev = virtinst.VirtualGraphics(self.conn.get_backend(),
|
||||
type=_type)
|
||||
try:
|
||||
self._dev.port = self.get_config_graphics_port()
|
||||
self._dev.tlsPort = self.get_config_graphics_tls_port()
|
||||
@ -1444,7 +1441,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
def validate_page_sound(self):
|
||||
smodel = self.get_config_sound_model()
|
||||
try:
|
||||
self._dev = virtinst.VirtualAudio(conn=self.conn.get_backend(),
|
||||
self._dev = virtinst.VirtualAudio(self.conn.get_backend(),
|
||||
model=smodel)
|
||||
except Exception, e:
|
||||
return self.err.val_err(_("Sound device parameter error"), e)
|
||||
@ -1532,7 +1529,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
model = self.get_config_video_model()
|
||||
|
||||
try:
|
||||
self._dev = VirtualVideoDevice(conn=conn)
|
||||
self._dev = VirtualVideoDevice(conn)
|
||||
self._dev.model_type = model
|
||||
except Exception, e:
|
||||
return self.err.val_err(_("Video device parameter error"), e)
|
||||
@ -1543,7 +1540,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
action = self.get_config_watchdog_action()
|
||||
|
||||
try:
|
||||
self._dev = VirtualWatchdog(conn=conn)
|
||||
self._dev = VirtualWatchdog(conn)
|
||||
self._dev.model = model
|
||||
self._dev.action = action
|
||||
except Exception, e:
|
||||
@ -1569,7 +1566,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
' that target already exists'))
|
||||
|
||||
try:
|
||||
self._dev = virtinst.VirtualFilesystem(conn=conn)
|
||||
self._dev = virtinst.VirtualFilesystem(conn)
|
||||
self._dev.source = source
|
||||
self._dev.target = target
|
||||
if mode:
|
||||
@ -1610,7 +1607,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
service = self.get_config_usbredir_service()
|
||||
|
||||
try:
|
||||
self._dev = VirtualRedirDevice(conn=conn, bus="usb", stype=stype)
|
||||
self._dev = VirtualRedirDevice(conn, bus="usb", stype=stype)
|
||||
if host:
|
||||
self._dev.host = host
|
||||
if service:
|
||||
|
@ -302,7 +302,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
net_type = net.type
|
||||
|
||||
# Generate a new MAC
|
||||
obj = VirtualNetworkInterface(conn=self.conn.get_backend(),
|
||||
obj = VirtualNetworkInterface(self.conn.get_backend(),
|
||||
type=VirtualNetworkInterface.TYPE_USER)
|
||||
obj.setup(self.conn.get_backend())
|
||||
newmac = obj.macaddr
|
||||
@ -676,7 +676,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
row = self.net_list[orig]
|
||||
|
||||
try:
|
||||
VirtualNetworkInterface(conn=self.conn.get_backend(),
|
||||
VirtualNetworkInterface(self.conn.get_backend(),
|
||||
type=VirtualNetworkInterface.TYPE_USER,
|
||||
macaddr=new)
|
||||
row[NETWORK_INFO_NEW_MAC] = new
|
||||
|
@ -1426,18 +1426,18 @@ class vmmCreate(vmmGObjectUI):
|
||||
"Using VNC graphics.")
|
||||
gtype = virtinst.VirtualGraphics.TYPE_VNC
|
||||
|
||||
return virtinst.VirtualGraphics(conn=guest.conn, type=gtype)
|
||||
return virtinst.VirtualGraphics(guest.conn, type=gtype)
|
||||
|
||||
def get_video_device(self, guest):
|
||||
if guest.installer.is_container():
|
||||
return
|
||||
return virtinst.VirtualVideoDevice(conn=guest.conn)
|
||||
return virtinst.VirtualVideoDevice(guest.conn)
|
||||
|
||||
def get_sound_device(self, guest):
|
||||
if (not self.config.get_new_vm_sound() or
|
||||
guest.installer.is_container()):
|
||||
return
|
||||
return virtinst.VirtualAudio(conn=guest.conn)
|
||||
return virtinst.VirtualAudio(guest.conn)
|
||||
|
||||
def build_guest(self, installer, name):
|
||||
guest = installer.guest_from_installer()
|
||||
@ -1584,7 +1584,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
self.guest.installer.init = init
|
||||
|
||||
if fs:
|
||||
fsdev = virtinst.VirtualFilesystem(conn=self.guest.conn)
|
||||
fsdev = virtinst.VirtualFilesystem(self.guest.conn)
|
||||
fsdev.target = "/"
|
||||
fsdev.source = fs
|
||||
self.guest.add_device(fsdev)
|
||||
@ -1704,7 +1704,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
if not diskpath:
|
||||
return self.err.val_err(_("A storage path must be specified."))
|
||||
|
||||
disk = virtinst.VirtualDisk(conn=conn,
|
||||
disk = virtinst.VirtualDisk(conn,
|
||||
path=diskpath,
|
||||
size=disksize,
|
||||
sparse=sparse)
|
||||
@ -1781,7 +1781,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
# Interesting methods
|
||||
def build_installer(self, instclass):
|
||||
installer = instclass(conn=self.conn.get_backend(),
|
||||
installer = instclass(self.conn.get_backend(),
|
||||
type=self.capsdomain.hypervisor_type,
|
||||
os_type=self.capsguest.os_type)
|
||||
installer.arch = self.capsguest.arch
|
||||
|
@ -923,7 +923,7 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
return self.err.val_err(_("An interface must be selected"))
|
||||
|
||||
try:
|
||||
iobj = iclass(name, self.conn.get_backend())
|
||||
iobj = iclass(self.conn.get_backend(), name)
|
||||
iobj.start_mode = start
|
||||
check_conflict = False
|
||||
|
||||
|
@ -501,7 +501,7 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
|
||||
try:
|
||||
self._pool_class = Storage.StoragePool.get_pool_class(typ)
|
||||
self._pool = self._pool_class(name=name, conn=conn)
|
||||
self._pool = self._pool_class(conn, name=name)
|
||||
except ValueError, e:
|
||||
return self.err.val_err(_("Pool Parameter Error"), e)
|
||||
|
||||
|
@ -745,7 +745,7 @@ def validate_network(parent, conn, nettype, devname, macaddr, model=None):
|
||||
elif nettype == VirtualNetworkInterface.TYPE_USER:
|
||||
pass
|
||||
|
||||
net = VirtualNetworkInterface(conn=conn.get_backend(),
|
||||
net = VirtualNetworkInterface(conn.get_backend(),
|
||||
type=nettype,
|
||||
bridge=bridge,
|
||||
network=netname,
|
||||
@ -776,8 +776,8 @@ def validate_network(parent, conn, nettype, devname, macaddr, model=None):
|
||||
def generate_macaddr(conn):
|
||||
newmac = ""
|
||||
try:
|
||||
net = VirtualNetworkInterface(conn=conn.get_backend())
|
||||
net.setup(conn.get_backend())
|
||||
net = VirtualNetworkInterface(conn.get_backend())
|
||||
net.setup()
|
||||
newmac = net.macaddr
|
||||
except:
|
||||
pass
|
||||
|
@ -132,8 +132,7 @@ class Cloner(object):
|
||||
if not path:
|
||||
device = VirtualDisk.DEVICE_CDROM
|
||||
|
||||
disk = VirtualDisk(path, size=.0000001,
|
||||
conn=self.conn,
|
||||
disk = VirtualDisk(self.conn, path, size=.0000001,
|
||||
device=device)
|
||||
disklist.append(disk)
|
||||
except Exception, e:
|
||||
@ -155,7 +154,7 @@ class Cloner(object):
|
||||
def set_clone_macs(self, mac):
|
||||
maclist = util.listify(mac)
|
||||
for m in maclist:
|
||||
VirtualNetworkInterface(m, conn=self.conn)
|
||||
VirtualNetworkInterface(self.conn, m)
|
||||
|
||||
self._clone_macs = maclist
|
||||
def get_clone_macs(self):
|
||||
@ -366,8 +365,7 @@ class Cloner(object):
|
||||
mac = self._clone_macs.pop()
|
||||
else:
|
||||
while 1:
|
||||
mac = util.randomMAC(self.conn.getType().lower(),
|
||||
conn=self.conn)
|
||||
mac = util.randomMAC(self.conn)
|
||||
ignore, msg = self._check_mac(mac)
|
||||
if msg is not None:
|
||||
continue
|
||||
@ -439,8 +437,8 @@ class Cloner(object):
|
||||
"same. Skipping.")
|
||||
continue
|
||||
|
||||
# VirtualDisk.setup_dev handles everything
|
||||
dst_dev.setup_dev(meter=meter)
|
||||
# VirtualDisk.setup handles everything
|
||||
dst_dev.setup(meter=meter)
|
||||
|
||||
except Exception, e:
|
||||
logging.debug("Duplicate failed: %s", str(e))
|
||||
@ -506,7 +504,7 @@ class Cloner(object):
|
||||
|
||||
# Check if new mac address is valid
|
||||
def _check_mac(self, mac):
|
||||
nic = VirtualNetworkInterface(macaddr=mac, conn=self.conn)
|
||||
nic = VirtualNetworkInterface(self.conn, macaddr=mac)
|
||||
return nic.is_conflict_net(self.conn)
|
||||
|
||||
# Parse disk paths that need to be cloned from the original guest's xml
|
||||
@ -536,7 +534,7 @@ class Cloner(object):
|
||||
# Tell VirtualDisk we are a cdrom to allow empty media
|
||||
device = VirtualDisk.DEVICE_CDROM
|
||||
|
||||
d = VirtualDisk(disk.path, conn=self.conn,
|
||||
d = VirtualDisk(self.conn, disk.path,
|
||||
device=device, driverType=disk.driver_type,
|
||||
validate=validate)
|
||||
d.target = disk.target
|
||||
|
@ -77,7 +77,7 @@ def _build_pool(conn, meter, path):
|
||||
name = util.generate_name("boot-scratch",
|
||||
conn.storagePoolLookupByName)
|
||||
logging.debug("Building storage pool: path=%s name=%s", path, name)
|
||||
poolbuild = Storage.DirectoryPool(conn=conn, name=name,
|
||||
poolbuild = Storage.DirectoryPool(conn, name=name,
|
||||
target_path=path)
|
||||
|
||||
# Explicitly don't build? since if we are creating this directory
|
||||
@ -108,12 +108,12 @@ def _upload_file(conn, meter, destpool, src):
|
||||
if name != basename:
|
||||
logging.debug("Generated non-colliding volume name %s", name)
|
||||
|
||||
disk = VirtualDisk(conn=conn,
|
||||
disk = VirtualDisk(conn,
|
||||
path=os.path.join(poolpath, name),
|
||||
sizebytes=size,
|
||||
sparse=True)
|
||||
|
||||
disk.setup_dev(meter=meter)
|
||||
disk.setup(meter=meter)
|
||||
vol = disk.vol_object
|
||||
if not vol:
|
||||
raise RuntimeError(_("Failed to lookup scratch media volume"))
|
||||
@ -155,14 +155,13 @@ def _upload_file(conn, meter, destpool, src):
|
||||
|
||||
|
||||
class DistroInstaller(Installer.Installer):
|
||||
def __init__(self, type="xen", location=None,
|
||||
extraargs=None, os_type=None,
|
||||
conn=None, caps=None):
|
||||
def __init__(self, conn, type="xen", location=None,
|
||||
extraargs=None, os_type=None, caps=None):
|
||||
# pylint: disable=W0622
|
||||
# Redefining built-in 'type', but it matches the XML so keep it
|
||||
|
||||
Installer.Installer.__init__(self, type, location, extraargs,
|
||||
os_type, conn=conn, caps=caps)
|
||||
Installer.Installer.__init__(self, conn, type, location, extraargs,
|
||||
os_type, caps=caps)
|
||||
|
||||
self._livecd = False
|
||||
|
||||
@ -195,7 +194,7 @@ class DistroInstaller(Installer.Installer):
|
||||
is_tuple = False
|
||||
validated = True
|
||||
self._location_is_path = True
|
||||
is_local = (not self.conn or not self.is_remote())
|
||||
is_local = not self.is_remote()
|
||||
|
||||
# Basic validation
|
||||
if type(val) is not str and (type(val) is not tuple and len(val) != 2):
|
||||
@ -204,9 +203,6 @@ class DistroInstaller(Installer.Installer):
|
||||
if type(val) is tuple and len(val) == 2:
|
||||
logging.debug("DistroInstaller location is a (poolname, volname)"
|
||||
" tuple")
|
||||
if not self.conn:
|
||||
raise ValueError(_("'conn' must be specified if 'location' is"
|
||||
" a storage tuple."))
|
||||
is_tuple = True
|
||||
|
||||
elif _is_url(val, is_local):
|
||||
@ -223,8 +219,8 @@ class DistroInstaller(Installer.Installer):
|
||||
# Didn't determine anything about the location
|
||||
validated = False
|
||||
|
||||
if self._location_is_path or (not validated and self.conn and
|
||||
util.is_storage_capable(self.conn)):
|
||||
if (self._location_is_path or
|
||||
(not validated and util.is_storage_capable(self.conn))):
|
||||
# If user passed a storage tuple, OR
|
||||
# We couldn't determine the location type and a storage capable
|
||||
# connection was passed:
|
||||
@ -234,11 +230,11 @@ class DistroInstaller(Installer.Installer):
|
||||
path = (not is_tuple and val) or None
|
||||
|
||||
try:
|
||||
d = VirtualDisk(path=path,
|
||||
d = VirtualDisk(self.conn,
|
||||
path=path,
|
||||
device=VirtualDisk.DEVICE_CDROM,
|
||||
transient=True,
|
||||
readOnly=True,
|
||||
conn=self.conn,
|
||||
volName=stuple)
|
||||
val = d.path
|
||||
except:
|
||||
@ -273,8 +269,8 @@ class DistroInstaller(Installer.Installer):
|
||||
else:
|
||||
cdrom = self.location
|
||||
|
||||
disk = VirtualDisk(path=cdrom,
|
||||
conn=guest.conn,
|
||||
disk = VirtualDisk(guest.conn,
|
||||
path=cdrom,
|
||||
device=VirtualDisk.DEVICE_CDROM,
|
||||
readOnly=True,
|
||||
transient=transient)
|
||||
@ -321,8 +317,6 @@ class DistroInstaller(Installer.Installer):
|
||||
logging.debug("gzip stderr=%s", gziperr)
|
||||
|
||||
def support_remote_url_install(self):
|
||||
if not self.conn:
|
||||
return False
|
||||
if hasattr(self.conn, "_virtinst__fake_conn"):
|
||||
return False
|
||||
return support.check_stream_support(self.conn,
|
||||
@ -375,7 +369,7 @@ class DistroInstaller(Installer.Installer):
|
||||
if self.is_xenpv() and can_cdrom:
|
||||
device = VirtualDisk.DEVICE_DISK
|
||||
|
||||
disk = VirtualDisk(conn=guest.conn,
|
||||
disk = VirtualDisk(guest.conn,
|
||||
device=device,
|
||||
path=self.location,
|
||||
readOnly=True,
|
||||
|
@ -221,8 +221,8 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
return
|
||||
|
||||
if not self.installer:
|
||||
i = virtinst.DistroInstaller(type=type,
|
||||
conn=conn,
|
||||
i = virtinst.DistroInstaller(conn,
|
||||
type=type,
|
||||
os_type=self._default_os_type,
|
||||
caps=self._get_caps())
|
||||
self.installer = i
|
||||
@ -679,7 +679,7 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
dev = objclass(self.conn, devnode.name,
|
||||
parsexmlnode=devnode, caps=caps)
|
||||
else:
|
||||
dev = objclass(conn=self.conn,
|
||||
dev = objclass(self.conn,
|
||||
parsexmlnode=devnode, caps=caps)
|
||||
self._add_device(dev)
|
||||
|
||||
@ -869,7 +869,7 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
Ensure that devices are setup
|
||||
"""
|
||||
for dev in self.get_all_devices():
|
||||
dev.setup_dev(self.conn, progresscb)
|
||||
dev.setup(progresscb)
|
||||
|
||||
##############
|
||||
# Public API #
|
||||
|
@ -26,32 +26,24 @@ from virtinst import CapabilitiesParser as Cap
|
||||
from virtinst.VirtualDisk import VirtualDisk
|
||||
|
||||
|
||||
class ImageInstallerException(Exception):
|
||||
def __init__(self, msg):
|
||||
Exception.__init__(self, msg)
|
||||
|
||||
|
||||
class ImageInstaller(Installer.Installer):
|
||||
"""
|
||||
Installer for virt-image-based guests
|
||||
"""
|
||||
_has_install_phase = False
|
||||
|
||||
def __init__(self, image, capabilities=None, boot_index=None, conn=None):
|
||||
Installer.Installer.__init__(self, conn=conn, caps=capabilities)
|
||||
def __init__(self, conn, image, boot_index=None):
|
||||
Installer.Installer.__init__(self, conn)
|
||||
|
||||
self._arch = None
|
||||
self._image = image
|
||||
|
||||
if not (self.conn or self._get_caps()):
|
||||
raise ValueError(_("'conn' or 'capabilities' must be specified."))
|
||||
|
||||
# Set boot _boot_caps/_boot_parameters
|
||||
if boot_index is None:
|
||||
self._boot_caps = match_boots(self._get_caps(),
|
||||
self.image.domain.boots)
|
||||
if self._boot_caps is None:
|
||||
raise ImageInstallerException(_("Could not find suitable boot "
|
||||
raise RuntimeError(_("Could not find suitable boot "
|
||||
"descriptor for this host"))
|
||||
else:
|
||||
if (boot_index < 0 or
|
||||
@ -63,9 +55,8 @@ class ImageInstaller(Installer.Installer):
|
||||
self._guest = self._get_caps().guestForOSType(self.boot_caps.type,
|
||||
self.boot_caps.arch)
|
||||
if self._guest is None:
|
||||
raise PlatformMatchException(_("Unsupported virtualization type: "
|
||||
"%s %s" % (self.boot_caps.type,
|
||||
self.boot_caps.arch)))
|
||||
raise RuntimeError(_("Unsupported virtualization type: %s %s" %
|
||||
(self.boot_caps.type, self.boot_caps.arch)))
|
||||
|
||||
self.os_type = self.boot_caps.type
|
||||
self._domain = self._guest.bestDomainType()
|
||||
@ -123,8 +114,7 @@ class ImageInstaller(Installer.Installer):
|
||||
# FIXME: We ignore the target for the mapping in m.target
|
||||
if (drive.disk.use == ImageParser.Disk.USE_SYSTEM and
|
||||
not os.path.exists(path)):
|
||||
raise ImageInstallerException(_("System disk %s does not exist")
|
||||
% path)
|
||||
raise RuntimeError(_("System disk %s does not exist") % path)
|
||||
|
||||
device = VirtualDisk.DEVICE_DISK
|
||||
if drive.disk.format == ImageParser.Disk.FORMAT_ISO:
|
||||
@ -144,11 +134,6 @@ class ImageInstaller(Installer.Installer):
|
||||
return self.image.abspath(p)
|
||||
|
||||
|
||||
class PlatformMatchException(Exception):
|
||||
def __init__(self, msg):
|
||||
Exception.__init__(self, msg)
|
||||
|
||||
|
||||
def match_boots(capabilities, boots):
|
||||
for b in boots:
|
||||
for g in capabilities.guests:
|
||||
|
@ -35,21 +35,6 @@ XEN_SCRATCH = "/var/lib/xen"
|
||||
LIBVIRT_SCRATCH = "/var/lib/libvirt/boot"
|
||||
|
||||
|
||||
def _pygrub_path(conn=None):
|
||||
# FIXME: This should be removed/deprecated when capabilities are
|
||||
# fixed to provide bootloader info
|
||||
if conn:
|
||||
cap = CapabilitiesParser.parse(conn.getCapabilities())
|
||||
if (cap.host.arch == "i86pc"):
|
||||
return "/usr/lib/xen/bin/pygrub"
|
||||
else:
|
||||
return "/usr/bin/pygrub"
|
||||
|
||||
if platform.system() == "SunOS":
|
||||
return "/usr/lib/xen/bin/pygrub"
|
||||
return "/usr/bin/pygrub"
|
||||
|
||||
|
||||
class Installer(XMLBuilderDomain.XMLBuilderDomain):
|
||||
"""
|
||||
Installer classes attempt to encapsulate all the parameters needed
|
||||
@ -78,8 +63,8 @@ class Installer(XMLBuilderDomain.XMLBuilderDomain):
|
||||
_dumpxml_xpath = "/domain/os"
|
||||
_has_install_phase = True
|
||||
|
||||
def __init__(self, type="xen", location=None,
|
||||
extraargs=None, os_type=None, conn=None,
|
||||
def __init__(self, conn, type="xen", location=None,
|
||||
extraargs=None, os_type=None,
|
||||
parsexml=None, parsexmlnode=None, caps=None):
|
||||
# pylint: disable=W0622
|
||||
# Redefining built-in 'type', but it matches the XML so keep it
|
||||
@ -127,10 +112,6 @@ class Installer(XMLBuilderDomain.XMLBuilderDomain):
|
||||
self._tmpfiles = []
|
||||
self._tmpvols = []
|
||||
|
||||
def get_conn(self):
|
||||
return self._conn
|
||||
conn = property(get_conn)
|
||||
|
||||
def _get_bootconfig(self):
|
||||
return self._bootconfig
|
||||
bootconfig = property(_get_bootconfig)
|
||||
@ -295,7 +276,6 @@ class Installer(XMLBuilderDomain.XMLBuilderDomain):
|
||||
return "/bin/sh"
|
||||
|
||||
def _get_osblob_helper(self, guest, isinstall, bootconfig):
|
||||
conn = guest.conn
|
||||
arch = self.arch
|
||||
machine = self.machine
|
||||
hvtype = self.type
|
||||
@ -315,7 +295,8 @@ class Installer(XMLBuilderDomain.XMLBuilderDomain):
|
||||
if (not isinstall and
|
||||
self.is_xenpv() and
|
||||
not self.bootconfig.kernel):
|
||||
return "<bootloader>%s</bootloader>" % _pygrub_path(conn)
|
||||
# This really should be provided by capabilites xml
|
||||
return "<bootloader>/usr/bin/pygrub</bootloader>"
|
||||
|
||||
osblob = "<os>"
|
||||
|
||||
|
@ -25,7 +25,6 @@ import libvirt
|
||||
import logging
|
||||
|
||||
from virtinst import util
|
||||
from virtinst import support
|
||||
|
||||
|
||||
class Interface(object):
|
||||
@ -76,7 +75,7 @@ class Interface(object):
|
||||
return util.generate_name(prefix, conn.interfaceLookupByName, sep="",
|
||||
force_num=True)
|
||||
|
||||
def __init__(self, object_type, name, conn=None):
|
||||
def __init__(self, conn, object_type, name):
|
||||
"""
|
||||
Initialize object parameters
|
||||
"""
|
||||
@ -85,7 +84,7 @@ class Interface(object):
|
||||
object_type)
|
||||
|
||||
self._object_type = object_type
|
||||
self._conn = None
|
||||
self._conn = conn
|
||||
self._name = None
|
||||
self._mtu = None
|
||||
self._macaddr = None
|
||||
@ -93,9 +92,6 @@ class Interface(object):
|
||||
self._protocols = []
|
||||
self._protocol_xml = None
|
||||
|
||||
if conn is not None:
|
||||
self.conn = conn
|
||||
|
||||
self.name = name
|
||||
|
||||
# Initialize all optional properties
|
||||
@ -109,14 +105,7 @@ class Interface(object):
|
||||
|
||||
def _get_conn(self):
|
||||
return self._conn
|
||||
def _set_conn(self, val):
|
||||
if not support.check_conn_support(val, support.SUPPORT_CONN_INTERFACE):
|
||||
raise ValueError(_("Passed connection is not libvirt interface "
|
||||
"capable"))
|
||||
self._conn = val
|
||||
conn = property(_get_conn, _set_conn, doc="""
|
||||
Libvirt connection to check object against/install on
|
||||
""")
|
||||
conn = property(_get_conn)
|
||||
|
||||
def _get_name(self):
|
||||
return self._name
|
||||
@ -170,9 +159,8 @@ class Interface(object):
|
||||
"example.")
|
||||
|
||||
def _check_name_collision(self, name):
|
||||
pool = None
|
||||
try:
|
||||
pool = self.conn.interfaceLookupByName(name)
|
||||
self.conn.interfaceLookupByName(name)
|
||||
except libvirt.libvirtError:
|
||||
return
|
||||
|
||||
@ -263,8 +251,8 @@ class _InterfaceCompound(Interface):
|
||||
Class representing an interface which can have child interfaces
|
||||
"""
|
||||
|
||||
def __init__(self, interface_type, name, conn=None):
|
||||
Interface.__init__(self, interface_type, name, conn)
|
||||
def __init__(self, conn, interface_type, name):
|
||||
Interface.__init__(self, conn, interface_type, name)
|
||||
self._interfaces = []
|
||||
|
||||
def _get_interfaces(self):
|
||||
@ -315,9 +303,9 @@ class InterfaceBridge(_InterfaceCompound):
|
||||
Class for building and installing libvirt interface bridge xml
|
||||
"""
|
||||
|
||||
def __init__(self, name, conn=None):
|
||||
_InterfaceCompound.__init__(self, Interface.INTERFACE_TYPE_BRIDGE,
|
||||
name, conn)
|
||||
def __init__(self, conn, name):
|
||||
_InterfaceCompound.__init__(self, conn,
|
||||
Interface.INTERFACE_TYPE_BRIDGE, name)
|
||||
|
||||
self._stp = None
|
||||
self._delay = None
|
||||
@ -371,9 +359,9 @@ class InterfaceBond(_InterfaceCompound):
|
||||
|
||||
INTERFACE_BOND_MONITOR_MODE_MII_CARRIER_TYPES = ["netif", "ioctl"]
|
||||
|
||||
def __init__(self, name, conn=None):
|
||||
_InterfaceCompound.__init__(self, Interface.INTERFACE_TYPE_BOND,
|
||||
name, conn)
|
||||
def __init__(self, conn, name):
|
||||
_InterfaceCompound.__init__(self, conn,
|
||||
Interface.INTERFACE_TYPE_BOND, name)
|
||||
|
||||
self._bond_mode = None
|
||||
self._monitor_mode = None
|
||||
@ -519,9 +507,9 @@ class InterfaceEthernet(Interface):
|
||||
Class for building and installing libvirt interface ethernet xml
|
||||
"""
|
||||
|
||||
def __init__(self, name, conn=None):
|
||||
Interface.__init__(self, Interface.INTERFACE_TYPE_ETHERNET,
|
||||
name, conn)
|
||||
def __init__(self, conn, name):
|
||||
Interface.__init__(self, conn,
|
||||
Interface.INTERFACE_TYPE_ETHERNET, name)
|
||||
|
||||
def _get_interface_xml(self):
|
||||
# No ethernet specific XML
|
||||
@ -533,9 +521,9 @@ class InterfaceVLAN(Interface):
|
||||
Class for building and installing libvirt interface vlan xml
|
||||
"""
|
||||
|
||||
def __init__(self, name, conn=None):
|
||||
Interface.__init__(self, Interface.INTERFACE_TYPE_VLAN,
|
||||
name, conn)
|
||||
def __init__(self, conn, name):
|
||||
Interface.__init__(self, conn,
|
||||
Interface.INTERFACE_TYPE_VLAN, name)
|
||||
|
||||
self._tag = None
|
||||
self._parent_interface = None
|
||||
|
@ -23,11 +23,6 @@ from virtinst import Installer
|
||||
from virtinst.VirtualDisk import VirtualDisk
|
||||
|
||||
|
||||
class LiveCDInstallerException(Exception):
|
||||
def __init__(self, msg):
|
||||
Exception.__init__(self, msg)
|
||||
|
||||
|
||||
class LiveCDInstaller(Installer.Installer):
|
||||
_has_install_phase = False
|
||||
|
||||
@ -42,8 +37,8 @@ class LiveCDInstaller(Installer.Installer):
|
||||
|
||||
disk = None
|
||||
if path or vol_tuple:
|
||||
disk = VirtualDisk(path=path,
|
||||
conn=self.conn,
|
||||
disk = VirtualDisk(self.conn,
|
||||
path=path,
|
||||
volName=vol_tuple,
|
||||
device=VirtualDisk.DEVICE_CDROM,
|
||||
readOnly=True)
|
||||
|
@ -121,17 +121,15 @@ class StorageObject(object):
|
||||
TYPE_POOL = "pool"
|
||||
TYPE_VOLUME = "volume"
|
||||
|
||||
def __init__(self, object_type, name, conn=None):
|
||||
def __init__(self, conn, object_type, name):
|
||||
"""
|
||||
Initialize storage object parameters
|
||||
"""
|
||||
if object_type not in [self.TYPE_POOL, self.TYPE_VOLUME]:
|
||||
raise ValueError(_("Unknown storage object type: %s") % type)
|
||||
self._object_type = object_type
|
||||
self._conn = None
|
||||
self._conn = conn
|
||||
self._name = None
|
||||
if conn is not None:
|
||||
self.conn = conn
|
||||
|
||||
self.name = name
|
||||
|
||||
@ -145,16 +143,9 @@ class StorageObject(object):
|
||||
return self._object_type
|
||||
object_type = property(get_object_type)
|
||||
|
||||
def get_conn(self):
|
||||
def _get_conn(self):
|
||||
return self._conn
|
||||
def set_conn(self, val):
|
||||
if not util.is_storage_capable(val):
|
||||
raise ValueError(_("Passed connection is not libvirt storage "
|
||||
"capable"))
|
||||
self._conn = val
|
||||
conn = property(get_conn, set_conn, doc="""
|
||||
Libvirt connection to check object against/install on
|
||||
""")
|
||||
conn = property(_get_conn)
|
||||
|
||||
def get_name(self):
|
||||
return self._name
|
||||
|
@ -28,10 +28,9 @@ class VirtualAudio(VirtualDevice):
|
||||
MODEL_DEFAULT = "default"
|
||||
MODELS = ["es1370", "sb16", "pcspk", "ac97", "ich6", MODEL_DEFAULT]
|
||||
|
||||
def __init__(self, model=None, conn=None,
|
||||
def __init__(self, conn, model=None,
|
||||
parsexml=None, parsexmlnode=None, caps=None):
|
||||
VirtualDevice.__init__(self, conn,
|
||||
parsexml, parsexmlnode, caps)
|
||||
VirtualDevice.__init__(self, conn, parsexml, parsexmlnode, caps)
|
||||
|
||||
self._model = None
|
||||
if self._is_parse():
|
||||
|
@ -71,7 +71,7 @@ class VirtualDevice(XMLBuilderDomain):
|
||||
# General device type (disk, interface, etc.)
|
||||
_virtual_device_type = None
|
||||
|
||||
def __init__(self, conn=None, parsexml=None, parsexmlnode=None, caps=None):
|
||||
def __init__(self, conn, parsexml=None, parsexmlnode=None, caps=None):
|
||||
"""
|
||||
Initialize device state
|
||||
|
||||
@ -105,17 +105,14 @@ class VirtualDevice(XMLBuilderDomain):
|
||||
# See XMLBuilderDomain for docs
|
||||
raise NotImplementedError()
|
||||
|
||||
def setup_dev(self, conn=None, meter=None):
|
||||
def setup(self, meter=None):
|
||||
"""
|
||||
Perform potentially hazardous device initialization, like
|
||||
storage creation or host device reset
|
||||
|
||||
@param conn: Optional connection to use if necessary. If not
|
||||
specified, device's 'conn' will be used
|
||||
@param meter: Optional progress meter to use
|
||||
"""
|
||||
# Will be overwritten by subclasses if necessary.
|
||||
ignore = conn
|
||||
ignore = meter
|
||||
return
|
||||
|
||||
|
@ -532,13 +532,13 @@ class VirtualDisk(VirtualDevice):
|
||||
except Exception, e:
|
||||
raise ValueError(_("Couldn't lookup volume object: %s" % str(e)))
|
||||
|
||||
def __init__(self, path=None, size=None, transient=False, type=None,
|
||||
def __init__(self, conn, path=None, size=None, transient=False, type=None,
|
||||
device=None, driverName=None, driverType=None,
|
||||
readOnly=False, sparse=True, conn=None, volObject=None,
|
||||
readOnly=False, sparse=True, volObject=None,
|
||||
volInstall=None, volName=None, bus=None, shareable=False,
|
||||
driverCache=None, format=None,
|
||||
validate=True, parsexml=None, parsexmlnode=None, caps=None,
|
||||
driverIO=None, sizebytes=None):
|
||||
driverIO=None, sizebytes=None, nomanaged=False):
|
||||
"""
|
||||
@param path: filesystem path to the disk image.
|
||||
@type path: C{str}
|
||||
@ -615,6 +615,7 @@ class VirtualDisk(VirtualDevice):
|
||||
self._iotune_wbs = None
|
||||
self._iotune_wis = None
|
||||
self._validate = validate
|
||||
self._nomanaged = nomanaged
|
||||
|
||||
# XXX: No property methods for these
|
||||
self.transient = transient
|
||||
@ -718,14 +719,8 @@ class VirtualDisk(VirtualDevice):
|
||||
self._check_str(val, "path")
|
||||
val = os.path.abspath(val)
|
||||
|
||||
# Pass the path to a VirtualDisk, which should provide validation
|
||||
# for us
|
||||
try:
|
||||
# If this disk isn't managed, don't pass 'conn' to this
|
||||
# validation disk, to ensure we have permissions for manual
|
||||
# cloning
|
||||
conn = self.__managed_storage() and self.conn or None
|
||||
VirtualDisk(conn=conn, path=val)
|
||||
VirtualDisk(self.conn, path=val, nomanaged=True)
|
||||
except Exception, e:
|
||||
raise ValueError(_("Error validating clone path: %s") % e)
|
||||
self.__validate_wrapper("_clone_path", val, validate, self.clone_path)
|
||||
@ -999,8 +994,7 @@ class VirtualDisk(VirtualDevice):
|
||||
"""
|
||||
pool = None
|
||||
|
||||
storage_capable = bool(self.conn and
|
||||
util.is_storage_capable(self.conn))
|
||||
storage_capable = util.is_storage_capable(self.conn)
|
||||
|
||||
# Try to lookup self.path storage objects
|
||||
if vol_object or vol_install:
|
||||
@ -1137,7 +1131,6 @@ class VirtualDisk(VirtualDevice):
|
||||
drvname = self._driverName
|
||||
drvtype = self._driverType
|
||||
|
||||
if self.conn:
|
||||
is_qemu = self.is_qemu()
|
||||
if is_qemu and not drvname:
|
||||
drvname = self.DRIVER_QEMU
|
||||
@ -1170,6 +1163,8 @@ class VirtualDisk(VirtualDevice):
|
||||
Return bool representing if managed storage parameters have
|
||||
been explicitly specified or filled in
|
||||
"""
|
||||
if self._nomanaged:
|
||||
return False
|
||||
return bool(self.vol_object is not None or
|
||||
self.vol_install is not None or
|
||||
self._pool_object is not None)
|
||||
@ -1220,8 +1215,7 @@ class VirtualDisk(VirtualDevice):
|
||||
|
||||
return True
|
||||
|
||||
storage_capable = bool(self.conn and
|
||||
util.is_storage_capable(self.conn))
|
||||
storage_capable = util.is_storage_capable(self.conn)
|
||||
|
||||
if self.is_remote():
|
||||
if not storage_capable:
|
||||
@ -1398,7 +1392,7 @@ class VirtualDisk(VirtualDevice):
|
||||
if dst_fd is not None:
|
||||
os.close(dst_fd)
|
||||
|
||||
def setup_dev(self, conn=None, meter=None):
|
||||
def setup(self, meter=None):
|
||||
"""
|
||||
Build storage (if required)
|
||||
|
||||
@ -1409,17 +1403,11 @@ class VirtualDisk(VirtualDevice):
|
||||
@param meter: Progress meter to report file creation on
|
||||
@type meter: instanceof urlgrabber.BaseMeter
|
||||
"""
|
||||
return self.setup(meter)
|
||||
|
||||
def setup(self, progresscb=None):
|
||||
"""
|
||||
DEPRECATED: Please use setup_dev instead
|
||||
"""
|
||||
if not progresscb:
|
||||
progresscb = progress.BaseMeter()
|
||||
if not meter:
|
||||
meter = progress.BaseMeter()
|
||||
|
||||
if self.creating_storage() or self.clone_path:
|
||||
self._do_create_storage(progresscb)
|
||||
self._do_create_storage(meter)
|
||||
|
||||
def _get_xml_config(self, disknode=None):
|
||||
"""
|
||||
|
@ -91,8 +91,8 @@ class VirtualGraphics(VirtualDevice):
|
||||
|
||||
return str(gtype).capitalize()
|
||||
|
||||
def __init__(self, type=TYPE_VNC, port=-1, listen=None, passwd=None,
|
||||
keymap=KEYMAP_DEFAULT, conn=None, parsexml=None,
|
||||
def __init__(self, conn, type=TYPE_VNC, port=-1, listen=None, passwd=None,
|
||||
keymap=KEYMAP_DEFAULT, parsexml=None,
|
||||
parsexmlnode=None, tlsPort=-1, channels=None,
|
||||
caps=None, passwdValidTo=None):
|
||||
# pylint: disable=W0622
|
||||
@ -131,7 +131,7 @@ class VirtualGraphics(VirtualDevice):
|
||||
self._default_keymap()
|
||||
|
||||
def _default_keymap(self, force_local=False):
|
||||
if (not force_local and self.conn and
|
||||
if (not force_local and
|
||||
support.check_conn_support(self.conn,
|
||||
support.SUPPORT_CONN_KEYMAP_AUTODETECT)):
|
||||
return None
|
||||
|
@ -177,15 +177,6 @@ class VirtualHostDevice(VirtualDevice):
|
||||
def _get_source_xml(self):
|
||||
raise NotImplementedError("Must be implemented in subclass")
|
||||
|
||||
def setup(self, conn=None):
|
||||
"""
|
||||
Unused
|
||||
|
||||
@param conn: libvirt virConnect instance to use (defaults to devices
|
||||
connection)
|
||||
"""
|
||||
ignore = conn
|
||||
|
||||
def _get_xml_config(self):
|
||||
xml = (" <hostdev mode='%s' type='%s' managed='%s'>\n" %
|
||||
(self.mode, self.type, self.managed and "yes" or "no"))
|
||||
|
@ -145,8 +145,8 @@ class VirtualNetworkInterface(VirtualDevice):
|
||||
return desc
|
||||
get_network_type_desc = staticmethod(get_network_type_desc)
|
||||
|
||||
def __init__(self, macaddr=None, type=TYPE_BRIDGE, bridge=None,
|
||||
network=None, model=None, conn=None,
|
||||
def __init__(self, conn, macaddr=None, type=TYPE_BRIDGE, bridge=None,
|
||||
network=None, model=None,
|
||||
parsexml=None, parsexmlnode=None, caps=None):
|
||||
# pylint: disable=W0622
|
||||
# Redefining built-in 'type', but it matches the XML so keep it
|
||||
@ -193,11 +193,10 @@ class VirtualNetworkInterface(VirtualDevice):
|
||||
return ret or None
|
||||
|
||||
def _generate_random_mac(self):
|
||||
if self.conn and not self._random_mac:
|
||||
if not self._random_mac:
|
||||
found = False
|
||||
for ignore in range(256):
|
||||
self._random_mac = util.randomMAC(self.conn.getType().lower(),
|
||||
conn=self.conn)
|
||||
self._random_mac = util.randomMAC(self.conn)
|
||||
ret = self.is_conflict_net(self.conn, self._random_mac)
|
||||
if ret[1] is not None:
|
||||
continue
|
||||
@ -346,21 +345,9 @@ class VirtualNetworkInterface(VirtualDevice):
|
||||
|
||||
return (False, None)
|
||||
|
||||
def setup_dev(self, conn=None, meter=None):
|
||||
return self.setup(conn)
|
||||
|
||||
def setup(self, conn=None):
|
||||
"""
|
||||
DEPRECATED: Please use setup_dev instead
|
||||
"""
|
||||
# Access self.macaddr to generate a random one
|
||||
if not self.conn and conn:
|
||||
self.conn = conn
|
||||
if not conn:
|
||||
conn = self.conn
|
||||
|
||||
def setup(self, meter=None):
|
||||
if self.macaddr:
|
||||
ret, msg = self.is_conflict_net(conn)
|
||||
ret, msg = self.is_conflict_net(self.conn)
|
||||
if msg is not None:
|
||||
if ret is False:
|
||||
logging.warning(msg)
|
||||
|
@ -34,14 +34,13 @@ class VirtualRedirDevice(VirtualDevice):
|
||||
TYPE_DEFAULT = "spicevmc"
|
||||
_types = ["tcp", "spicevmc", None]
|
||||
|
||||
def __init__(self, bus=BUS_DEFAULT, stype=TYPE_DEFAULT,
|
||||
conn=None, parsexml=None, parsexmlnode=None, caps=None):
|
||||
def __init__(self, conn, bus=BUS_DEFAULT, stype=TYPE_DEFAULT,
|
||||
parsexml=None, parsexmlnode=None, caps=None):
|
||||
"""
|
||||
@param conn: Connection the device/guest will be installed on
|
||||
@type conn: libvirt.virConnect
|
||||
"""
|
||||
VirtualDevice.__init__(self, conn, parsexml,
|
||||
parsexmlnode, caps)
|
||||
VirtualDevice.__init__(self, conn, parsexml, parsexmlnode, caps)
|
||||
|
||||
self._type = None
|
||||
self._bus = None
|
||||
|
@ -390,8 +390,7 @@ class XMLBuilderDomain(object):
|
||||
"""
|
||||
|
||||
_dumpxml_xpath = "."
|
||||
def __init__(self, conn=None, parsexml=None, parsexmlnode=None,
|
||||
caps=None):
|
||||
def __init__(self, conn, parsexml=None, parsexmlnode=None, caps=None):
|
||||
"""
|
||||
Initialize state
|
||||
|
||||
@ -402,16 +401,14 @@ class XMLBuilderDomain(object):
|
||||
@param parsexmlnode: Option xpathNode to use
|
||||
@param caps: Capabilities() instance
|
||||
"""
|
||||
self._conn = None
|
||||
self._conn_uri = None
|
||||
self.__remote = False
|
||||
self._conn = conn
|
||||
self._conn_uri = self._conn.getURI()
|
||||
self.__remote = uriutil.is_uri_remote(self._conn_uri, conn=self._conn)
|
||||
self.__caps = None
|
||||
|
||||
self._xml_node = None
|
||||
self._xml_ctx = None
|
||||
|
||||
if conn:
|
||||
self.set_conn(conn)
|
||||
|
||||
if caps:
|
||||
if not isinstance(caps, CapabilitiesParser.Capabilities):
|
||||
@ -449,19 +446,15 @@ class XMLBuilderDomain(object):
|
||||
self._cache()
|
||||
return copy.copy(self)
|
||||
|
||||
def get_conn(self):
|
||||
def _get_conn(self):
|
||||
return self._conn
|
||||
def set_conn(self, val):
|
||||
self._conn = val
|
||||
self._conn_uri = self._conn.getURI()
|
||||
self.__remote = uriutil.is_uri_remote(self._conn_uri, conn=self._conn)
|
||||
conn = property(get_conn, set_conn)
|
||||
conn = property(_get_conn)
|
||||
|
||||
def get_uri(self):
|
||||
return self._conn_uri
|
||||
|
||||
def _get_caps(self):
|
||||
if not self.__caps and self.conn:
|
||||
if not self.__caps:
|
||||
self.__caps = CapabilitiesParser.parse(self.conn.getCapabilities())
|
||||
return self.__caps
|
||||
|
||||
|
@ -276,11 +276,10 @@ def generate_name(base, collision_cb, suffix="", lib_collision=True,
|
||||
raise ValueError(_("Name generation range exceeded."))
|
||||
|
||||
|
||||
def default_bridge(conn=None):
|
||||
def default_bridge(conn):
|
||||
dev = default_route()
|
||||
|
||||
if (dev is not None and
|
||||
(not conn or not uriutil.is_uri_remote(conn.getURI(), conn=conn))):
|
||||
if (dev is not None and uriutil.is_uri_remote(conn.getURI(), conn)):
|
||||
# New style peth0 == phys dev, eth0 == bridge, eth0 == default route
|
||||
if os.path.exists("/sys/class/net/%s/bridge" % dev):
|
||||
return ["bridge", dev]
|
||||
@ -403,7 +402,7 @@ def is_blktap_capable():
|
||||
return False
|
||||
|
||||
|
||||
def randomMAC(typ, conn=None):
|
||||
def randomMAC(conn):
|
||||
"""Generate a random MAC address.
|
||||
|
||||
00-16-3E allocated to xensource
|
||||
@ -414,25 +413,16 @@ def randomMAC(typ, conn=None):
|
||||
The remaining 3 fields are random, with the first bit of the first
|
||||
random field set 0.
|
||||
|
||||
>>> randomMAC().startswith("00:16:3E")
|
||||
True
|
||||
>>> randomMAC("foobar").startswith("00:16:3E")
|
||||
True
|
||||
>>> randomMAC("xen").startswith("00:16:3E")
|
||||
True
|
||||
>>> randomMAC("qemu").startswith("52:54:00")
|
||||
True
|
||||
|
||||
@return: MAC address string
|
||||
"""
|
||||
if conn and hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||
if hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||
# Testing hack
|
||||
return "00:11:22:33:44:55"
|
||||
|
||||
ouis = {'xen': [0x00, 0x16, 0x3E], 'qemu': [0x52, 0x54, 0x00]}
|
||||
|
||||
try:
|
||||
oui = ouis[typ]
|
||||
oui = ouis[conn.getType().lower()]
|
||||
except KeyError:
|
||||
oui = ouis['xen']
|
||||
|
||||
@ -444,7 +434,7 @@ def randomMAC(typ, conn=None):
|
||||
|
||||
|
||||
def randomUUID(conn):
|
||||
if conn and hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||
if hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||
# Testing hack
|
||||
return "00000000-1111-2222-3333-444444444444"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user