-
-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RDY] Format domain XML from a file to allow for more flexibility #903
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ def __init__(self, xml, config): | |
|
||
x = xml.find("attrs/attr[@name='libvirtd']/attrs") | ||
assert x is not None | ||
self.domain_tpl = x.find("attr[@name='template']/string").get("value") | ||
self.vcpu = x.find("attr[@name='vcpu']/int").get("value") | ||
self.memory_size = x.find("attr[@name='memorySize']/int").get("value") | ||
self.extra_devices = x.find("attr[@name='extraDevicesXML']/string").get("value") | ||
|
@@ -185,38 +186,19 @@ def _make_os(defn): | |
" <cmdline>%s</cmdline>"% defn.cmdline if len(defn.kernel) > 0 else "", | ||
'</os>'] | ||
|
||
|
||
domain_fmt = "\n".join([ | ||
'<domain type="{5}">', | ||
' <name>{0}</name>', | ||
' <memory unit="MiB">{1}</memory>', | ||
' <vcpu>{4}</vcpu>', | ||
'\n'.join(_make_os(defn)), | ||
' <devices>', | ||
' <emulator>{2}</emulator>', | ||
' <disk type="file" device="disk">', | ||
' <driver name="qemu" type="qcow2"/>', | ||
' <source file="{3}"/>', | ||
' <target dev="hda"/>', | ||
' </disk>', | ||
'\n'.join([iface(n) for n in defn.networks]), | ||
' <graphics type="vnc" port="-1" autoport="yes"/>' if not defn.headless else "", | ||
' <input type="keyboard" bus="usb"/>', | ||
' <input type="mouse" bus="usb"/>', | ||
defn.extra_devices, | ||
' </devices>', | ||
defn.extra_domain, | ||
'</domain>', | ||
]) | ||
|
||
return domain_fmt.format( | ||
self._vm_id(), | ||
defn.memory_size, | ||
qemu, | ||
self._disk_path(defn), | ||
defn.vcpu, | ||
defn.domain_type | ||
result = defn.domain_tpl.format( | ||
name=self._vm_id(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I tried to replace the |
||
memory_size=defn.memory_size, | ||
os='\n'.join(_make_os(defn)), | ||
emulator=qemu, | ||
interfaces='\n'.join([iface(n) for n in defn.networks]), | ||
diskPath=self._disk_path(defn), | ||
vcpu=defn.vcpu, | ||
domain_type=defn.domain_type, | ||
extra_domain=defn.extra_domain, | ||
extra_devices=defn.extra_devices + ('<graphics type="vnc" port="-1" autoport="yes"/>' if not defn.headless else ""), | ||
) | ||
return result | ||
|
||
def _parse_ip(self): | ||
""" | ||
|
@@ -260,7 +242,9 @@ def start(self): | |
self.private_ipv4 = self._parse_ip() | ||
else: | ||
self.log("starting...") | ||
self.dom.create() | ||
if self.dom.create() is False: | ||
self.log("Failed to create domain "); | ||
return False | ||
self._wait_for_ip(0) | ||
|
||
def get_ssh_name(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm confused what's the point of having this as a nixops option ?
What if someone changes this to:
That'll basically make it inconsistent with what the python code expects