How do we programmatically upload a DISK Image from local pc?

  • 10 August 2020
  • 2 replies

Hello - We created a custom DISK Image and need to automate the upload to Nutanix. Is there a way for us to programatically upload an image using powershell?


Best answer by TimGaray 11 August 2020, 17:14

View original

This topic has been closed for comments

2 replies

Userlevel 6
Badge +5

Hi sk193,

Not sure I understand the question. Are you looking for a way to push the Disk image from the PC to Prism Element (clusters)? If so then PC has Image Management feature that allows you to set up policies for image distribution. You can manipulate the settings using Web Console or the APIv3 (image_placement_policies and images)

As per PowerShell, maybe someone here will be able to share their experience.

Userlevel 2
Badge +3

I’ve not done it from local storage but here is some code where I create images from a VM.  Maybe the $ImageSpec.url can be manipulated to retrieve the file locally.  Maybe this can get you heading in the right direction.


# Windows Server 2012R2
WriteLog "" 1 "White"
WriteLog "" 1 "White"
WriteLog ("Starting " + $Sysprep2012 + "...") 1 "White"
$SourceVM = Get-NTNXVM | Where {$_.vmname -eq $Sysprep2016}
$VDiskPaths = $SourceVM.nutanixVirtualDisks
$VDisks = Get-NTNXVMDisk -vmid $SourceVM.vmid -includeDiskSizes | Where {$ -match "scsi"} | Sort id

# RF2 2012R2 OSDisk
WriteLog " Uploading RF2 2012-OSDisk..." 1 "White"
$ImageSpec = New-NTNXObject -Name ImageImportSpec
$ImageSpec.containerName = $DestContainerRF2
$ImageSpec.url = "nfs://" + ($VDiskPaths | Where {$_ -match $VDisks[0].vmDiskUuid})
$OSDiskTask = New-NTNXImage -Name ("2012-OSDisk-RF2") -ImageType "disk_image" -ImageImportSpec $ImageSpec

# RF2 2012R2 LogsDisk
WriteLog " Uploading RF2 2012-LogsDisk..." 1 "White"
$ImageSpec = New-NTNXObject -Name ImageImportSpec
$ImageSpec.containerName = $DestContainerRF2
$ImageSpec.url = "nfs://" + ($VDiskPaths | Where {$_ -match $VDisks[1].vmDiskUuid})
$LogsDiskTask = New-NTNXImage -Name ("2012-LogsDisk-RF2") -ImageType "disk_image" -ImageImportSpec $ImageSpec

# Wait for tasks to complete
WriteLog " Waiting for upload tasks to complete..." 0 "White"
$Task1 = Get-NTNXTask -Taskid $OSDiskTask.taskUuid -IncludeCompleted
$Task2 = Get-NTNXTask -Taskid $LogsDiskTask.taskUuid -IncludeCompleted
While (!$Task1.completeTime -or !$Task2.completeTime)
WriteLog "." 0 "White"
Start-Sleep -Seconds 10
$Task1 = Get-NTNXTask -Taskid $OSDiskTask.taskUuid -IncludeCompleted
$Task2 = Get-NTNXTask -Taskid $LogsDiskTask.taskUuid -IncludeCompleted
WriteLog "Complete!" 1 "Green"