Automation

 View Only
  • 1.  VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 24, 2008 12:31 PM

    The script is working so far.

    The next challenge is that i have 2 cluster, each in a different site. Each site is active. each cluster has the same resourcepools and the resourcepools have the same names + the -<sitecode>. So each resourcepool is unique.

    The script clones a template and put's the vm in a resourcepool on a cluster. But if i don't want to put a vm in a resourcepool, i looked at the SDK concerning VirtualMachineRelocateSpec.

    In the VirtualMachineRelocateSpec there is a line that when you clone a template to vm, you must specify a resourcepool, but how to do that if i want to use the cluster default resourcepool?

    The code for getting the resourcepool is:

    #RESOURCE POOL FROM CLUSTER

    $pool = get-resourcepool $vmpool

    $poolview = get-view $pool.id

    $vmrSpec.pool = $poolview.moref

    But how to use the default resourcepool of a cluster?

    Thanks in advance.



  • 2.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 24, 2008 03:24 PM

    I was thinking.

    Every host and cluster has a resource pool, i think the pool is called resources.

    If i do this interactively:

    get-cluster ClusterName | get-resourcepool

    I see the resourcepools in the cluster, but also the default one.

    But how to use it in the script?

    I tried it using

    get-cluster ClusterName | get-resourcepool $vmpool

    $poolview = get-view $pool.id

    $vmrSpec.pool = $poolview.moref

    But then vmrSpec.pool is null and the script fails.

    Anyone an idea?



  • 3.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Broadcom Employee
    Posted Jul 24, 2008 04:40 PM

    According to VI API documentation the ClusterComputeResource object has resourcePool property that is reference to root resource pool.

    So In you case you can do

    $cl = Get-View (get-cluster ClusterName).Id

    $vmrSpec.pool = $cl.ResourcePool

    Is this is the resource pool you are looking for ?



  • 4.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 24, 2008 05:11 PM
      |   view attached

    Yes, that property points to the default pool called Resources.

    Just one caveat, the property is a MoRef so you will have to cast it to a ResourcePool object.

    Short example with the MoveIntoResourcePool method

    
    $respool = [http://VMware.Vim.ResourcePool|http://VMware.Vim.ResourcePool](Get-View (Get-Cluster <cluster-name>).ID).ResourcePool
    $vm = Get-View (Get-VM <guest-name>).ID
     
    $respool.MoveIntoResourcePool($vm.MoRef)
     
    

    Since the forum SW doesn't like square brackets I attached the code

    Attachment(s)

    ps1
    MoveIntoResourcePool.ps1   178 B 1 version


  • 5.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 24, 2008 06:15 PM

    ykalchev luc,

    Thanks for giving me some input.

    @luc

    I have a question about this line:

    (Get-Cluster &lt;cluster-name&gt;).ID).ResourcePool

    Doesn't this line get all the resourcepools in the cluster?

    I have a long weekend i won't be able to update the script until monday.



  • 6.  RE: VirtualMachineRelocateSpec + CloneVM_Task
    Best Answer

    Posted Jul 24, 2008 06:56 PM

    No, like ykalchev said, the property ResourcePool in the ClusterComputeResource object, which is an extension of the ComputeResource object, points to the "...root resource pool".

    The line is in fact

    (Get-View (Get-Cluster <cluster-name>).ID).ResourcePool
    

    - we get the cluster <cluster-name> which returns a ClusterImpl object

    - with Get-View we get to the ClusterComputeResource object

    - and in that object we get the property ResourcePool, which is a MoRef



  • 7.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 24, 2008 09:10 PM

    oke thanks for explaining that.



  • 8.  RE: VirtualMachineRelocateSpec + CloneVM_Task

    Posted Jul 28, 2008 07:05 AM

    The script now completely works oke:

    $cluster = Get-View (get-cluster ClusterName).Id

    $vmrSpec.pool = $cl.ResourcePool

    Put's the vm in the default resourcepool of the cluster.

    Next thing to do is, get the default resourcepool of a standalone esx server to make the script even more flexibel.