Solved

PowerShell and ImageImportSpec

  • 10 November 2017
  • 7 replies
  • 8813 views

Badge +1
Hi,

We just got a nutanix cluster and i'm trying to write a script that will migrate a machine from Hyper-V to AHV using powershell.
I have used blog from: https://dsronnie.wordpress.com/2017/07/05/migrate-hyper-v-to-nutanix-ahv/ as input for creating the PowerShell script

I can't get it to work.... i'm stuck at importing the image. I'm trying to do a "ImageImportSpec" in powershell but i can't figure out. Here's my code:


#
$ImgCreateSpec = New-NTNXObject -Name ImageImportSpecDTO$ContainerID = (Get-NTNXContainer -SearchString "Container Name").id
$ImgCreateSpec.containerid = $ContainerID.Substring($ContainerID.IndexOf(":")+2)$ImgCreateSpec.url = "nfs://127.0.0.1/migration/Test_DISK01.VHDX"

New-NTNXImage -Name "Test" -ImageType DISK_IMAGE -ImageImportSpec $ImgCreateSpec

I recieve a task-UUID, but in the web console ImageCreate task is failed almost immediatly. Bucnh of errors in create_task.py and modify_task.py.

Any ideas?

I will share my powershell script once I got it working
Thanks
icon

Best answer by sandeepmp 12 November 2017, 08:15

Buch

As Chandru mentioned, this looks like a "Permission issue".
Check the image creation task status in Prism tasks.
If this is a permission issue you will receive error similar to the below.



or from powershell.


Check the file permission and set it to 777.



After changing the permission try again and image should get created without any issues.



Task status:



Let us know if you still face any issues.
View original

7 replies

Badge +2
@Chandru Hi! I tried this, but its not working. It is throwing me the following error:

code:
Error occurred while creating Disk Image
New-NTNXImage : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ New-NTNXImage -Name "xenahvwintst - disk 1" -Annotation "Copied VM xe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Nutanix.Prism.Common.NutanixCluster:NutanixCluster) [New-NTNXImage], WebException
+ FullyQualifiedErrorId : {"message":"Error occurred while creating Disk Image"},Nutanix.Prism.PS.Cmds.Acropolis.NewImage


I am trying to achieve here is to create a disk image from a disk that exists on a NTNX container using image source as URL (instead of uploading a file).
Userlevel 3
Badge +12
@darshan.patel Check out Buch's script, you need to create a imagespec object before you can use it with -ImageImportSpec switch in New-NTNXImage cmdlet. It would look like below,

code:
$ImgCreateSpec = New-NTNXObject -Name ImageImportSpecDTO
$ContainerID = (Get-NTNXContainer -SearchString "").id
$ImgCreateSpec.containerid = $ContainerID.Substring($ContainerID.IndexOf(":")+2)
$ImgCreateSpec.url = "nfs://172.21.92.26/Xen_to_AHV_Migration/f63571ed-3fbf-80ba-f851-31767ad753fc/357527a6-e441-46e9-a680-f05f1af831aa.vhd"

New-NTNXImage -Name "xenahvwintst - disk 1" -Annotation "Copied VM xenahvwintst - disk 1" -ImageType DISK_IMAGE -ImageImportSpec $ImageCreateSpec
Badge +2
@Chandru @sandeepmp @Buch I have a similar issue here... please help.

POST: https://next.nutanix.com/scripts-32/creating-an-image-from-url-using-powershell-31534

I am migrating VMs to AHV from XenServer.

The process involves
  • Copy XenServer VM Disks to Nutanix Datashare on XenServer
  • Create DISK_IMAGE from the disks copied on Nutanix DataShare
The manual process is to create an image in Nutanix using URL
nfs://Nutanix Host IP/SR Name/SR UUID/DISK UUID.vhd

I am looking to automate this step using Powershell and Nutanix Cmdlets 'New-NTNXImage'

Please help me on how can I create a image (source: URL) using powershell

So far I have this,

$URL = "nfs://172.21.92.26/Xen_to_AHV_Migration/f63571ed-3fbf-80ba-f851-31767ad753fc/357527a6-e441-46e9-a680-f05f1af831aa.vhd"

New-NTNXImage -Name "xenahvwintst - disk 1" -Annotation "Copied VM xenahvwintst - disk 1" -ImageType DISK_IMAGE -ImageImportSpec $URL

I am not sure on how to include the URL into the command to create NTNXImage
Badge +1
Sorry for the late reply,

Alter all it was just a case sensitve problem. I had the Nutanix container type without a capital 😃
Userlevel 4
Badge +19
BuchHow are you?Is the issue fixed?Hope we were able to answer your queries.If so, please mark the post as resolved
Userlevel 4
Badge +19
Buch

As Chandru mentioned, this looks like a "Permission issue".
Check the image creation task status in Prism tasks.
If this is a permission issue you will receive error similar to the below.



or from powershell.


Check the file permission and set it to 777.



After changing the permission try again and image should get created without any issues.



Task status:



Let us know if you still face any issues.
Userlevel 3
Badge +12
Buch The script you are using is correct. If the image creation fails immediately then it could be the permissions on the image is restrictive. Please use winscp to connect to one of the CVM ip with protocol as sftp and port as 2222, use prism admin usernameto login. Once logged in Navigate to the migration container and check the properties of the vhdx to see if others have read,write bits set?

Reply