Migration/openshift/openshiftUtil.psm1

Import-Module -Name @(Join-Path $PSScriptRoot .. | Join-Path -ChildPath .. | Join-Path -ChildPath Common | Join-Path -ChildPath Wrappers | Join-Path -ChildPath Wrappers)

function Read-RMInstanceType {
    param (
        [System.Object] $TargetInventory
    )
    
    while ($true) {
        $ReadValue = Read-RMString -UserMessage "Enter instance type, e.g. cx1.large" `
            -ParameterName "Instance type" -DefaultValue "None" -IsRequired $false

        $InstanceTypeArray = $TargetInventory.attributes.openshift.instance_types.name

        if ("" -ne $ReadValue -and $InstanceTypeArray -notcontains $ReadValue) {
            Write-RMError -Message "Instance type '$ReadValue' does not exist."
            continue
        }

        return $ReadValue
    }
}

function  Read-RMRAMOrCPU {
    param (
        [int] $MinValue,
        [string] $ErrorMessage,
        [string] $UserMessage,
        [string] $DefaultValue,
        [string] $ParameterName
    )
    
    while ($true) {
        $ReadValue = Read-RMInt -UserMessage $UserMessage -DefaultValue $DefaultValue `
            -ParameterName $ParameterName -IsRequired $false
        if ($ReadValue -lt $MinValue) {
            Write-RMError -Message $ErrorMessage
            continue
        }

        return $ReadValue
    }
}