Automation

 View Only
  • 1.  Custom Atrribute Access

    Posted Apr 17, 2008 07:59 PM

    In VIrtualCenter 2.5, you have the ability to create Annotations in the "description/annotations" part of the VM. Is there a way to access these in PowerShell? I ask, as I would like to have a custom attribute that would be called "ReleaseSnapshot" and if the value is Y or TRUE, then take a snap before code is released. Otherwise skip the VM.



  • 2.  RE: Custom Atrribute Access

    Posted Apr 17, 2008 09:38 PM

    The attributes can't be accessed directly (afaik) but by getting the virtualmachine object you can access and test the attributes.

    In the virtualmachine object there are 2 arrays:

    - AvailableField: contains all the available custom attributes. Here we have to get the "key" of the attribute we want

    - CustomValue: contains all the values for the custom attributes. We have to use the "key" to find the desired value

    The following script shows how this can be done from within the VI Toolkit

    $VCimpl = Get-VIServer -Server <VCserver>
    
    $tgtVM = "VMName"
    $tgtName = "ReleaseSnapshot"
    $tgtValue = "yes"
    
    $vm = Get-View (Get-VM -Name $tgtVM).ID
    foreach ($fld in $vm.AvailableField){
      if ($fld.Name -eq $tgtName) {
        $tgt = $fld.Key
      }
    }
    foreach ($val in $vm.CustomValue){
      if ($val.Key -eq $tgt){
        if ($val.Valye -eq $tgtValue){
    	  $retValue = $TRUE
    	}
      }
    }
    

    You could package this logic in a function that you can then use inside a pipe-construct.



  • 3.  RE: Custom Atrribute Access

    Posted Apr 17, 2008 10:49 PM

    You could edit the notes/description part of the vm, which is accesible to powershell. Is that what you wanted.

    -KjB



  • 4.  RE: Custom Atrribute Access

    Posted Apr 17, 2008 10:56 PM

    They should be available. Try:

    Get-Command *CustomField

    And individual objects (e.g. the result of Get-VM) should have a CustomFields property.

    If you have trouble with this, please let us know.



  • 5.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 12:12 AM

    Hi gpeck29

    This will allow you to set the description field.

    set-vm -description 'whatever the description is'



  • 6.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 06:39 AM

    I suspect there is some confusion between "Attributes" and "Notes" in the Annotations field of a guest.

    The "Notes" you can indeed access/set via the -Description parameter in a number of guest related cmdlets.

    For the "Attributes" I didn't find a straightforward way of accessing/settings these in any cmdlet in the Toolkit.



  • 7.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 07:08 AM

    Thanks for the clarification. (I'm still quite new to this)



  • 8.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 06:18 PM

    The *CustomField cmdlets are supposed to help you manage the "attributes." If they're not clear enough or not working as expected, please do let us know.



  • 9.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 06:33 PM

    You are right, the *CustomField cmdlets allow us to set and manipulate the "attributes".

    I must have missed those.

    No need to access the entity objects directly.

    The only confusion could be the fact that the VI Client calls them Attributes while the Toolkit uses the term CustomField



  • 10.  RE: Custom Atrribute Access

    Posted Apr 18, 2008 06:35 PM

    Right. We use one name in the UI and another name in the API. Need to consider whether we should change the name of the cmdlet.