MigrationProfile/OpenshiftMigrationProfile.psm1
Import-Module -Name @(Join-Path $PSScriptRoot .. | Join-Path -ChildPath Util | Join-Path -ChildPath Util) function New-RMOpenshiftMigrationProfile { param( [Parameter(Mandatory)] [System.Object] $CloudAccount, [Parameter(Mandatory)] [System.Object] $Entitlement, [Parameter(Mandatory)] [System.Object] $Source, [Parameter(Mandatory)] [System.Object] $ScheduledAt, [string] $TransferMethod, [Parameter(Mandatory)] [string] $TargetVMName, [string] $InstanceType, [System.Object] $Cores, [System.Object] $RAM, [System.Object] $Sockets, [Parameter(Mandatory)] [string] $VolumeType, [System.Object] $ResizeMountPoint, [Parameter(Mandatory)] [string] $Project, [Parameter(Mandatory)] [string] $NetworkName, [Parameter(Mandatory)] [string] $NetworkType, [Parameter(Mandatory)] [string] $NetworkAdapterModel, [Parameter(Mandatory)] [System.Object[]] $SelectedMount, [Parameter(Mandatory)] [bool] $RemoveRMSAgent, [Parameter(Mandatory)] [bool] $ShutdownSource, [Parameter(Mandatory)] [bool] $ShutdownTarget, [bool] $ConnectARCAgent, [bool] $InstallAzureARC, [System.Object] $InstallApplicationParameter, [string] $NetBIOSName, [hashtable] $OSHardening, [string] $MigrationExtension, [string] $MigrationExtensionId, [string] $MigrationExtensionOSM, [string] $MigrationExtensionIdOSM, [bool] $InPlaceUpgrade, [System.Object] $UpgradeOSVersion, [bool] $IgnoreValidationError, [bool] $DisableTargetDNSRegistration, [string] $AccessMode, [string] $VolumeMode, [hashtable] $MigrationInstruction, [bool] $EnableCloudFilesMigration, [bool] $GeneralizeSystem, [hashtable] $ConvertFileSystem ) $MigrationExtensionIdArray = @() if (![string]::IsNullOrEmpty($MigrationExtensionId)) { $MigrationExtensionIdArray += $MigrationExtensionId } $MigrationExtensionArray = @() if (![string]::IsNullOrEmpty($MigrationExtension)) { $MigrationExtensionArray += $MigrationExtension } $MigrationExtensionIdOSMArray = @() if (![string]::IsNullOrEmpty($MigrationExtensionIdOSM)) { $MigrationExtensionIdOSMArray += $MigrationExtensionIdOSM } $MigrationExtensionOSMArray = @() if (![string]::IsNullOrEmpty($MigrationExtensionOSM)) { $MigrationExtensionOSMArray += $MigrationExtensionOSM } $InstallApplicationsObject = @() if ($InstallAzureARC) { $InstallApplicationsObject = @( @{ "name" = "AZURE_ARC" "parameters" = $InstallApplicationParameter } ) } if ($null -ieq $ConvertFileSystem) { $ConvertFileSystem = @{} } $CurrentTime = Get-Date -Format "yyyy/MM/dd HH:mm:ss" $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" = if ([string]::IsNullOrEmpty($ScheduledAt)) { $null } else { $ScheduledAt } "transfer_mode" = "run-once" "sources" = @( @{ "desc" = "Basic Migration" "source"= $Source.id "transfer_type" = $TransferMethod "target_config" = @{ "vm_details" = @{ "vm_name" = $TargetVMName "flavor" = @{ "cores" = $Cores "ram_gb" = $RAM "sockets" = $Sockets "flavor_type" = if([string]::IsNullOrEmpty($InstanceType)) { $null } else {$InstanceType} "volume_type" = $VolumeType "volume_access_mode" = if ([string]::IsNullOrEmpty($AccessMode)) { $null } else { $AccessMode } "volume_mode" = if ([string]::IsNullOrEmpty($VolumeMode)) { $null } else {$VolumeMode} } "external_network_name" = $null } "options" = @{ "project" = $Project } "properties" = @{ "network" = @{ "automatic_dns_registration" = !$DisableTargetDNSRegistration "interfaces" = @{ "eth0" = @{ "ip_type" = "dhcp" "network_name" = $NetworkName "type" = $NetworkType "adapter_type" = $NetworkAdapterModel } } } "selected_mounts" = $SelectedMount "mounts_new_size"= $ResizeMountPoint "convert_filesystems"= $ConvertFileSystem "name" = $TargetVMName "connect_azure_arc_agent" = $ConnectARCAgent "install_applications" = $InstallApplicationsObject "hostname" = $NetBIOSName } } "harden_os" = if ($null -ieq $OSHardening) { $false } else { $true } "os_hardening" = $OSHardening "os_type" = $Source.os_type "name" = $Source.hostname "collection_type" = $null "binary_asset_groups" = @( @{ "binary_assets" = $MigrationExtensionIdArray } @{ "binary_asset_names" = $MigrationExtensionArray } ) "binary_asset_groups_osm"= @( @{ "osm_assets" = $MigrationExtensionIdOSMArray } @{ "osm_asset_names" = $MigrationExtensionOSMArray } ) "shutdown_source"= $ShutdownSource "shutdown_target"= $ShutdownTarget "in_place_upgrade" = $InPlaceUpgrade "upgrade_os_version" = if ([string]::IsNullOrEmpty($UpgradeOSVersion)) { $null } else { $UpgradeOSVersion } "remove_target_agent" = $RemoveRMSAgent "migration_instructions" = $MigrationInstruction "ignore_validation_errors" = $IgnoreValidationError "file_storage_mode" = if($EnableCloudFilesMigration) { "netapp" } else { $null } "generalize_system" = $GeneralizeSystem "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/json" Cookie = $RMLoginResult } $Params = @{ Method = "Post" Uri = $Uri + "/migrationprofiles" Body = $MigrationProfileJson ContentType = "application/json" Headers = $Headers } return Invoke-RMRestMethod -Params $Params } function New-RMOpenshiftVMBasedMigrationProfile { param ( [Parameter(Mandatory)] [System.Object] $CloudAccount, [Parameter(Mandatory)] [System.Object] $Entitlement, [Parameter(Mandatory)] [System.Object] $Source, [Parameter(Mandatory)] [System.Object] $ScheduledAt, [Parameter(Mandatory)] [string] $TargetVMName, [System.Object] $Cores, [System.Object] $RAM, [System.Object] $Sockets, [Parameter(Mandatory)] [string] $VolumeType, [string] $AccessMode, [string] $VolumeMode, [Parameter(Mandatory)] [string] $Project, [Parameter(Mandatory)] [string] $NetworkName, [Parameter(Mandatory)] [string] $NetworkType, [Parameter(Mandatory)] [string] $NetworkAdapterModel, [Parameter(Mandatory)] [System.Object[]] $SelectedMount, [string] $MigrationExtension, [string] $MigrationExtensionId, [bool] $ShutdownSource, [bool] $ShutdownTarget, [bool] $FinalizeTarget, [hashtable] $MigrationInstruction, [bool] $IgnoreValidationError, [string] $InstanceType ) $MigrationExtensionIdArray = @() if (![string]::IsNullOrEmpty($MigrationExtensionId)) { $MigrationExtensionIdArray += $MigrationExtensionId } $MigrationExtensionArray = @() if (![string]::IsNullOrEmpty($MigrationExtension)) { $MigrationExtensionArray += $MigrationExtension } $CurrentTime = Get-Date -Format "yyyy/MM/dd HH:mm:ss" $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" = if ([string]::IsNullOrEmpty($ScheduledAt)) { $null } else { $ScheduledAt } "transfer_mode" = "run-once" "sources" = @( @{ "desc" = "Basic Migration" "source" = $Source.id "generalize_system" = $false "transfer_type" = "block-based" "target_config" = @{ "vm_details" = @{ "vm_name" = $TargetVMName "flavor" = @{ "cores" = if(0 -ieq $Cores) { $null } else { $Cores } "sockets" = if(0 -ieq $Sockets) { $null } else { $Sockets } "ram_gb" = if(0 -ieq $RAM) { $null } else { $RAM } "flavor_type" = if([string]::IsNullOrEmpty($InstanceType)) { $null } else {$InstanceType} "volume_type" = $VolumeType "volume_access_mode" = if ([string]::IsNullOrEmpty($AccessMode)) { $null } else { $AccessMode } "volume_mode" = if ([string]::IsNullOrEmpty($VolumeMode)) { $null } else {$VolumeMode} } "external_network_name" = $null } "options" = @{ "project" = $Project } "properties" = @{ "network" = @{ "interfaces" = @{ "eth0" = @{ "ip_type" = "dhcp" "network_name" = $NetworkName "type" = $NetworkType "adapter_type" = $NetworkAdapterModel } } } "mounts_new_size" = @{} "selected_mounts" = $SelectedMount "convert_filesystems" = @{} "name" = $TargetVMName } } "transfer_technology" = "bbt" "os_type" = $Source.os_type "name" = $Source.name "collection_type" = "vm" "binary_asset_groups" = @( @{ "binary_assets" = $MigrationExtensionIdArray } @{ "binary_asset_names" = $MigrationExtensionArray } ) "shutdown_source"= $ShutdownSource "shutdown_target"= $ShutdownTarget "finalize_target" = $FinalizeTarget "in_place_upgrade" = $false "upgrade_os_version" = $null "migration_instructions" = $MigrationInstruction "ignore_validation_errors" = $IgnoreValidationError "preflight_warning" = $false } ) } $MigrationProfileJson = $MigrationProfile |ConvertTo-Json -Depth 100 $RMLoginResult = Get-Variable -Name "RMContext-UserLogin" -ValueOnly $Uri = Get-Variable -Name "RMContext-ReactorURI" -ValueOnly $Headers = @{ Accept = "application/json" Cookie = $RMLoginResult } $Params = @{ Method = "Post" Uri = $Uri + "/migrationprofiles" Body = $MigrationProfileJson ContentType = "application/json" Headers = $Headers } return Invoke-RMRestMethod -Params $Params } |