Skip to content

Commit

Permalink
add deploy tweak tweak to set cache and io
Browse files Browse the repository at this point in the history
attributes for CDROMs

Signed-off-by: Anton Todorov <[email protected]>
  • Loading branch information
atodorov-storpool committed Oct 2, 2019
1 parent 0beadb0 commit 490b191
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
57 changes: 57 additions & 0 deletions misc/qemu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
#
# -------------------------------------------------------------------------- #
# Copyright 2015-2019, StorPool (storpool.com) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
#
from __future__ import print_function

import sys
import os
from xml.etree.ElementTree import ElementTree
from xml.etree import ElementTree as ET

ns = {'qemu': 'http://libvirt.org/schemas/domain/qemu/1.0',
'one': "http://opennebula.org/xmlns/libvirt/1.0"
}

if len(sys.argv) <= 2 or sys.argv[2] != "migrate":
sys.exit(0)

for prefix, uri in ns.items():
ET.register_namespace(prefix, uri)

tree = ET.parse(sys.stdin)
root = tree.getroot()

for disk in root.findall('.//disk'):
try:
source = disk.find('./source')
if 'file' in source.attrib:
diskPath = os.path.realpath(source.attrib['file'])
elif 'dev' in source.attrib:
diskPath = os.path.realpath(source.attrib['dev'])
else:
diskPath = None
if diskPath and diskPath[0:8] == '/dev/sp-':
driver = disk.find('./driver')
driver.attrib['cache'] = 'none'
driver.attrib['io'] = 'native'
except Exception as e:
print("Error: {e}".format(e=e), file=stderr)

tree.write(sys.stdout)

sys.stdout.flush()
61 changes: 61 additions & 0 deletions vmm/kvm/deploy-tweaks.d.example/context-cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

# -------------------------------------------------------------------------- #
# Copyright 2015-2019, StorPool (storpool.com) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #

from __future__ import print_function
from sys import argv, stderr
from xml.etree import ElementTree as ET

ns = {'qemu': 'http://libvirt.org/schemas/domain/qemu/1.0',
'one': "http://opennebula.org/xmlns/libvirt/1.0"
}

def indent(elem, level=0):
i = "\n" + level*"\t"
if elem is not None:
# if not elem.text or not elem.text.strip():
# elem.text = i + "\t"
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i

xmlDomain = argv[1]
doc = ET.parse(xmlDomain)
root = doc.getroot()

for prefix, uri in ns.items():
ET.register_namespace(prefix, uri)

changed = 0
for disk in root.findall('./devices/disk[@type="file"][@device="cdrom"]'):
try:
driver = disk.find('./driver')
driver.attrib['cache'] = 'none'
driver.attrib['io'] = 'native'
changed = 1
except Exception as e:
print("Error: {e}".format(e=e), file=stderr)

if changed:
indent(root)
doc.write(xmlDomain)

0 comments on commit 490b191

Please sign in to comment.