-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
5 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
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,25 @@ | ||
from typing import IO, Iterator | ||
from xml.etree.ElementTree import Element | ||
|
||
try: | ||
from defusedxml import ElementTree | ||
except ImportError: | ||
from xml.etree import ElementTree | ||
|
||
|
||
class PVS: | ||
"""Parallels VM settings file. | ||
Args: | ||
fh: The file-like object to a PVS file. | ||
""" | ||
|
||
def __init__(self, fh: IO): | ||
self._xml: Element = ElementTree.fromstring(fh.read()) | ||
|
||
def disks(self) -> Iterator[str]: | ||
"""Yield the disk file names.""" | ||
for hdd_elem in self._xml.iterfind(".//Hdd"): | ||
system_name = hdd_elem.find("SystemName") | ||
if system_name is not None: | ||
yield system_name.text |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from io import StringIO | ||
|
||
from dissect.hypervisor.descriptor.pvs import PVS | ||
|
||
|
||
def test_pvs(): | ||
xml = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ParallelsVirtualMachine dyn_lists="VirtualAppliance 0" schemaVersion="1.0"> | ||
<Hardware dyn_lists="Fdd 0 CdRom 1 Hdd 9 Serial 0 Parallel 0 Printer 1 NetworkAdapter 4 Sound 1 USB 1 PciVideoAdapter 0 GenericDevice 0 GenericPciDevice 0 GenericScsiDevice 0 GenericNvmeDevice 0"> | ||
<Hdd dyn_lists="Partition 0" id="0"> | ||
<SystemName>Fedora-0.hdd</SystemName> | ||
</Hdd> | ||
</Hardware> | ||
</ParallelsVirtualMachine> | ||
""" # noqa: E501 | ||
|
||
with StringIO(xml.strip()) as fh: | ||
pvs = PVS(fh) | ||
assert next(pvs.disks()) == "Fedora-0.hdd" |