Merge remote-tracking branch 'vmware/master'
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
Function Get-XVCMStatus {
|
Function Get-XVCMStatus {
|
||||||
<#
|
<#
|
||||||
.NOTES
|
.NOTES
|
||||||
===========================================================================
|
===========================================================================
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Get-XVCMStatus
|
Get-XVCMStatus
|
||||||
#>
|
#>
|
||||||
$Uri = "http://localhost:8080/api/ping"
|
$Uri = "http://localhost:8080/api/status" #Updated for 2.0, Old: "http://localhost:8080/api/ping"
|
||||||
|
|
||||||
$results = Invoke-WebRequest -Uri $Uri -Method GET -TimeoutSec 5
|
$results = Invoke-WebRequest -Uri $Uri -Method GET -TimeoutSec 5
|
||||||
|
|
||||||
@@ -142,7 +142,9 @@ Function New-XVCMRequest {
|
|||||||
===========================================================================
|
===========================================================================
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This function initiates a migration request
|
This function initiates a migration request
|
||||||
.PARAMETER SrcSite
|
.PARAMETER opType
|
||||||
|
The type of task, Relocate or Clone
|
||||||
|
.PARAMETER SrcSite
|
||||||
The name of the source vCenter Server
|
The name of the source vCenter Server
|
||||||
.PARAMETER DstSite
|
.PARAMETER DstSite
|
||||||
The name of the destination vCenter Server
|
The name of the destination vCenter Server
|
||||||
@@ -151,31 +153,35 @@ Function New-XVCMRequest {
|
|||||||
.PARAMETER DstDatacenter
|
.PARAMETER DstDatacenter
|
||||||
The name of the destination vSphere Datacenter
|
The name of the destination vSphere Datacenter
|
||||||
.PARAMETER SrcCluster
|
.PARAMETER SrcCluster
|
||||||
The name of the source vSphere Cluster
|
<Not needed for v2.0,removed from code>
|
||||||
.PARAMETER DstCluster
|
.PARAMETER DstCluster
|
||||||
The name of the destination vSphere Cluster
|
The name of the destination vSphere Cluster, set to null if DstHost is defined
|
||||||
.PARAMETER DstDatastore
|
.PARAMETER DstDatastore
|
||||||
The name of the destination Datastore
|
The name of the destination Datastore
|
||||||
.PARAMETER srcVMs
|
.PARAMETER DstHost
|
||||||
|
The name of the destination host. Set to null if DstCluster is defined
|
||||||
|
.PARAMETER srcVMs
|
||||||
List of VMs to migrate
|
List of VMs to migrate
|
||||||
.PARAMETER NetworkMapping
|
.PARAMETER NetworkMapping
|
||||||
Hash table of the VM network mappings between your source and destination vCenter Server
|
Hash table of the VM network mappings between your source and destination vCenter Server
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
New-XVCMRequest -SrcSite SiteA -DstSite SiteB `
|
New-XVCMRequest -opType Relocate -SrcSite SiteA -DstSite SiteB `
|
||||||
-SrcDatacenter Datacenter-SiteA -DstDatacenter Datacenter-SiteB `
|
-SrcDatacenter Datacenter-SiteA -DstDatacenter Datacenter-SiteB `
|
||||||
-SrcCluster Palo-Alto -DstCluster Santa-Barbara `
|
-DstCluster $null -DstHost VMhost1.test.lab `
|
||||||
-DstDatastore vsanDatastore `
|
-DstDatastore vsanDatastore `
|
||||||
-srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") `
|
-srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") `
|
||||||
-NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"}
|
-NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"}
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
|
[Parameter(Mandatory=$true)][String]$opType, #Added by CPM for 2.0
|
||||||
[Parameter(Mandatory=$true)][String]$SrcSite,
|
[Parameter(Mandatory=$true)][String]$SrcSite,
|
||||||
[Parameter(Mandatory=$true)][String]$DstSite,
|
[Parameter(Mandatory=$true)][String]$DstSite,
|
||||||
[Parameter(Mandatory=$true)][String]$SrcDatacenter,
|
[Parameter(Mandatory=$true)][String]$SrcDatacenter,
|
||||||
[Parameter(Mandatory=$true)][String]$DstDatacenter,
|
[Parameter(Mandatory=$true)][String]$DstDatacenter,
|
||||||
[Parameter(Mandatory=$true)][String]$SrcCluster,
|
#[Parameter(Mandatory=$true)][String]$SrcCluster, #Removed by CPM for 2.0
|
||||||
[Parameter(Mandatory=$true)][String]$DstCluster,
|
[Parameter(Mandatory=$true)][AllowNull()] $DstCluster, #Added [AllowNull()], removed [String] by CPM for 2.0
|
||||||
[Parameter(Mandatory=$true)][String]$DstDatastore,
|
[Parameter(Mandatory=$true)][String]$DstDatastore,
|
||||||
|
[Parameter(Mandatory=$true)][AllowNull()] $DstHost, #Added by CPM for 2.0
|
||||||
[Parameter(Mandatory=$true)][String[]]$srcVMs,
|
[Parameter(Mandatory=$true)][String[]]$srcVMs,
|
||||||
[Parameter(Mandatory=$true)][Hashtable]$NetworkMapping
|
[Parameter(Mandatory=$true)][Hashtable]$NetworkMapping
|
||||||
)
|
)
|
||||||
@@ -187,11 +193,13 @@ Function New-XVCMRequest {
|
|||||||
"targetSite"=$DstSite;
|
"targetSite"=$DstSite;
|
||||||
"sourceDatacenter"=$SrcDatacenter;
|
"sourceDatacenter"=$SrcDatacenter;
|
||||||
"targetDatacenter"=$dstDatacenter;
|
"targetDatacenter"=$dstDatacenter;
|
||||||
"sourceCluster"=$SrcCluster;
|
#"sourceCluster"=$SrcCluster; #Removed by CPM for 2.0
|
||||||
"targetCluster"=$DstCluster;
|
"targetCluster"=$DstCluster;
|
||||||
"targetDatastore"=$DstDatastore;
|
"targetDatastore"=$DstDatastore;
|
||||||
|
"targetHost"=$DstHost; #Added by CPM for 2.0
|
||||||
"networkMap"=$NetworkMapping;
|
"networkMap"=$NetworkMapping;
|
||||||
"vmList"=$srcVMs;
|
"vmList"=$srcVMs;
|
||||||
|
"operationType"=$opType; #Added by CPM for 2.0
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $body | ConvertTo-Json
|
$body = $body | ConvertTo-Json
|
||||||
|
|||||||
@@ -44,22 +44,52 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
# SourceVM must either be running or running but in Frozen State
|
# SourceVM must either be running or running but in Frozen State
|
||||||
if($vm.PowerState -ne "PoweredOn") {
|
if($vm.PowerState -ne "poweredOn") {
|
||||||
Write-Host -ForegroundColor Red "Instant Cloning is only supported on a PoweredOn or Frozen VM"
|
Write-Host -ForegroundColor Red "Instant Cloning is only supported on a PoweredOn or Frozen VM"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
# SourceVM == Powered On
|
# SourceVM == Powered On
|
||||||
if((Get-VM $SourceVM).ExtensionData.Runtime.InstantCloneFrozen -eq $false) {
|
if((Get-VM $SourceVM).ExtensionData.Runtime.InstantCloneFrozen -eq $false) {
|
||||||
Write-Host -ForegroundColor Red "Instant Cloning from a PoweredOn VM has not been implemented"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
$spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec
|
# Retrieve all Network Adapters for SourceVM
|
||||||
$locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec
|
$vmNetworkAdapters = @()
|
||||||
$spec.Config = $config
|
$devices = $vm.ExtensionData.Config.Hardware.Device
|
||||||
$spec.Location = $locationSpec
|
foreach ($device in $devices) {
|
||||||
$spec.Name = $DestinationVM
|
if($device -is [VMware.Vim.VirtualEthernetCard]) {
|
||||||
|
$vmNetworkAdapters += $device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec
|
||||||
|
$locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec
|
||||||
|
|
||||||
|
# Disconect all NICs for new Instant Clone to ensure no dupe addresses on network
|
||||||
|
# post-Instant Clone workflow needs to renable after uypdating GuestOS
|
||||||
|
foreach ($vmNetworkAdapter in $vmNetworkAdapters) {
|
||||||
|
$networkName = $vmNetworkAdapter.backing.deviceName
|
||||||
|
$deviceConfigSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec
|
||||||
|
$deviceConfigSpec.Operation = "edit"
|
||||||
|
$deviceConfigSpec.Device = $vmNetworkAdapter
|
||||||
|
$deviceConfigSpec.Device.backing = New-Object VMware.Vim.VirtualEthernetCardNetworkBackingInfo
|
||||||
|
$deviceConfigSpec.device.backing.deviceName = $networkName
|
||||||
|
$connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
|
||||||
|
$connectable.MigrateConnect = "disconnect"
|
||||||
|
$deviceConfigSpec.Device.Connectable = $connectable
|
||||||
|
$locationSpec.DeviceChange += $deviceConfigSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
$spec.Config = $config
|
||||||
|
$spec.Location = $locationSpec
|
||||||
|
$spec.Name = $DestinationVM
|
||||||
|
# SourceVM == Frozen
|
||||||
|
} else {
|
||||||
|
$spec = New-Object VMware.Vim.VirtualMachineInstantCloneSpec
|
||||||
|
$locationSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec
|
||||||
|
$spec.Config = $config
|
||||||
|
$spec.Location = $locationSpec
|
||||||
|
$spec.Name = $DestinationVM
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Creating Instant Clone $DestinationVM ..."
|
Write-Host "Creating Instant Clone $DestinationVM ..."
|
||||||
$task = $vm.ExtensionData.InstantClone_Task($spec)
|
$task = $vm.ExtensionData.InstantClone_Task($spec)
|
||||||
|
|||||||
@@ -10481,9 +10481,8 @@ function register-hvpod {
|
|||||||
#}
|
#}
|
||||||
|
|
||||||
$temppw = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ADPassword)
|
$temppw = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ADPassword)
|
||||||
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($temppw)
|
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($temppw)
|
||||||
$plainpassword
|
$vcPassword = New-Object VMware.Hv.SecureString
|
||||||
$vcPassword = New-Object VMware.Hv.SecureString
|
|
||||||
$enc = [system.Text.Encoding]::UTF8
|
$enc = [system.Text.Encoding]::UTF8
|
||||||
$vcPassword.Utf8String = $enc.GetBytes($PlainPassword)
|
$vcPassword.Utf8String = $enc.GetBytes($PlainPassword)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user