Skip to content
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

Implement gathering of Interface and Mac from powered off domain #190

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

stratus-ss
Copy link
Contributor

@stratus-ss stratus-ss commented Jan 23, 2025

SUMMARY

There are use cases where you need to get the mac address of a domain in order to provide it to PXE, Sushy-tools or other related tools. There should be a way to get this information without powering on the machine

Fixes #189

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

This is an addition to the plugin virt.py which allows the ansible module to process the xml generated by get_xml in order to return the interfaces and their associate mac addresses

This makes use of etree.fromstring to get the xml. A dictionary is returned with the primary key being network_interfaces with a nested dict containing the interface name as the key for an additional dict containing the mac address and the pci bus:

interface_dict = {"network_interfaces": {"bridge0": {"mac": "00:00:00:00", "pci_bus": "00x02"} } } 
ADDITIONAL INFORMATION

A simple playbook

---
- name: get network interfaces
  gather_facts: false
  hosts: localhost
  tasks:
  - name: register vm info
    community.libvirt.virt:
      command: get_interfaces
      name: "sno"
    register: vminfo

  - name: debug result
    debug: 
      msg: "{{ vminfo }}"

And the output:

PLAY [get UUID] ******************************************************************************************************

TASK [register vm info] **********************************************************************************************
ok: [localhost]

TASK [debug result] **************************************************************************************************
ok: [localhost] => {
    "msg": {
        "bridge-f0": {
            "mac": "52:54:00:c1:45:c9",
            "pci_bus": "0x01"
        },
        "bridge0-f1": {
            "mac": "52:54:00:00:8d:3b",
            "pci_bus": "0x02"
        }
    }
}

@stratus-ss stratus-ss marked this pull request as draft January 24, 2025 00:40
@stratus-ss stratus-ss marked this pull request as ready for review January 24, 2025 01:25
Copy link
Contributor

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stratus-ss thanks for the contribution!

@csmart do i understand it correctly that we can't run integration tests in containers for this collection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: Return Interfaces and Macs for Domains that are powered off
2 participants