Beispiel #1
0
def main():

    if hooking.tobool(os.environ.get('ifacemacspoof')):
        domxml = hooking.read_domxml()
        interface, = domxml.getElementsByTagName('interface')
        removeMacSpoofingFilter(interface)
        hooking.write_domxml(domxml)
Beispiel #2
0
def main():
    newnet = os.environ.get('extnet')
    if newnet is not None:
        doc = hooking.read_domxml()
        interface, = doc.getElementsByTagName('interface')
        replaceSource(interface, newnet)
        hooking.write_domxml(doc)
Beispiel #3
0
def main():
    if "macbind" in os.environ:
        macbindopts = ast.literal_eval(os.environ["macbind"])
        macbindopts = dict((k.lower(), v) for k, v in macbindopts.iteritems())
        domxml = hooking.read_domxml()
        replaceSourceBridge(domxml, macbindopts)
        hooking.write_domxml(domxml)
def vcpupin(arg_cpu_node):
    domxml = hooking.read_domxml()
    domain = domxml.getElementsByTagName('domain')[0]
    vcpu = domain.getElementsByTagName('vcpu')[0]
    vcpu.setAttribute('cpuset', get_node_cpu(arg_cpu_node))

    hooking.write_domxml(domxml)
Beispiel #5
0
def main():
    if "spiceoptions" in os.environ:
        try:
            spiceConfig = ast.literal_eval(os.environ["spiceoptions"])
            spiceConfig = dict((k.lower(), v) for k, v in spiceConfig.iteritems())

            domxml = hooking.read_domxml()
            for graphDev in domxml.getElementsByTagName("graphics"):
                if graphDev.getAttribute("type") == "spice":
                    for elmt, value in spiceConfig.items():
                        if elmt not in spiceOpts:
                            sys.stderr.write(" Invalid ELEMENT" " [%s] " % elmt)
                        else:
                            for attr, attrValue in value.items():
                                if attr not in spiceOpts[elmt]:
                                    sys.stderr.write(" Invalid ATTRIBUTE" " [%s]" % attr)
                                elif attrValue not in spiceOpts[elmt][attr]:
                                    sys.stderr.write(" Invalid VALUE" " [%s]" % attrValue)
                                else:
                                    returnElmt = createElement(domxml, elmt, attr, attrValue)
                                    if returnElmt:
                                        graphDev.appendChild(returnElmt)

            hooking.write_domxml(domxml)

        except:
            hooking.exit_hook("spiceoptions: [unexpected error]: %s\n" % traceback.format_exc())
            sys.exit(2)
Beispiel #6
0
def main():
    if 'macbind' in os.environ:
        macbindopts = ast.literal_eval(os.environ['macbind'])
        macbindopts = dict((k.lower(), v) for k, v in macbindopts.iteritems())
        domxml = hooking.read_domxml()
        replaceSourceBridge(domxml, macbindopts)
        hooking.write_domxml(domxml)
Beispiel #7
0
def main():
    if 'diskunmap' in os.environ:
        unmapConfig = os.environ['diskunmap']
        domxml = hooking.read_domxml()
        if unmapConfig == 'on':
            addDiscardUnmap(domxml)
            hooking.write_domxml(domxml)
Beispiel #8
0
def main():
    if 'spiceoptions' in os.environ:
        try:
            spiceConfig = ast.literal_eval(os.environ['spiceoptions'])
            spiceConfig = dict(
                (k.lower(), v) for k, v in spiceConfig.iteritems())

            domxml = hooking.read_domxml()
            for graphDev in domxml.getElementsByTagName('graphics'):
                if graphDev.getAttribute('type') == 'spice':
                    for elmt, value in spiceConfig.items():
                        if elmt not in spiceOpts:
                            sys.stderr.write(" Invalid ELEMENT"
                                             " [%s] " % elmt)
                        else:
                            for attr, attrValue in value.items():
                                if attr not in spiceOpts[elmt]:
                                    sys.stderr.write(" Invalid ATTRIBUTE"
                                                     " [%s]" % attr)
                                elif attrValue not in spiceOpts[elmt][attr]:
                                    sys.stderr.write(" Invalid VALUE"
                                                     " [%s]" % attrValue)
                                else:
                                    returnElmt = createElement(
                                        domxml, elmt, attr, attrValue)
                                    if returnElmt:
                                        graphDev.appendChild(returnElmt)

            hooking.write_domxml(domxml)

        except:
            hooking.exit_hook('spiceoptions: [unexpected error]: %s\n' %
                              traceback.format_exc())
            sys.exit(2)
def numatune(arg_cpu_node):
    domxml = hooking.read_domxml()
    domain = domxml.getElementsByTagName('domain')[0]
    numatunes = domain.getElementsByTagName('numatune')
    numatune = None
    if len(numatunes) == 0:
        numatune = domxml.createElement('numatune')
        domain.appendChild(numatune)
    else:
        numatune = numatunes[0]
    memories = numatune.getElementsByTagName('memory')
    memnodes = numatune.getElementsByTagName('memnode')
    memory = None
    if len(memories) == 0:
        memory = domxml.createElement('memory')
        numatune.appendChild(memory)
    else:
        memory = memories[0]
    memory.setAttribute('mode', 'strict')
    memory.setAttribute('nodeset', str(arg_cpu_node))

    memnode = None
    if len(memnodes) == 0:
        memnode = domxml.createElement('memnode')
        numatune.appendChild(memnode)
    else:
        memnode = memnodes[0]
    memnode.setAttribute('cellid', '0')
    memnode.setAttribute('mode', 'strict')
    memnode.setAttribute('nodeset', str(arg_cpu_node))

    hooking.write_domxml(domxml)
Beispiel #10
0
def main():
    if 'diskunmap' in os.environ:
        unmapConfig = os.environ['diskunmap']
        domxml = hooking.read_domxml()
        if unmapConfig == 'on':
            addDiscardUnmap(domxml)
            hooking.write_domxml(domxml)
Beispiel #11
0
def main():

    if hooking.tobool(os.environ.get('ifacemacspoof')):
        domxml = hooking.read_domxml()
        interface, = domxml.getElementsByTagName('interface')
        removeMacSpoofingFilter(interface)
        hooking.write_domxml(domxml)
Beispiel #12
0
def test_hook_should_inject_devices_to_vm(dom_xml, vhostmd_conf, sap_agent):
    vhostmd_before.main(vhostmd_conf)
    xml_doc = hooking.read_domxml()
    devices = xml_doc.getElementsByTagName("devices")[0]

    check_vbd_device(devices, vhostmd_before.DEFAULT_VBD_PATH)
    check_virtio_device(devices)
 def __init__(self):
     super(HostedEngineHook, self).__init__()
     self.config = {}
     self.domxml = hooking.read_domxml()
     self.enabled = os.path.exists(
         ohostedcons.FileLocations.ENGINE_VM_CONF
     )
Beispiel #14
0
def main():

    IPs = os.environ.get('noipspoof', '').split(',')
    if IPs:
        domxml = hooking.read_domxml()
        for interface in domxml.getElementsByTagName('interface'):
            replaceMacSpoofingFilter(interface, IPs)
        hooking.write_domxml(domxml)
Beispiel #15
0
def main():
    try:
        doc = hooking.read_domxml()
        sound = doc.getElementsByTagName('sound')[0]
        sound.setAttribute('model', 'ac97')
        hooking.write_domxml(doc)
    except Exception as e:
        pass
Beispiel #16
0
def main():

    IPs = os.environ.get('noipspoof', '').split(',')
    if IPs:
        domxml = hooking.read_domxml()
        for interface in domxml.getElementsByTagName('interface'):
            replaceMacSpoofingFilter(interface, IPs)
        hooking.write_domxml(domxml)
Beispiel #17
0
def main():
    portProfile = os.environ.get('vmfex')
    if portProfile is not None:
        handleDirectPool(libvirtconnection.get())
        doc = hooking.read_domxml()
        interface, = doc.getElementsByTagName('interface')
        attachProfileToInterfaceXml(interface, portProfile)
        hooking.write_domxml(doc)
def main():
    provider_type = os.environ.get(PROVIDER_TYPE_KEY, None)
    if provider_type != PROVIDER_TYPE:
        return

    domxml = hooking.read_domxml()
    ovs_device(domxml)
    hooking.write_domxml(domxml)
Beispiel #19
0
def main():
    portProfile = os.environ.get('vmfex')
    if portProfile is not None:
        handleDirectPool(libvirtconnection.get())
        doc = hooking.read_domxml()
        interface, = doc.getElementsByTagName('interface')
        attachProfileToInterfaceXml(interface, portProfile)
        hooking.write_domxml(doc)
def hook():
    import hooking
    if hooking.tobool(os.environ.get('kvmhidden')):
        try:
            domxml = hooking.read_domxml()
            domxml = kvmhidden(domxml)
            hooking.write_domxml(domxml)
        except:
            sys.stderr.write('kvmhidden: [unexpected error]: %s\n' % traceback.format_exc())
            sys.exit(2)
def hook():
    import hooking
    if os.environ.__contains__('clockoffset'):
        try:
            clockoffsetmanual = os.environ.get('clockoffset')
            domxml = hooking.read_domxml()
            domxml = clockoffset(domxml,clockoffsetmanual)
            hooking.write_domxml(domxml)
        except:
            sys.stderr.write('clockoffset: [unexpected error]: %s\n' % traceback.format_exc())
            sys.exit(2)
Beispiel #22
0
def hook():
    import hooking
    if hooking.tobool(os.environ.get('apicfeature')):
        try:
            domxml = hooking.read_domxml()
            domxml = apic_feature(domxml)
            hooking.write_domxml(domxml)
        except:
            sys.stderr.write('apic-feature: [unexpected error]: %s\n' %
                             traceback.format_exc())
            sys.exit(2)
Beispiel #23
0
def main():
    if "httpsisoboot" in os.environ:
        httpsisoboot = os.environ["httpsisoboot"]
        protocol, hostname, port_s, url_path = validate_URL(httpsisoboot)

        domxml = hooking.read_domxml()
        devices = domxml.getElementsByTagName("devices")[0]
        increase_devices_boot_order(devices)

        diskdev = create_https_iso_element(domxml, protocol, hostname, port_s, url_path)
        devices.appendChild(diskdev)
        hooking.write_domxml(domxml)
def hook():
    import hooking
    if hooking.tobool(os.environ.get('cpuhostmodelcheckpartial')):
        try:
            domxml = hooking.read_domxml()
            domxml = cpuhostmodelcheckpartial(domxml)
            hooking.write_domxml(domxml)
        except:
            sys.stderr.write(
                'cpuhostmodelcheckpartial: [unexpected error]: %s\n' %
                traceback.format_exc())
            sys.exit(2)
Beispiel #25
0
def main():
    #newnet = os.environ.get('extnet')
    try:
        newnet = "nat"
        if newnet is not None:
            doc = hooking.read_domxml()
            interfaces = doc.getElementsByTagName('interface')
            interface = interfaces[0]
            replaceSource(interface, newnet)
            hooking.write_domxml(doc)
    except Exception as e:
        pass
Beispiel #26
0
def main():
    if PROVIDER_TYPE_KEY not in os.environ:
        return

    providerType = os.environ[PROVIDER_TYPE_KEY]
    if providerType == OPENSTACK_NET_PROVIDER_TYPE:
        domxml = hooking.read_domxml()
        vNicId = os.environ[VNIC_ID_KEY]
        pluginType = os.environ[PLUGIN_TYPE_KEY]
        sys.stderr.write('Adding vNIC %s for provider type %s and plugin %s'
                         % (vNicId, providerType, pluginType))
        addOpenstackVnic(domxml, pluginType, vNicId)
        hooking.write_domxml(domxml)
def main():
    if PROVIDER_TYPE_KEY not in os.environ:
        return

    providerType = os.environ[PROVIDER_TYPE_KEY]
    pluginType = os.environ[PLUGIN_TYPE_KEY]
    if (providerType == OPENSTACK_NET_PROVIDER_TYPE and
            pluginType == PT_OVS and SECURITY_GROUPS_KEY in os.environ):
        domxml = hooking.read_domxml()
        portId = os.environ[VNIC_ID_KEY]
        iface = domxml.getElementsByTagName('interface')[0]
        mac = iface.getElementsByTagName('mac')[0].getAttribute('address')
        setUpSecurityGroupVnic(mac, portId)
Beispiel #28
0
def hook():
    import hooking
    if os.environ.__contains__('pcixmlfile'):
        try:
            pcixmlfilename = os.environ['pcixmlfile']
            domxml = hooking.read_domxml()
            etxml = convertdomtoet(domxml)
            etxml = pcixml(etxml,pcixmlfilename)
            domxml = convertettodom(etxml)
            hooking.write_domxml(domxml)
        except:
            sys.stderr.write('pcixml: [unexpected error]: %s\n' % traceback.format_exc())
            sys.exit(2)
Beispiel #29
0
def main():
    if PROVIDER_TYPE_KEY not in os.environ:
        return

    providerType = os.environ[PROVIDER_TYPE_KEY]
    pluginType = os.environ[PLUGIN_TYPE_KEY]
    if (providerType == OPENSTACK_NET_PROVIDER_TYPE and pluginType == PT_OVS
            and SECURITY_GROUPS_KEY in os.environ):
        domxml = hooking.read_domxml()
        portId = os.environ[VNIC_ID_KEY]
        iface = domxml.getElementsByTagName('interface')[0]
        mac = iface.getElementsByTagName('mac')[0].getAttribute('address')
        setUpSecurityGroupVnic(mac, portId)
Beispiel #30
0
def main():
    if 'httpsisoboot' in os.environ:
        httpsisoboot = os.environ['httpsisoboot']
        protocol, hostname, port_s, url_path = validate_URL(httpsisoboot)

        domxml = hooking.read_domxml()
        devices = domxml.getElementsByTagName('devices')[0]
        increase_devices_boot_order(devices)

        diskdev = create_https_iso_element(domxml, protocol, hostname, port_s,
                                           url_path)
        devices.appendChild(diskdev)
        hooking.write_domxml(domxml)
Beispiel #31
0
def main():
    #newnet = os.environ.get('extnet')
    doc = hooking.read_domxml()
    uuid = doc.getElementsByTagName('uuid')[0]
    UUID = uuid.childNodes[0].nodeValue
    if UUID == "f60cba97-e09f-4515-bdef-a7af3d93e6e5":
        pass
    else:
        return 0
    devices_dom = doc.getElementsByTagName("devices")[0]
    ext_dom = minidom.parseString(ext_string)
    ext_elements = ext_dom.getElementsByTagName("hostdev")[0]
    devices_dom.appendChild(ext_elements)
    hooking.write_domxml(doc)
Beispiel #32
0
def main(vhostmd_conf):
    if hooking.tobool(os.environ.get("sap_agent", False)):
        domxml = hooking.read_domxml()

        subprocess.call(["/usr/bin/sudo", "-n", "/sbin/service", "vhostmd",
                         "start"])

        if VhostmdTransport.VBD in vhostmd_conf.transports:
            add_vbd_device(domxml, vhostmd_conf.vbd_path)

        if VhostmdTransport.VIRTIO in vhostmd_conf.transports:
            add_virtio_device(domxml)

        hooking.write_domxml(domxml)
Beispiel #33
0
def tune_socket():
    domxml = hooking.read_domxml()
    domain = domxml.getElementsByTagName('domain')[0]
    cpu = domain.getElementsByTagName('cpu')[0]
    cpu.setAttribute('mode', 'host-passthrough')
    cpu.setAttribute('migratable', 'off')
    if cpu.hasAttribute('match'):
        cpu.removeAttribute('match')
    if cpu.hasAttribute('check'):
        cpu.removeAttribute('check')
    disable_hypervisor = domxml.createElement('feature')
    disable_hypervisor.setAttribute('policy', 'disable')
    disable_hypervisor.setAttribute('name', 'hypervisor')
    cpu.appendChild(disable_hypervisor)
    hooking.write_domxml(domxml)
Beispiel #34
0
def tune_socket():
    	domxml = hooking.read_domxml()
    	domain = domxml.getElementsByTagName('domain')[0]
	vcpu = domain.getElementsByTagName('vcpu')[0]

	cpu_num_assigned = int(vcpu.childNodes[0].data)
	has_cur_attr = vcpu.hasAttribute('current')
	if has_cur_attr:
		cpu_num_assigned = int(vcpu.getAttribute('current'))
		vcpu.childNodes[0].data = cpu_num_assigned

    	cpu = domain.getElementsByTagName('cpu')[0]
	top = cpu.getElementsByTagName('topology')[0]
	top.setAttribute('sockets','1')
    	top.setAttribute('cores',str(cpu_num_assigned))
    	top.setAttribute('threads','1')
	
    	hooking.write_domxml(domxml)
def vcpupin(arg_cpu_list):
    domxml = hooking.read_domxml()
    domain = domxml.getElementsByTagName('domain')[0]
    cputunes = domain.getElementsByTagName('cputune')
    cputune = None
    if len(cputunes) == 0:
        cputune = domxml.createElement('cputune')
        domain.appendChild(cputune)
    else:
        cputune = cputunes[0]
    exist_vcpupins = cputune.getElementsByTagName('vcpupin')
    for i in range(len(arg_cpu_list)):
        found = False
        for e_vcpupin in exist_vcpupins:
            vcpu = e_vcpupin.getAttribute('vcpu')
            if vcpu == str(i):
                e_vcpupin.setAttribute('cpuset', str(arg_cpu_list[i]))
                found = True
            else:
                continue
        if found:
            continue
        vcpupin = domxml.createElement('vcpupin')
        vcpupin.setAttribute('vcpu', str(i))
        vcpupin.setAttribute('cpuset', str(arg_cpu_list[i]))
        cputune.appendChild(vcpupin)

    emulatorpins = cputune.getElementsByTagName('emulatorpin')
    emulatorpin = None
    if len(emulatorpins) == 0:
        emulatorpin = domxml.createElement('emulatorpin')
        cputune.appendChild(emulatorpin)
    else:
        emulatorpin = emulatorpins[0]
    s = ''
    for i, item in enumerate(arg_cpu_list):
        if i != 0:
            s = s + ','
        s = s + str(item)
    emulatorpin.setAttribute('cpuset', s)

    hooking.write_domxml(domxml)
Beispiel #36
0
def main():
    if PROVIDER_TYPE_KEY not in os.environ:
        return

    providerType = os.environ[PROVIDER_TYPE_KEY]
    if providerType == OPENSTACK_NET_PROVIDER_TYPE:
        domxml = hooking.read_domxml()
        vNicId = os.environ[VNIC_ID_KEY]
        pluginType = os.environ[PLUGIN_TYPE_KEY]
        sys.stderr.write('Adding vNIC %s for provider type %s and plugin %s' %
                         (vNicId, providerType, pluginType))
        addOpenstackVnic(domxml, pluginType, vNicId)
        hooking.write_domxml(domxml)

        vm_id = os.environ[VM_ID_KEY]
        PAUSE_FLAG = libvirt.VIR_DOMAIN_START_PAUSED
        flags = hooking.load_vm_launch_flags_from_file(vm_id)

        if (flags & PAUSE_FLAG) != PAUSE_FLAG:
            flags |= PAUSE_FLAG
            hooking.dump_vm_launch_flags_to_file(vm_id, flags)
            mark_for_unpause(vm_id)
Beispiel #37
0
def main():
    if PROVIDER_TYPE_KEY not in os.environ:
        return

    providerType = os.environ[PROVIDER_TYPE_KEY]
    if providerType == OPENSTACK_NET_PROVIDER_TYPE:
        domxml = hooking.read_domxml()
        vNicId = os.environ[VNIC_ID_KEY]
        pluginType = os.environ[PLUGIN_TYPE_KEY]
        hasSecurityGroups = SECURITY_GROUPS_KEY in os.environ
        sys.stderr.write('Adding vNIC %s for provider type %s and plugin %s'
                         % (vNicId, providerType, pluginType))
        addOpenstackVnic(domxml, pluginType, vNicId, hasSecurityGroups)
        hooking.write_domxml(domxml)

        vm_id = os.environ[VM_ID_KEY]
        PAUSE_FLAG = libvirt.VIR_DOMAIN_START_PAUSED
        flags = hooking.load_vm_launch_flags_from_file(vm_id)

        if (flags & PAUSE_FLAG) != PAUSE_FLAG:
            flags |= PAUSE_FLAG
            hooking.dump_vm_launch_flags_to_file(vm_id, flags)
            mark_for_unpause(vm_id)
Beispiel #38
0
def test_vm_with_sap_agent_disabled_should_be_unaffected(dom_xml, vhostmd_conf,
                                                         sap_agent):
    dom_xml_before = hooking.read_domxml().toxml()
    vhostmd_before.main(vhostmd_conf)

    assert hooking.read_domxml().toxml() == dom_xml_before
#!/usr/bin/python

import hooking
import os
import sys
sys.path.append("/usr/libexec/vdsm/hooks/vifdriver")
import vif_driver_hooking

reply = vif_driver_hooking.before_device_destroy(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
#!/usr/bin/python

import hooking
import os
import sys
sys.path.append("/usr/libexec/vdsm/hooks/vifdriver")
import vif_driver_hooking

reply = vif_driver_hooking.before_migration_destination(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
Beispiel #41
0
def main():
    domxml = hooking.read_domxml()
    ovs_device(domxml)
    hooking.write_domxml(domxml)
#!/usr/bin/python

import hooking
import os
import sys
sys.path.append("/usr/libexec/vdsm/hooks/vifdriver")
import vif_driver_hooking

reply = vif_driver_hooking.after_vm_start(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
def main():
    device_xml = hooking.read_domxml()
    allocate_random_network(device_xml)
    hooking.write_domxml(device_xml)
Beispiel #44
0
import os
import sys
import hooking
import traceback
'''
pincpu usages
=============
pincpu="0" (use the first cpu)
pincpu="1-4" (use cpus 1-4)
pincpu="^3" (dont use cpu 3)
pincpu="1-4,^3,6" (or all together)
'''

if 'pincpu' in os.environ:
    try:
        domxml = hooking.read_domxml()

        vcpu = domxml.getElementsByTagName('vcpu')[0]

        if not vcpu.hasAttribute('cpuset'):
            sys.stderr.write('pincpu: pinning cpu to: %s\n' %
                             os.environ['pincpu'])
            vcpu.setAttribute('cpuset', os.environ['pincpu'])
            hooking.write_domxml(domxml)
        else:
            sys.stderr.write('pincpu: cpuset attribute is present in vcpu, '
                             'doing nothing\n')
    except:
        sys.stderr.write('pincpu: [unexpected error]: %s\n' %
                         traceback.format_exc())
        sys.exit(2)
#!/usr/bin/python

import hooking
import os
import sys
sys.path.append("/usr/libexec/vdsm/hooks/vifdriver")
import vif_driver_hooking

reply = vif_driver_hooking.before_nic_unplug(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
#!/usr/bin/python

import hooking
import os
import sys
sys.path.append("/usr/libexec/vdsm/hooks/vifdriver")
import vif_driver_hooking

reply = vif_driver_hooking.before_migration_source(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
Beispiel #47
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#

import os
import subprocess
import hooking


if hooking.tobool(os.environ.get('sap_agent', False)):
    domxml = hooking.read_domxml()

    subprocess.call(['/usr/bin/sudo', '-n', '/sbin/service', 'vhostmd',
                     'start'])
    devs = domxml.getElementsByTagName('devices')[0]
    diskelem = domxml.createElement('disk')
    diskelem.setAttribute('device', 'disk')

    source = domxml.createElement('source')
    diskelem.setAttribute('type', 'file')
    source.setAttribute('file', '/dev/shm/vhostmd0')
    diskelem.appendChild(source)

    target = domxml.createElement('target')
    target.setAttribute('dev', 'vdzz')  # FIXME do not use a static location
    target.setAttribute('bus', 'virtio')
def getVirtXML():
    return hooking.read_domxml()