-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deploy tweak tweak to set cache and io
attributes for CDROMs Signed-off-by: Anton Todorov <[email protected]>
- Loading branch information
1 parent
0beadb0
commit 490b191
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |