This patch prepares _create_xml method for support of virtual machines:
- Adds support for virtual mode, which will write only hostname and
libvirt domain to the output XML file
- Changes the method so it uses newly created _write_to_xml method
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Controller/Wizard.py | 67 ++++++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 30 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py
index 1a3ecc0..570f0d1 100644
--- a/lnst/Controller/Wizard.py
+++ b/lnst/Controller/Wizard.py
@@ -197,37 +197,44 @@ class Wizard:
param_el.setAttribute("name", "hostname")
param_el.setAttribute("value", hostname)
params_el.appendChild(param_el)
- interfaces_el = doc.createElement("interfaces")
- top_el.appendChild(interfaces_el)
-
- interfaces_added = 0
- for iface in machine_interfaces.itervalues():
- if mode == "interactive":
- answer = raw_input("Do you want to add interface '%s' (%s)
"
- "to the recipe? [Y/n]: " %
(iface["name"],
-
iface["hwaddr"]))
- if mode == "noninteractive" or answer.lower() == "y"\
- or answer == "":
- interfaces_added += 1
- eth_el = doc.createElement("eth")
- eth_el.setAttribute("id", iface["name"])
- eth_el.setAttribute("label", "default_network")
- interfaces_el.appendChild(eth_el)
- params_el = doc.createElement("params")
- eth_el.appendChild(params_el)
- param_el = doc.createElement("param")
- param_el.setAttribute("name", "hwaddr")
- param_el.setAttribute("value", iface["hwaddr"])
- params_el.appendChild(param_el)
- param_el = doc.createElement("param")
- param_el.setAttribute("name", "driver")
- param_el.setAttribute("value", iface["driver"])
- params_el.appendChild(param_el)
- if interfaces_added == 0:
- sys.stderr.write("You didn't add any interface, no file "
- "'%s' will be created\n" % filename)
- return
+ if mode == "virtual":
+ param_el = doc.createElement("param")
+ param_el.setAttribute("name", "libvirt_domain")
+ param_el.setAttribute("value", libvirt_domain)
+ params_el.appendChild(param_el)
+ else:
+ interfaces_el = doc.createElement("interfaces")
+ top_el.appendChild(interfaces_el)
+
+ interfaces_added = 0
+ for iface in machine_interfaces.itervalues():
+ if mode == "interactive":
+ msg = "Do you want to add interface '%s' (%s) to the
"\
+ "recipe? [Y/n]: " % (iface["name"],
iface["hwaddr"])
+ answer = raw_input(msg)
+ if mode == "noninteractive" or answer.lower() ==
"y"\
+ or answer == "":
+ interfaces_added += 1
+ eth_el = doc.createElement("eth")
+ eth_el.setAttribute("id", iface["name"])
+ eth_el.setAttribute("label", "default_network")
+ interfaces_el.appendChild(eth_el)
+ params_el = doc.createElement("params")
+ eth_el.appendChild(params_el)
+ param_el = doc.createElement("param")
+ param_el.setAttribute("name", "hwaddr")
+ param_el.setAttribute("value", iface["hwaddr"])
+ params_el.appendChild(param_el)
+ if interfaces_added == 0:
+ sys.stderr.write("You didn't add any interface, no file "
+ "'%s' will be created\n" % filename)
+ return
+ if self._write_to_file(pool_dir, filename, doc):
+ print("File '%s/%s' successfuly created." % (pool_dir,
filename))
+ else:
+ sys.stderr.write("File '%s/%s' could not be opened "
+ "or data written.\n" % (pool_dir, filename))
def _write_to_file(self, pool_dir, filename, doc):
""" Writes contents of XML to a file
--
2.4.3