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

add libvirt nodeinfo datasource #1073

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

memetb
Copy link

@memetb memetb commented Feb 22, 2024

This feature allows querying the host machine's nodeinfo through the libvirt protocol.

This is useful for, among other things, obtaining the target machine's architecture to select a guest image.

// main.tf
provider "libvirt" {
  uri = "qemu+ssh://${var.target}/system?sshauth=privkey&no_verify"
}

data "libvirt_nodeinfo" "host" {}

locals {
  arch = data.libvirt_nodeinfo.host.arch
  images = {
    "debian-x86_64" = "/srv/images/debian-12-backports-generic-amd64.qcow2",
    "debian-aarch64"  = "/srv/images/debian-12-backports-generic-arm64.qcow2",
  }
  image_path = local.images["debian-${local.arch}"]
}

output image_path {
  value = local.image_path
}

Which will create the following output:

$~/terraform-provider-libvirt/testing$ TF_VAR_target=chromium terraform apply 
data.libvirt_nodeinfo.host: Reading...
data.libvirt_nodeinfo.host: Read complete after 1s [id=d4e1bf70-6374-45b7-a970-fb584a1b4062]

Changes to Outputs:
  + image_path = "/srv/images/debian-12-backports-generic-arm64.qcow2"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes


Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

image_path = "/srv/images/debian-12-backports-generic-arm64.qcow2"
$~/terraform-provider-libvirt/testing$ terraform show 
# data.libvirt_nodeinfo.host:
data "libvirt_nodeinfo" "host" {
    arch                      = "aarch64"
    cores                     = 2
    dies                      = 1
    features                  = [
        "fp",
        "asimd",
        "evtstrm",
        "aes",
        "pmull",
        "sha1",
        "sha2",
        "crc32",
        "cpuid",
    ]
    host                      = "qemu+ssh://chromium/system?sshauth=privkey&no_verify=true"
    id                        = "d4e1bf70-6374-45b7-a970-fb584a1b4062"
    live_migration_support    = true
    live_migration_transports = [
        "tcp",
        "rdma",
    ]
    model                     = "cortex-a72"
    sockets                   = 1
    threads                   = 1
    topology                  = []
    vendor                    = "ARM"
}


Outputs:

image_path = "/srv/images/debian-12-backports-generic-arm64.qcow2"

Memet Bilgin added 2 commits February 22, 2024 12:15
however tests aren't running right project wide and there will need to be a PR
to address this
allow querying VM Host capabilities so that we can make decisions on what
resources to deploy. This can be things like machine architecture, but possibly
also to deploy VMs in a CPU topology manner
@memetb
Copy link
Author

memetb commented Feb 23, 2024

My bad, this appears to have been merged in #1042 - after I started the feature, before I pushed this PR.

@memetb
Copy link
Author

memetb commented Feb 23, 2024

I've made this a draft until the issue #1074 is discussed

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.

None yet

1 participant