MigrationProfile/VSphereMigrationProfile.psm1
Import-Module -Name $PSScriptRoot\..\Util\Util function New-RMVSphereMigrationProfile { param( [Parameter(Mandatory)] [System.Object] $CloudAccount, [Parameter(Mandatory)] [System.Object] $Entitlement, [Parameter(Mandatory)] [System.Object] $Source, [Parameter(Mandatory)] [string] $TargetVMName, [Parameter(Mandatory)] [System.Object[]] $SelectedMounts, [Parameter(Mandatory)] [hashtable] $MountsResize, [Parameter(Mandatory)] [bool] $ShutdownSource, [Parameter(Mandatory)] [bool] $ShutdownTarget, [Parameter(Mandatory)] [bool] $RemoveRMSAgent, [Parameter(Mandatory)] [string] $DatacenterName, [bool] $EnableDestinationNetworkIsolation, [string] $DestinationNetworkName, [string] $EnableDvSwitchName, [string] $EnableIpType, [string] $EnableIpAddress, [string] $EnableNetmask, [string] $EnableDefaultGateway, [string] $EnablePrimaryDNS, [string] $EnableSecondaryDNS, [string] $IsolatedNetworkName, [string] $IsolatedDvSwitchName, [string] $IsolatedIpType, [string] $IsolatedIpAddress, [string] $IsolatedNetmask, [string] $IsolatedDefaultGateway, [string] $IsolatedPrimaryDNS, [string] $IsolatedSecondaryDNS, [string] $IpType, [string] $IpAddress, [string] $Netmask, [string] $DefaultGateway, [string] $PrimaryDNS, [string] $SecondaryDNS, [string] $DvSwitchName, [bool]$DisableAuthomaticDNSRegistrationOnTheTarget, [Parameter(Mandatory)] [string] $Cluster, [Parameter(Mandatory)] [string[]] $DatastoreLocations, [string] $FolderName, [string] $DatastoreCluster, [Parameter(Mandatory)] [string[]] $DisksProvisioningType, [string] $TransferType, [Parameter(Mandatory)] [string] $CoresPerSocket, [Parameter(Mandatory)] [bool] $OverrideMemory, [int] $OverrideMemorySize, [string] $ResourcePool, [Parameter(Mandatory)] [int] $HardwareVersion, [Parameter(Mandatory)] [string] $ToolsPackage, [hashtable] $MigrationInstructions, [Parameter(Mandatory)] [bool] $InPlaceUpgrade, [System.Object] $UpgradeOSVersion ) $CurrentTime = Get-Date -Format "yyyy/MM/dd HH:mm:ss" if ($OverrideMemory -eq $true) { $MemorySize = $OverrideMemorySize } else { $MemorySize = $Source.attributes.memory.total_kb/1000000 } if ($DisableAuthomaticDNSRegistrationOnTheTarget -eq $true) { $AutomaticDnsRegistration = $false } else { $AutomaticDnsRegistration = $true } $StaticInterfaces = @{} if ("" -ne $DvSwitchName) { $StaticInterfaces = @{ "dv_switch_name" = "$DvSwitchName" "ip_addr" = "$IpAddress" "ip_type" = "$IpType" "netmask" = "$Netmask" "network_name"= $DestinationNetworkName "type"= "Ethernet" } } else { $StaticInterfaces = @{ "ip_addr" = "$IpAddress" "ip_type" = "$IpType" "netmask" = "$Netmask" "network_name"= $DestinationNetworkName "type"= "Ethernet" } } $DHCPInterfaces =@{} if ("" -ne $DvSwitchName) { $DHCPInterfaces = @{ "dv_switch_name" = "$DvSwitchName" "ip_type"= "$IpType" "type"= "Ethernet" "network_name"= $DestinationNetworkName } } else { $DHCPInterfaces = @{ "ip_type"= "$IpType" "type"= "Ethernet" "network_name"= $DestinationNetworkName } } $MigrationNetworkStaticIp = @{ "dns" = @{ "primary" = "$PrimaryDNS" "secondary" = "$SecondaryDNS" } "interface" = $StaticInterfaces "routes" = @{ "default_gateway" = "$DefaultGateway" } } $MigrationNetworkDHCP = @{ "interface" = $DHCPInterfaces } $IsolatedStaticInterfaces = @{} if ("" -ne $IsolatedDvSwitchName) { $IsolatedStaticInterfaces = @{ "eth0" = @{ "dv_switch_name" = $IsolatedDvSwitchName "ip_addr" = "$IsolatedIpAddress" "ip_type" = "$IsolatedIpType" "netmask" = "$IsolatedNetmask" "network_name" = $IsolatedNetworkName "type" = "Ethernet" } } } else { $IsolatedStaticInterfaces = @{ "eth0" = @{ "ip_addr" = "$IsolatedIpAddress" "ip_type" = "$IsolatedIpType" "netmask" = "$IsolatedNetmask" "network_name" = $IsolatedNetworkName "type" = "Ethernet" } } } $IsolatedNetworkStaticIp = @{ "automatic_dns_registration" = $AutomaticDnsRegistration "dns" = @{ "primary" = "$IsolatedPrimaryDNS" "secondary" = "$IsolatedSecondaryDNS" } "interfaces" = $IsolatedStaticInterfaces "routes" = @{ "default_gateway" = "$IsolatedDefaultGateway" } } if ("" -ne $IsolatedDvSwitchName) { $IsolatedNetworkDHCP =@{ "interfaces" = @{ "eth0"= @{ "dv_switch_name" = $IsolatedDvSwitchName "ip_type"= "$IsolatedIpType" "type"= "Ethernet" "network_name"= $IsolatedNetworkName } } "automatic_dns_registration" = $AutomaticDnsRegistration } } else { $IsolatedNetworkDHCP =@{ "interfaces" =@{ "eth0"= @{ "ip_type"= "$IsolatedIpType" "type"= "Ethernet" "network_name"= $IsolatedNetworkName } } "automatic_dns_registration" = $AutomaticDnsRegistration } } $NetworkStaticIp = @{ "automatic_dns_registration" = $AutomaticDnsRegistration "dns" = @{ "primary" = "$PrimaryDNS" "secondary" = "$SecondaryDNS" } "interfaces" = @{ "eth0" = $StaticInterfaces } "routes" = @{ "default_gateway" = "$DefaultGateway" } } $NetworkDHCP = @{ "interfaces" = @{ "eth0"= $DHCPInterfaces } "automatic_dns_registration" = $AutomaticDnsRegistration } $properties = $null if ($IsolatedIpType -eq "static") { $IsolatedNetworkProperties = $IsolatedNetworkStaticIp } else { $IsolatedNetworkProperties = $IsolatedNetworkDHCP } if ($IpType -eq "static") { $NetworkProperties = $NetworkStaticIp } else { $NetworkProperties = $NetworkDHCP } if ($EnableDestinationNetworkIsolation) { if ($IpType -eq "static") { $MigrationNetworkProperties = $MigrationNetworkStaticIp } else { $MigrationNetworkProperties = $MigrationNetworkDHCP } $properties = @{ "migration_network" = $MigrationNetworkProperties "mounts_new_size"= $MountsResize "name"= $TargetVMName "network" = $IsolatedNetworkProperties "selected_mounts"= $SelectedMounts } } else { $properties = @{ "mounts_new_size"= $MountsResize "name"= $TargetVMName "network" = $NetworkProperties "selected_mounts"= $SelectedMounts } } $MigrationProfile = @{ "name"= "powershell-" + $Source.host + "-" + $CurrentTime "tags"= @() "entitlement"=$Entitlement.id "cloud_account"=$CloudAccount.id "is_data_only"= $false "is_vdi"= $false "appliance_id"=$CloudAccount.appliance.id "schedule"= $null "transfer_mode"="run-once" "sources"= @( @{ "source"= $Source.id "target_config"= @{ "vm_details"= @{ "datacenter_name" = "$DatacenterName" "datastore_cluster" = "" "datastore_cluster_name" = "$DatastoreCluster" "datastore_locations" = $DatastoreLocations "storage_profile_ids" = @() "storage_profile_names" = @() "disks_provisioning_types" = $DisksProvisioningType "network_name"= $null "folder_name" = "$FolderName" "target_name" = "$Cluster" "target_type" = "cluster" "resource_pool" = "$ResourcePool" "vapp_name" = "$TargetVMName" "flavor"= @{ "cpu" = $Source.attributes.cpu.processors.Count "ram_gb" = $MemorySize "cores_per_socket" = $CoresPerSocket } "tools_package" = "$ToolsPackage" "tools_removed_exclusions" = @( "ThinPrint", "WYSE", "Buslogic", "Sync" ) "hardware_version" = "$HardwareVersion" } "properties" = $properties "options"= @{ "power_on"= $true } } "verify_ssl_certificates"= $false "transfer_type" = "$TransferType" "publish_migration_hub"= $false "os_type"= $Source.os_type "name"= $Source.name "collection_type"= $null "shutdown_source"= $ShutdownSource "shutdown_target"= $ShutdownTarget "remove_target_agent"= $RemoveRMSAgent "in_place_upgrade"= $InPlaceUpgrade "upgrade_os_version"= $UpgradeOSVersion "migration_instructions"= $MigrationInstructions "data_transfer_port"= $null "ignore_validation_errors"= $true "preflight_warning"= $false } ) } # Giving max depth otherwise the cmdlet 'ConvertTo-Json' will truncate the JSON $MigrationProfileJson = $MigrationProfile |ConvertTo-Json -Depth 100 $RMLoginResult = Get-Variable -Name "RMContext-UserLogin" -ValueOnly $Uri = Get-Variable -Name "RMContext-ReactorURI" -ValueOnly $Headers = @{ Accept = "application/rm+json" "X-Auth-Token" = $RMLoginResult.token } $Params = @{ Method = "Post" Uri = $Uri + "/migrationprofiles" Body = $MigrationProfileJson ContentType = "application/json" Headers = $Headers } Invoke-RMRestMethod -Params $Params } #TODO=try to make all the methods in the module as private, yet accessible from our code(other modules) Export-ModuleMember -Function New-RMVSphereMigrationProfile |