예제 #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)
예제 #2
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)
예제 #3
0
def main():

    if hooking.tobool(os.environ.get('ifacemacspoof')):
        domxml = hooking.read_domxml()
        interface, = domxml.getElementsByTagName('interface')
        removeMacSpoofingFilter(interface)
        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)
예제 #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)
예제 #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)
예제 #7
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)
예제 #8
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)
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)
예제 #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)
예제 #11
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)
예제 #12
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)
예제 #14
0
파일: noipspoof.py 프로젝트: EdDev/vdsm
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)
예제 #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
예제 #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)
예제 #17
0
파일: vmfex_vnic.py 프로젝트: zofuthan/vdsm
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)
예제 #18
0
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)
예제 #19
0
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)
예제 #20
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)
예제 #21
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)
예제 #22
0
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)
예제 #23
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
예제 #24
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)
예제 #25
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)
예제 #26
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)
예제 #27
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)
예제 #28
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)
예제 #29
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)
예제 #30
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)
예제 #31
0
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)
예제 #32
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)
예제 #33
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)
예제 #34
0
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')
    diskelem.appendChild(target)

    diskelem.appendChild(domxml.createElement('readonly'))

    devs.appendChild(diskelem)

    hooking.write_domxml(domxml)
예제 #35
0
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)
 def save(self):
     hooking.write_domxml(self.domxml)
예제 #37
0
def main():
    domxml = hooking.read_domxml()
    ovs_device(domxml)
    hooking.write_domxml(domxml)
예제 #38
0
def main():
    device_xml = hooking.read_domxml()
    allocate_random_network(device_xml)
    hooking.write_domxml(device_xml)
예제 #39
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.after_vm_start(os.environ, hooking.read_domxml())
if reply:
    hooking.write_domxml(reply)
hooking.exit_hook("", return_code=0)
 def save(self):
     hooking.write_domxml(self.domxml)
def writeVirtXML(xml):
    hooking.write_domxml(xml)
예제 #42
0
def main():
    device_xml = hooking.read_domxml()
    allocate_random_network(device_xml)
    hooking.write_domxml(device_xml)