VMware Cloud Community
AstraMonti
Enthusiast
Enthusiast
Jump to solution

Script to create VMs fails when trying to add disk on datastore cluster

Hello,

Attached is script that I have been using to create virtual machines and it works fine when the VMs are being created to single datastores but doesn't like clustered datastores. I think the reason is that it creates the VM through the esx host (which doesn't know about the cluter) and not through vCenter (which does know about it.) Unfortunately I don't know how to rectify it.

Thanks,

Astra

Reply
0 Kudos
1 Solution

Accepted Solutions
markdjones82
Expert
Expert
Jump to solution

Looks like it needs a datastore object for that parameter. So, we need to do a get Datastore cluster I can try to test tomorrow, but try this:

If ($datastore1 -ne "none") {

                 $drscluster  = Get-DatastoreCluster $datastore1

                 $vmadddsk = New-HardDisk -VM $gstname -CapacityKB $datastore1size -DataStore $drscluster           

    }

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Is the datastorecluster perhaps configured to have the VMs in "fully automated" ?

And what is the error message you get ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AstraMonti
Enthusiast
Enthusiast
Jump to solution

The SDRS automation is set to Manual mode, no automation. The error message is that the datastore I am pointing to (the name of the datastore cluster) does not exist.

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

What are you connecting to when running your script are you connecting to Vcenter or host?

Coudl have something to do with  there is a default affinity rule to keep disks together in SDRS cluster?

Are you trying to have the disks go to a different datastore than the first hard disk?  Why do you need 2 datastore variables if going to a SDRS cluster?

http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/index.html

-------------- Example 5 --------------

$vm = Get-VM WebServerVM

$disk = $vm | Get-HardDisk

$antiAffinityRule = New-Object 'VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMDiskAntiAffinityRule' $disk

New-HardDisk -VM $vm -AdvancedOption $antiAffinityRule -CapacityGB 40 -Datastore DatastoreCluster1

First retrieves the existing disk which will be part of the VMDK anti affinity rule. Then, creates an object describing the rule and creates the new hard disk.

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
AstraMonti
Enthusiast
Enthusiast
Jump to solution

I am connecting to the vCenter through the vsphere cli (connect-vihost and the name) when I am running the script.

There are no affinity rules.

The primary disk is going to the OS datastore. The SDRS cluster is the 2nd datastore which is for the data volumes of the VMs.

I tried your example but it still says that the datastore (name of the SDRS cluster) does not exist.

Thanks for the help to figure this out.

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

Connect to your vcenter and not the host.  The script should still work

connect-viserver vcenter

and not

connect-vihost

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Reply
0 Kudos
AstraMonti
Enthusiast
Enthusiast
Jump to solution

Sorry that a was a mispell, connect-viserver is the one I am using.

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

Looks like it needs a datastore object for that parameter. So, we need to do a get Datastore cluster I can try to test tomorrow, but try this:

If ($datastore1 -ne "none") {

                 $drscluster  = Get-DatastoreCluster $datastore1

                 $vmadddsk = New-HardDisk -VM $gstname -CapacityKB $datastore1size -DataStore $drscluster           

    }

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Reply
0 Kudos
AstraMonti
Enthusiast
Enthusiast
Jump to solution

markdjones82 thanks for the help, when the Get-DatastoreCluster was not recognized I realized that's something not right, so I looked and I was on 4.1 cli :smileyplain: Anyhow, when I upgraded to 5.1 everything worked, so thanks all for your help.

Reply
0 Kudos
markdjones82
Expert
Expert
Jump to solution

Excellent, that was going to be my next suggestion.  So did the original script work once you upgraded the powercli or did you have to get the datastore cluster object first?

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Reply
0 Kudos
AstraMonti
Enthusiast
Enthusiast
Jump to solution

The original script worked fine when I upgraded the powercli, 4.1 was too young to know about sdrds hehe. Thanks again for the help.

Reply
0 Kudos