VMware Cloud Community
GregRoberts2011
Enthusiast
Enthusiast

The VCD - vCenter Glue - Linking VMs and Events


Hi All

I have sucessfully talked to the vCenter running our Blades and hosting vCLoud, and vCloud itself

I can see VMs from both sides.

1. What i am looking for is the glue that allows you to link the vCD VM to the underlying one.

Why ? So i can get the OS name for the vm, the CI VM interface does not return this.

[Found Linking your vCloud Director VMs and vSphere VMs | VMware PowerCLI Blog - VMware Blogs however the "$vsphereVMView = Get-View –RelatedObject $VM.ExtensionData" returns a $null object]

There are also references to examples like ' Get-CIVM -Name ‘MyVM’ | Get-CIView | Get-View ' this works to the Get-CIView level but not the Get-View level, it is like functionality was broken or changed from v5.1 to v5.5. I am using v5.5

2. I assume with this link then events can be grabbed for a vm ?

(the reason being i found no Get-CIEvent and when passing the vCD VM info to this Get-Event -vm vcdtoken this does not work)

3. Also is there a camlett for vCD events ? (i did not see one)

4. I am guessing multple opens are needed to reference objects ? e.g.

   Connect-CIServer & COnnect-VIServer (even though the CIServer should have some internal object to the underlying vCenter ?)

[YES}

Many thanks

NB: For 1. I did which is fairly ugly but worked, i.e. relying on the naming convention, however there has to be a better way, it is documented as working for v5

Function ConvertCIVM-ToVM {
    <#
        .SYNOPSIS
            Converts a vCloud VM into a vCenter VM Object

        .DESCRIPTION
            Converts a vCloud VM into a vCenter VM Object
   This is the single object form

        .PARAMETER  CIVM
            One or more vCloud VMs

        .EXAMPLE
            PS C:\> Get-CIVM -Name 'xxxx' | ConvertCIVM-ToVM
    #>
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true)]
        [Object]$CIVM
    )
    process {

        If ((-not $DefaultCIServers) -or (-not $DefaultVIServer)){
            Write-Host -ForegroundColor Red "You will need to be connected to both the CIServer and VIServer for this cmdlet to work"
            Return
        }

  # Build name - do the easy way
  $items = $CIVM.Id.Split(':')
 
  $vm = $CIVM.Name + ' (' + $items[3] + ')';
 
  return Get-VM -Server $global:DefaultVIServer -Name $vm

    }
}

0 Kudos
2 Replies
DanMSleek
Contributor
Contributor

I've been looking at doing a similar job because I want to get to the Tags that a virtual machines datastores have (we have a Replicated Tag so it'd help to identify replication VMs). I noted that the CIVM object type has a 'ToVirtualMachine' method but not had any success using it as yet. This might be a step in the right direction if that function could work (or even if it's supposed to) (Documentation is at VmRelatedObject)

PowerCLI C:\Windows\system32> $vivm = $VMs[0].ToVirtualMachine()

PowerCLI C:\Windows\system32> $vivm

An error occurred while enumerating through a collection: Unexpected exception has occured.

At line:1 char:1

+ $vivm

+ ~~~~~

    + CategoryInfo          : InvalidOperation: (VMware.VimAutom...ualMachine>d__0:<ToVirtualMachine>d__0) [], Runtime

   Exception

    + FullyQualifiedErrorId : BadEnumeration

0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

Hi,

Use the ToVirtualMachine method. See attached example I did.

Cheers.

0 Kudos