dissect.target icon indicating copy to clipboard operation
dissect.target copied to clipboard

Retrieve the name(s) of a targets children

Open lhaagsma opened this issue 7 months ago • 1 comments

Currently the Dissect Loaders for various virtualization layers only return the path/config of a child without returning a display name. This is not very user-friendly. Proxmox for example internally uses virtual machine IDs, making it not very apparent which vm is which.

IE:

Children
- <Child #="0" type="proxmox" path="/etc/pve/qemu-server/101.conf">
- <Child #="1" type="proxmox" path="/etc/pve/qemu-server/102.conf">
- <Child #="2" type="proxmox" path="/etc/pve/qemu-server/103.conf">
- <Child #="3" type="proxmox" path="/etc/pve/qemu-server/100.conf">
- <Child #="4" type="proxmox" path="/etc/pve/qemu-server/104.conf">

A potential solution would be to parse parts of the configuration already yielded by various loaders.

For Proxmox this would be:

https://github.com/fox-it/dissect.target/blob/624774b52ce64a87dfc72a751934119c97fd87d6/dissect/target/plugins/child/proxmox.py#L22

    def list_children(self) -> Iterator[ChildTargetRecord]:
        for vm in self.target.vmlist():
            yield ChildTargetRecord(
                type=self.__type__,
                path=vm.path,
                _target=self.target,
            )

Extend the above ChildTargetRecord record yielded by the list_children function with a .name attribute parsed from the provided config file in vmlist(). By creating a function called get_child_name (for each of the loaders in https://github.com/fox-it/dissect.target/tree/624774b52ce64a87dfc72a751934119c97fd87d6/dissect/target/plugins/child).

The goal would be to to extend the earlier provided children list to look something like:

Children
- <Child #="0", name="Never", type="proxmox" path="/etc/pve/qemu-server/101.conf">
- <Child #="1", name="Gonna",  type="proxmox" path="/etc/pve/qemu-server/102.conf">
- <Child #="2", name="Give",  type="proxmox" path="/etc/pve/qemu-server/103.conf">
- <Child #="3", name="You",  type="proxmox" path="/etc/pve/qemu-server/100.conf">
- <Child #="4", name="Up",  type="proxmox" path="/etc/pve/qemu-server/104.conf">

Retrieving a child name, or hostname is possible by just opening/loading the child, but this would be slower and still the display name of a VM can be different from the child's hostname.

Would this be the correct approach?

lhaagsma avatar May 02 '25 07:05 lhaagsma

Additionally, open_child/--child could then also be modified to accept a name. In the Target.open_child method we should then first try to open it as a path (and check if it exists), and then iterate all children to find a matching name. I think that'll be safer than doing heuristics on if it should be interpreted as a path or name, and it's faster in the case you are actually passing a path (don't need to parse all children first).

Schamper avatar May 02 '25 10:05 Schamper