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?
Page 1 / 1
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.
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 {$_.id -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://127.0.0.1" + ($VDiskPaths | Where {$_ -match $VDisksD0].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://127.0.0.1" + ($VDiskPaths | Where {$_ -match $VDisksD1].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"
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.