Skip to main content

Hi Folks,

 

I have a few machines I would like to convert from IDE to SCSI.

 

I understand this can be done with acli. The procedure is to clone the ide disk and replace it for the VM.

 

nutanix@cvm$ acli vm.disk_create <vm_name> clone_from_vmdisk=<vmdisk_UUID> bus=scsi

 

However, I’d like to do this in PowerShell given I’ve already started developing down that track. I have PowerShell cmdlets to snapshot and shutdown the VM which are recommended steps before performing this task.

 

I didn’t see a cmdlet to perform the clone and replacement, so I turned to the REST API.

I am fairly new to Nutanix to I wanted to get some feedback on whether this is the right approach or at least that its not going to break anything other than my test VM.

$uri = "https://$ntxCluster/api/nutanix/v2.0/vms/$($vm.vmid)/disks/attach"


$body = '{"uuid":"abcdefg-08h3-4i44-95j0-kl44m82no758","vm_disks":8{"vm_disk_clone":{"disk_address":{"device_bus":"SCSI","device_index":123}}}]}'
$headers=@{}
$headers.Add("content-type", "application/json")
$response = Invoke-WebRequest -Uri $uri -Method POST -Headers $headers -ContentType 'application/json' -Body $body


Thanks,

 

Michael

You can always create a test VM and run your script against that VM first. That would be a safe approach.


Thanks Alona, yes that was my initial approach. I loaded in the values including an id of a test VM to the Open API input box and chose ‘Try it Out’

I got this back . . .

This might change the state of the cluster. Are you sure you want to do this operation?

After seeing that message on a Friday evening on our production cluster, and being a first time Nutanix user I decided it would more prudent to see if anyone else has experience of this.

I find coding examples a bit light on the ground. For example none of the PowerShell modules have any examples in the inline help.

I’ll probably just have to take the leap of faith on it.


I gave that go but I’m missing something

I’m not sure which of the disk attributes this pertains to

{
"message": "Disk spec must be specified"
}

Could it be that you are missing the UUID of the disk you want to clone from? As in the one you would usually supply through acli in “clone_from_vmdisk=”

 

I will try to do this with one of our VMs tomorrow and I will report back if it works.


Please disregard my previous reply, I see now that you are using v2.0 and directly targeting disk.

I will try to do this on v3 against Prism Central tomorrow, and then how this goes onto v2


This {{body}} worked for me, with the uuid being VM uuid.

It cloned the IDE disk (3c5551a4-4961-4b5f-b87c-7bc769a1c1b3) onto SCSI bus and it booted fine from it (you will need to make a new call to remove the old IDE disk though).

 

{
  "uuid": "491ac854-f21b-4e64-a30c-8a9b8a0135d3",
  "vm_disks": "
    {
      "vm_disk_clone": {
        "disk_address": {
          "device_bus": "SCSI",
          "device_index": 0,
          "vmdisk_uuid": "3c5551a4-4961-4b5f-b87c-7bc769a1c1b3"
        }
      }
    }
  ]
}

 

Edited: To note that this is was done with API v2 /vms/{uuid}/disks/attach


I really appreciate the trouble you went to nijezauzeto.

I’ve tried with the Open API interface and also with a REST call from PowerShell and hit the same issue - (422) Unprocessable Entity.

Here is a sample of my code  . . .

 

Connect-NutanixCluster -Server $ntxCluster -UserName $cred.UserName -Password $cred.Password 

 

$vm = Get-NTNXVM | Where {$_.vmname -eq "myvirtualmachine"} | 

 

$uri = "https://$($ntxCluster):9440/PrismGateway/services/rest/v2.0/vms/$($vm.uuid)/disks/attach"


$body = @"
{
  "uuid": "$($vm.uuid))",
  "vm_disks": "
    {
      "vm_disk_clone": {
        "disk_address": {
          "device_bus": "SCSI",
          "device_index": 0,
          "vmdisk_uuid": "$($vm.nutanixVirtualDiskUuids)"
        }
      }
    }
  ]
}
"@

$Method = "POST"
$encoded     = $authHeader  = eSystem.Convert]::ToBase64String($Encoded)
$headers = @{
    "Content-Type" = "application/json"
    "Authorization" = "Basic $authHeader"
    }

Invoke-WebRequest -Uri $uri -Method $Method -Headers $headers -ContentType 'application/json' -Body $body -OutVariable response -Verbose
VERBOSE: POST https://cluster.domain.local:9440/PrismGateway/services/rest/v2.0/vms/30c41101-9bd5-4027-b913-ccf2cee03fbe/disks/attach with -1-byte payload


Invoke-WebRequest : The remote server returned an error: (422) Unprocessable Entity.

 

Thanks 

 

Michael


Hi Michael,

Seems you have one too many closed brackets in $body part:

  "uuid": "$($vm.uuid))”

Let me know if that works?


Wow - what a great spot!

It worked.

Thank you so much nijezauzeto