Example #1
0
 def test_featuresElement(self):
     """Testing OvfLibvirt.featuresElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.featuresElement(True, True, True, True)),
                      '<features><pae/><nonpae/><acpi/><apic/></features>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.featuresElement(pae=True)),
                      '<features><pae/></features>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.featuresElement(nonpae=True)),
                      '<features><nonpae/></features>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.featuresElement(acpi=True)),
                      '<features><acpi/></features>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.featuresElement(apic=True)),
                      '<features><apic/></features>')
Example #2
0
def get_networks(ovf_file):
    """
    Retrieves network interface information for the virtual machine from the Ovf file.
    @return: list of dictionaries eg. {interfaceType = 'network', sourceName = 'vmbr0'}
    @rtype: list
    """
    virtual_hardware_node = ovf_file.document.getElementsByTagName("VirtualHardwareSection")[0]
    nets = OvfLibvirt.getOvfNetworks(virtual_hardware_node)
    return nets
Example #3
0
    def test_libvirtDocument(self):
        """Testing OvfLibvirt.libvirtDocument"""
        domain = self.testDocument.createElement('domain')
        domain.setAttribute('type', 'xen')

        elem = self.testDocument.createElement('name')
        elem.appendChild(self.testDocument.createTextNode('test'))
        domain.appendChild(elem)

        # no sections
        testDoc = OvfLibvirt.libvirtDocument(domain)
        testStr = self.docTag + '<domain type="xen"><name>test</name></domain>'
        self.assertEqual(Ovf.xmlString(testDoc), testStr)

        # new section
        clockSection = self.testDocument.createElement('clock')
        clockSection.setAttribute('sync','utc')

        testDoc = OvfLibvirt.libvirtDocument(domain, clockSection)
        testStr = self.docTag + '<domain type="xen"><name>test</name>' + \
                  '<clock sync="utc"/></domain>'
        self.assertEqual(Ovf.xmlString(testDoc), testStr)

        # replace section
        domain.appendChild(clockSection)
        newClockSection = self.testDocument.createElement('clock')
        newClockSection.setAttribute('sync','localtime')

        testDoc = OvfLibvirt.libvirtDocument(domain, newClockSection)
        testStr = self.docTag + '<domain type="xen"><name>test</name>' + \
                  '<clock sync="localtime"/></domain>'
        self.assertEqual(Ovf.xmlString(testDoc), testStr)

        # multiple sections (new and old)
        newNameSection = self.testDocument.createElement('name')
        nameNode = self.testDocument.createTextNode('test_completed')
        newNameSection.appendChild(nameNode)

        testDoc = OvfLibvirt.libvirtDocument(domain, newNameSection,
                                                   newClockSection)
        testStr = self.docTag + '<domain type="xen">' + \
                  '<name>test_completed</name>' + \
                  '<clock sync="localtime"/></domain>'
        self.assertEqual(Ovf.xmlString(testDoc), testStr)
Example #4
0
def get_networks(ovf_file):
    """
    Retrieves network interface information for the virtual machine from the Ovf file.
    @return: list of dictionaries eg. {interfaceType = 'network', sourceName = 'vmbr0'}
    @rtype: list
    """
    virtual_hardware_node = ovf_file.document.getElementsByTagName(
        "VirtualHardwareSection")[0]
    nets = OvfLibvirt.getOvfNetworks(virtual_hardware_node)
    return nets
Example #5
0
 def test_uuidElement(self):
     """Testing OvfLibvirt.uuidElement"""
     testStr = '4dea22b31d52d8f32516782e98ab3fa0'
     self.assertEqual(Ovf.xmlString(OvfLibvirt.uuidElement(testStr)),
                      '<uuid>' + testStr + '</uuid>')
Example #6
0
 def test_clockElement(self):
     """Testing OvfLibvirt.clockElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.clockElement('localtime')),
                      '<clock sync="localtime"/>')
Example #7
0
 def test_domainElement(self):
     """Testing OvfLibvirt.domainElement"""
     testElem = OvfLibvirt.domainElement('kqemu')
     self.assertEqual(Ovf.xmlString(testElem),
                      '<domain type="kqemu"/>')
Example #8
0
 def test_nameElement(self):
     """Testing OvfLibvirt.nameElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.nameElement('test')),
                      '<name>test</name>')
Example #9
0
 def test_graphicsElement(self):
     """Testing OvfLibvirt.graphicsElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.graphicsElement('vnc', '192.168.1.1', '6522')),
                      '<graphics listen="192.168.1.1" port="6522" type="vnc"/>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.graphicsElement('sdl')),
                      '<graphics type="sdl"/>')
Example #10
0
 def test_currentMemoryElement(self):
     """Testing OvfLibvirt.currentMemoryElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.currentMemoryElement('262144')),
                      '<currentMemory>262144</currentMemory>')
Example #11
0
 def test_emulatorElement(self):
     """Testing OvfLibvirt.emulatorElement"""
     testElem = OvfLibvirt.emulatorElement('/usr/bin/qemu')
     self.assertEqual(Ovf.xmlString(testElem),
                      '<emulator>/usr/bin/qemu</emulator>')
Example #12
0
 def test_inputElement(self):
     """Testing OvfLibvirt.inputElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.inputElement('mouse', 'usb')),
                      '<input bus="usb" type="mouse"/>')
     self.assertEqual(Ovf.xmlString(OvfLibvirt.inputElement('tablet')),
                      '<input type="tablet"/>')
Example #13
0
 def test_memoryElement(self):
     """Testing OvfLibvirt.memoryElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.memoryElement('262144')),
                      '<memory>262144</memory>')
Example #14
0
 def test_vcpuElement(self):
     """Testing OvfLibvirt.vcpuElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.vcpuElement('1')),
                      '<vcpu>1</vcpu>')
Example #15
0
 def test_onCrashElement(self):
     """Testing OvfLibvirt.onCrashElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.onCrashElement('restart')),
                      '<on_crash>restart</on_crash>')
Example #16
0
 def test_onRebootElement(self):
     """Testing OvfLibvirt.onRebootElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.onRebootElement('restart')),
                      '<on_reboot>restart</on_reboot>')
Example #17
0
 def test_onPowerOffElement(self):
     """Testing OvfLibvirt.onPowerOffElement"""
     self.assertEqual(Ovf.xmlString(OvfLibvirt.onPowerOffElement('destroy')),
                      '<on_poweroff>destroy</on_poweroff>')