nutanix-cloud-native / packer-plugin-nutanix

Packer Builder for Nutanix AHV
https://developer.hashicorp.com/packer/integrations/nutanix-cloud-native/nutanix
Apache License 2.0
35 stars 19 forks source link

feat: adds GPU support to packer plugin nutanix #187

Closed faiq closed 6 months ago

faiq commented 6 months ago

What this PR does / why we need it:

Adds GPU support to the packer plugin.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Fixes #123

How Has This Been Tested?:

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and test output

I tested this by adding this to my packer.pkl.hcl file

source "nutanix" "kib_image" {
  boot_type              = var.boot_type
  cluster_name           = trim(var.nutanix_cluster_name, "\r\n")
  cpu                    = var.cpus
  force_deregister       = var.force_deregister
  gpu {
    name = "Ampere 40"
  }
  image_delete           = local.image_delete
  image_description      = "kube image-builder packer"
  image_export           = var.image_export
  image_name             = local.image_name
  memory_mb              = var.memory
  nutanix_endpoint       = trim(var.nutanix_endpoint, "\r\n")
  nutanix_insecure       = trim(var.nutanix_insecure, "\r\n")
  nutanix_password       = trim(var.nutanix_password, "\r\n")
  nutanix_port           = trim(var.nutanix_port, "\r\n")
  nutanix_username       = trim(var.nutanix_username, "\r\n")
  os_type                = var.guest_os_type
  shutdown_command       = "echo '${var.ssh_password}' | sudo -S -E sh -c 'usermod -L ${var.ssh_username} && ${var.shutdown_command}'"
  ssh_handshake_attempts = "100"
  ssh_agent_auth         = var.ssh_agent_auth
  ssh_private_key_file   = local.ssh_private_key_file
  ssh_password           = var.ssh_password
  ssh_timeout            = "20m"
  ssh_username           = var.ssh_username
  user_data              = base64encode(local.cloud_init)
  vm_disks {
    disk_size_gb        = var.disk_size_gb
    image_type          = "DISK_IMAGE"
    source_image_delete = var.source_image_delete
    source_image_force  = var.source_image_force
    source_image_uri    = var.source_image_url
    source_image_name   = var.source_image_name
  }
  vm_force_delete        = var.vm_force_delete
  vm_name                = local.image_name
  vm_nics  {
    subnet_name = trim(var.nutanix_subnet_name,  "\r\n")
  }
}

This created the VM and when I observed in the console the GPU was attached

12:10 PM  faiqus @ archlinux  ~/go/src/github.com/nutanix-cloud-native/example   
$ packer build -debug -var-file=./rocky.pkrvars.hcl packer.pkr.hcl 
Debug mode enabled. Builds will not be parallelized.
nutanix.kib_image: output will be in this color.

==> nutanix.kib_image: Creating Packer Builder virtual machine...
    nutanix.kib_image: Virtual machine rocky-9.3-kube--20240502181338 created
    nutanix.kib_image: Found IP for virtual machine: 10.41.16.5
==> nutanix.kib_image: Using SSH communicator to connect: 10.41.16.5
==> nutanix.kib_image: Waiting for SSH to become available...
==> nutanix.kib_image: Connected to SSH!
==> nutanix.kib_image: Gracefully halting virtual machine...
==> nutanix.kib_image: Creating image(s) from virtual machine rocky-9.3-kube--20240502181338...
    nutanix.kib_image: Found disk to copy: SCSI:0
    nutanix.kib_image: Image successfully created: rocky-9.3-kube--20240502181338 (df466e42-8940-43a7-822a-60e216be3df1)
==> nutanix.kib_image: Deleting virtual machine...
    nutanix.kib_image: Virtual machine successfully deleted
==> nutanix.kib_image: Running post-processor: packer-manifest (type manifest)
Build 'nutanix.kib_image' finished after 1 minute 23 seconds.

==> Wait completed after 1 minute 23 seconds

==> Builds finished. The artifacts of successful builds are:
--> nutanix.kib_image: rocky-9.3-kube--20240502181338
--> nutanix.kib_image: rocky-9.3-kube--20240502181338

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

Adds GPU support to plugin