Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 231887

Re: Import and Export of vApp

$
0
0

One feature I find particularly useful is the "Lossless" export for vApp templates. This preserves the personality of all of the VMs (UUIDs, MAC addresses, etc.). It is less portable than a "regular" export, but saves time if you're going between vCD instances.

 

I took Clint Kitson's Export-CiOVF and modified it a little to leverage this new feature:

 

 

 

Function Export-CIOvfLossless {

<#

  .DESCRIPTION

  Export VAppTemplate while maintaining identity

  .EXAMPLE

  PS C:\> Get-CIVAppTemplate myVappTempalte | Export-CIOvfLossless

#>

  PARAM(

  $targetDir,

  [Parameter(Mandatory=$True, Position=1, ValueFromPipeline=$true)]

  [PSObject[]]$InputObject

  )

  PROCESS {

  $InputObject | %{

  if(!($_ | Get-CIView | %{ $_.Link } | where {$_.Rel -eq "download:identity"})) {

  try {

  Write-Host "Enabling download..."

  $_ | Get-CIView | %{ $_.EnableDownload() }

  } catch {

  Write-Error $error[0]

  }

  }

 

 

  $href = $_ | Get-CIView | %{ $_.Link } | where {$_.Rel -eq "download:identity"} | %{ $_.Href }

  if(!$targetDir) { $targetDir = $_.name }

 

 

  if($href) {

  $serverName = ($href.Split("/"))[2]

  $cloudServer = $global:DefaultCIServers | where {$_.Name -eq $serverName }

  $sessionId = $cloudServer.sessionid

  $webClient = New-Object system.net.webclient

  $webClient.Headers.Add('x-vcloud-authorization',$sessionId)

  if(!(Test-Path $targetDir)) { New-Item -type Directory $targetDir | out-null }

  $targetDir = (Get-Item $targetDir).FullName

  $baseHref = $href -replace "descriptor-with-id.ovf",""

  $webClient.DownloadFile("$href","$($targetDir)\descriptor-with-id.ovf")

  [xml]$xmlDescriptor = Get-Content "$($targetDir)\descriptor-with-id.ovf"

  $xmlDescriptor.Envelope.References.File | %{ $_.href } | %{

  try {

  Write-Host "Downloading $($targetDir)\$($_)"

  $webClient.DownloadFile("$($baseHref+$_)","$($targetDir)\$($_)")

  } catch {

  Write-Host -fore red "Error downloading OVF disk named $($_)"

  }

  }

  } else {

  Write-Host -fore red "OVF Download Link Not Found"

  }

  Write-Host "Disabling download"

  $_ | Get-CIView | %{ $_.DisableDownload() }

  }

  }

} #Export-CIOvfLossless


Viewing all articles
Browse latest Browse all 231887

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>