ConfigManager.psm1

Import-Module $PSScriptRoot\Utils.psm1
Import-Module $PSScriptRoot\ClusUtils.psm1

$script:CMap = @{}

$script:CMap["turnKeySdnPath"] = ""
$script:CMap["storePath"] = ""
$script:CMap["state"] = "state.json"
$script:CMap["credential"] = "cred.json"
$script:CMap["workloadcredential"] = "workloadcred.json"
$script:CMap["userConfigPath"] = "$PSScriptRoot\config\deployment"
$script:CMap["deploymentConfigPath"] = "$PSScriptRoot\config\deployment"
$script:CMap["deploymentFile"] = "deployment.json"
$script:CMap["hnvpaNetworkFile"] = "networkconfig\logicalnetworks\hnvpa.json"
$script:CMap["mgmtNetworkFile"] = "networkconfig\logicalnetworks\management.json"
$script:CMap["greNetworkFile"] = "networkconfig\logicalnetworks\grevip.json"
$script:CMap["publicVIPNetworkFile"] = "networkconfig\logicalnetworks\publicvip.json"
$script:CMap["privateVIPNetworkFile"] = "networkconfig\logicalnetworks\privatevip.json"
$script:CMap["macpoolFile"] = "networkconfig\macpools\defaultMacPool.json"
$script:CMap["sdnConfigFile"] = "sdnconfig.json"

$script:CMap["sdnExpressConfigPath"] = "$PSScriptRoot\config\sdnexpress"
$script:CMap["sdnExpressTemplateFile"] = "template.psd1"

$script:CMap["userWorkloadConfigPath"] = "$PSScriptRoot\config\workload"
$script:CMap["workloadConfigPath"] = "$PSScriptRoot\config\workload"
$script:CMap["workload"] = "workloadconfig.json"

$script:CMap["vhdStore"] = ""

$script:MgmtHostNicName = "TurnKeySdn-Mgmt"

$script:DefaultTestVhdShare = "\\skyshare.redmond.corp.microsoft.com\Beanstalk\SDN_ADOArtifacts\TestArtifacts\mariner_workload_vhd"
$script:DefaultTestVhdFile = "full-2.0.20231004.vhdx"

$script:InstallStateInstalled = "installed"
$script:InstallStateInstallFailed = "installFailed"
$script:InstallStateInstalling = "installing"
$script:InstallStateNone = "none"

$script:InternetSwitchDefaultName = "turnkeysdn-internet"
$script:SdnSwitchDefaultName = "turnkeysdn-sdnswitch"

# Corp network routes, used on the management nic of gateway VMs to allow access to corp network
$script:MSFTCorpRoutes = @("10.0.0.0/8")
function Initialize-StorePath {

    if (-not [String]::IsNullOrEmpty($script:CMap["turnKeySdnPath"]) -and `
            -not ([String]::IsNullOrEmpty($script:CMap["storePath"]))) {
        return
    }

    $csv = Get-CSV

    if ($null -ne $csv) {
        $script:CMap["turnKeySdnPath"] = Join-Path $csv "TurnKeySdn"
        $script:CMap["vhdStore"] = Join-Path $csv "TurnKeySdnVhdStore"
    }
    else {
        $script:CMap["turnKeySdnPath"] = Join-Path $Env:SystemDrive "TurnKeySdn"
        $script:CMap["vhdStore"] = Join-Path $Env:SystemDrive "TurnKeySdnVhdStore"
    }

    $script:CMap["storePath"] = Join-Path $script:CMap["turnKeySdnPath"] ".store"

    if (Test-IsInitialized) {
        $script:CMap["deploymentConfigPath"] = Join-Path $script:CMap["turnKeySdnPath"] "DeploymentConfig"
        $script:CMap["workloadConfigPath"] = Join-Path $script:CMap["turnKeySdnPath"] "WorkloadConfig"
    }
    
    if (-not $(Test-Path (Get-TurnKeySdnPath))) {
        New-Item (Get-TurnKeySdnPath) -ItemType Directory -ErrorAction Stop | Out-Null
    }

    if (-not $(Test-Path (Get-StorePath))) {
        New-Item (Get-StorePath) -ItemType Directory -ErrorAction Stop | Out-Null
    }

}

function Undo-StorePathInitialization {
    $script:CMap["turnKeySdnPath"] = ""
    $script:CMap["storePath"] = ""
    $script:CMap["deploymentConfigPath"] = $script:CMap["userConfigPath"] 
    $script:CMap["workloadConfigPath"] = $script:CMap["userWorkloadConfigPath"]
    $script:CMap["vhdStore"] = ""

}

function Get-StorePath {
    Initialize-StorePath
    return $script:CMap["storePath"]
}

function Get-TurnKeySdnPath {
    Initialize-StorePath
    return $script:CMap["turnKeySdnPath"]
}

function Get-InternalDeploymentConfigPath {
    Initialize-StorePath
    return $script:CMap["deploymentConfigPath"]
}

function Get-InternalWorkloadConfigPath {
    Initialize-StorePath
    return $script:CMap["workloadConfigPath"]
}

function Get-VhdStore {
    Initialize-StorePath
    return $script:CMap["vhdStore"]
}

function Get-SdnExpressPath {

    param (
        [parameter(Mandatory = $false)][switch] $SkipConfigPath
    )

    if (-not $($SkipConfigPath.IsPresent)) {
        $infraconfig = Get-DeploymentConfig
        $sdnExpPath = $infraconfig.sdnexpressPath
    
        if (-not [String]::IsNullOrEmpty($sdnExpPath)) {
            $sdnExpPSM1 = Join-Path $sdnExpPath "SDNExpress.psm1"
            if ($(Test-Path $sdnExpPSM1)) {
                return $sdnExpPath
            }
        }
    }

    $sdnExpPath = Join-Path $PSScriptRoot "..\..\SDNExpress"
    $sdnExpPSM1 = Join-Path $sdnExpPath "SDNExpress.psm1"
    if ($(Test-Path $sdnExpPSM1)) {
        return $sdnExpPath
    }

    Import-Module -Name SdnExpress -ErrorAction SilentlyContinue
    $module = Get-Module SdnExpress
    if ($null -ne $module) {
        return $module.ModuleBase
    }

    return $null
}

function Set-SdnExpressPathInternal {
    param(
        [parameter(Mandatory = $true)][string] $sdnExpressPath
    )
 
    $infraconfig = Get-DeploymentConfig
    $infraconfig.sdnexpressPath = $sdnExpressPath
    Set-DeploymentConfig -deploymentConfig $infraconfig
    Write-TraceLog "Set-SdnExpressPath: Updated path to $sdnExpressPath"
}

function Get-SdnExpressModule {
    $sdnExpPath = Get-SdnExpressPath
    $sdnexpress = Join-Path $sdnExpPath SDNExpress.psm1
    return $sdnexpress
}

function Get-SdnExpressScript {
    $sdnExpPath = Get-SdnExpressPath
    $sdnexpress = Join-Path $sdnExpPath SDNExpress.ps1
    return $sdnexpress
}

function Get-RestoreReplayScriptPath {
    
    param (
        [parameter(Mandatory = $false)][switch] $SkipConfigPath
    )

    if (-not $($SkipConfigPath.IsPresent)) {
        $infraconfig = Get-DeploymentConfig
        $restoreReplayScriptPath = $infraconfig.restoreReplayScriptPath

        if (-not [String]::IsNullOrEmpty($restoreReplayScriptPath)) {
            $restoreReplayScript = Join-Path $restoreReplayScriptPath RestoreReplay.ps1
            if ($(Test-Path $restoreReplayScript)) {
                return $restoreReplayScriptPath
            }
        }
    }

    $restoreReplayScriptPath = Join-Path $PSScriptRoot "..\BCDR"
    $restoreReplayScript = Join-Path $restoreReplayScriptPath RestoreReplay.ps1
    if ($(Test-Path $restoreReplayScript)) {
        return $restoreReplayScriptPath
    }

    $script = Get-InstalledScript RestoreReplay -ErrorAction SilentlyContinue

    if ($null -ne $script) {
        return $script.InstalledLocation
    }

    return $null
}

function Get-RestoreReplayScript {
    $restoreReplayScriptPath = Get-RestoreReplayScriptPath
    $restoreReplay = Join-Path $restoreReplayScriptPath RestoreReplay.ps1
    return $restoreReplay
}

function Get-DefaultNetworkControllerPsModulePath {
    return Join-Path $env:SystemRoot "system32\WindowsPowerShell\v1.0\Modules\NetworkControllerFc"
}
function Get-DefaultNetworkControllerPackageLocation {
    return (Join-Path $env:SystemRoot "NetworkController")
}

function Get-DefaultNetworkControllerDBLocation {
    $csv = Get-CSV

    if ($csv -ne $null) {
        return (Join-Path $csv "FCNCDB")
    }

    return (Join-Path $env:SystemDrive "FCNCDB")
}

function Set-AddressRandmoizerSeed {
    param(
        [parameter(Mandatory = $true)][int] $seed
    )

    $internalConfig = Get-TurnKeySdnInternalConfig -configType state
    $internalConfig.randomizerSeed = $seed
    Set-TurnKeySdnInternalConfig -configType state -config $internalConfig
}

function Get-AddressRandmoizerSeed {

    $internalConfig = Get-TurnKeySdnInternalConfig -configType state
    if (-not [String]::IsNullOrEmpty($internalConfig.randomizerSeed)) {
        return [int]$internalConfig.randomizerSeed
    }

    $curhost = (hostname)
    $hostIndex = $curhost.Substring($($curhost.Length - 2))
    $result = 0

    if (-not [int]::TryParse($hostIndex, [ref]$result)) {
        $result = Get-Random -Minimum 1 -Maximum 60
    }

    return $result
}

function Get-RandomizedIPv4Address {
    param(
        $address,
        $randomizer
    )

    $addresses = $address.Split(".")
    $addresses[1] = ([int]$addresses[1] + $randomizer) % 255
    return $addresses -join '.'
}

function Update-IPv4Address {
    param(
        $Address
    )

    $depConfig = Get-DeploymentConfig

    if (-not $depConfig.randomizeAddresses) {
        return $Address
    }

    $randomizer = Get-AddressRandmoizerSeed
    $addr = Get-RandomizedIPv4Address -address $Address -randomizer $randomizer
    return $addr
}
function Update-LogicalNetworkAddresses {
    param(
        $network
    )

    $depConfig = Get-DeploymentConfig

    if (-not $depConfig.randomizeAddresses) {
        return $network
    }

    $isOneNode = $depConfig.hyperVHosts.Count -eq 1
    $randomizer = Get-AddressRandmoizerSeed
    $network.properties.subnets | ForEach-Object {
        $subnetProp = $_.properties
        $subnetProp.addressPrefix = Get-RandomizedIPv4Address -address $subnetProp.addressPrefix -randomizer $randomizer

        $newGateways = @()
        $subnetProp.defaultGateways | ForEach-Object {
            $newGateways += Get-RandomizedIPv4Address -address $_ -randomizer $randomizer
        }

        $subnetProp.defaultGateways = $newGateways

        $subnetProp.ipPools | Foreach-Object {
            $poolProp = $_.Properties
            $poolProp.startIpAddress = Get-RandomizedIPv4Address -address $poolProp.startIpAddress -randomizer $randomizer
            $poolProp.endIpAddress = Get-RandomizedIPv4Address -address $poolProp.endIpAddress -randomizer $randomizer
        }

        if ($isOneNode) {
            $subnetProp.vlanID = $([int]$subnetProp.vlanID) + $randomizer
        }
    }
    return $network
}

function Set-TurnKeySdnInternalConfig {

    param(
        [ValidateSet("workloadcredential","credential", "state")]
        [parameter(Mandatory = $true)][string] $configType,
        [parameter(Mandatory = $true)] $config
    )

    $configFile = Join-Path (Get-StorePath) $script:CMap[$configType]
    $value = $(ConvertTo-Json $config -Depth 10)
    Set-Content -Path $configFile -Value $value -Encoding UTF8
}

function Get-TurnKeySdnInternalConfig {

    param(
        [ValidateSet("workloadcredential","credential", "state")]
        [parameter(Mandatory = $true)][string] $configType
    )

    $configFile = Join-Path (Get-StorePath) $script:CMap[$configType]
    return $(Get-Config $configFile)
}

function Test-TurnKeySdnStateConfigExist {   
    $configFile = Get-StateFileWithoutInit
    return $(Test-Path $configFile)
}

function Get-TurnKeySdnCred {

    if ($Global:SdnCredential -ne $null -and $Global:SdnCredential -ne [pscredential]::Empty) {
        return $Global:SdnCredential
    }

    $configFile = Join-Path (Get-StorePath) $script:CMap["credential"]
    try {
        $c = Get-Config $configFile
    } catch {
    }
    
    if ([String]::IsNullOrEmpty($c.username) -or [String]::IsNullOREmpty($c.password)) {
        Write-TraceLog "Get-TurnKeySdnCred: Failed to get credentials, defaulting to empty cred"    
        return [pscredential]::Empty
    }

    $cred = [pscredential]::new($c.username, $($c.password | ConvertTo-SecureString -ErrorAction Stop))
    return $cred
}
function Get-TurnKeySdnWorkloadVmCred {

    # todo: find a better way to store workload credentials
    # $configFile = Join-Path (Get-StorePath) $script:CMap["workloadcredential"]
    # $c = Get-Config $configFile
    
    # if([string]::IsNullOrEmpty($c.username) -or [string]::IsNullOrEmpty($c.password)) {

    # throw "Workload VMcredentials is not initialized. Please make sure $Env:TURNKEY_WORKLOAD_PASSWORD is set on the machine. Then run initialize again for TurnKey SDN"

    # } else {
    # $vmUserName = $c.username
    # $vmUserPassword = $c.password
    # }
    $vmUserName = $Env:TURNKEY_WORKLOAD_USERNAME
    $vmUserPassword = $Env:TURNKEY_WORKLOAD_PASSWORD
    return  [pscredential]::new($vmUserName, $($vmUserPassword | ConvertTo-SecureString  -AsPlainText -Force))
}


function Get-Config {
    param(
        [parameter(Mandatory = $true)][string] $file
    )

    Test-FileExist -path $file
    $config = Get-Content $file -ErrorAction Stop | ConvertFrom-Json
    return $config
}

function Get-GreVipLogicalNetworkConfig {
    param(
        [Parameter(Mandatory = $false)][bool] $RandomizeAddress = $true
    )

    $greNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["greNetworkFile"]
    $network = Get-Config $greNetworkFile
    if ($RandomizeAddress) {
        $network = Update-LogicalNetworkAddresses $network
    }
    return $network
}

function Set-GreVipNetworkConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Network
    )

    $greNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["greNetworkFile"]
    $Network | ConvertTo-Json -Depth 100 | Out-File $greNetworkFile -Force
}

function Get-HnvPaNetworkConfig {
    param(
        [Parameter(Mandatory = $false)][bool] $RandomizeAddress = $true
    )

    $hnvpaNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["hnvpaNetworkFile"]
    $hnvPaNetwork = Get-Config $hnvpaNetworkFile
    if ($RandomizeAddress) {
        $hnvPaNetwork = Update-LogicalNetworkAddresses $hnvPaNetwork
    }
    return $hnvPaNetwork
}

function Set-HnvPaNetworkConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Network
    )

    $hnvpaNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["hnvpaNetworkFile"]
    $Network | ConvertTo-Json -Depth 100 | Out-File $hnvpaNetworkFile -Force
}

function Get-MgmtNetworkConfig {
    param(
        [Parameter(Mandatory = $false)][bool] $RandomizeAddress = $true
    )
    $mgmtNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["mgmtNetworkFile"]
    $mgmtNetwork = Get-Config $mgmtNetworkFile
    if ($RandomizeAddress) {
        $mgmtNetwork = Update-LogicalNetworkAddresses $mgmtNetwork
    }
    return $mgmtNetwork
}
function Set-MgmtNetworkConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Network
    )

    $mgmtNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["mgmtNetworkFile"]
    $Network | ConvertTo-Json -Depth 100 | Out-File $mgmtNetworkFile -Force
}
function Get-PublicVipNetworkConfig {
    $publicVipNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["publicVipNetworkFile"]
    $publicVipNetwork = Get-Config $publicVipNetworkFile
    return $publicVipNetwork
}

function Set-PublicVipNetworkConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Network
    )

    $publicVipNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["publicVipNetworkFile"]   
    $Network | ConvertTo-Json -Depth 100 | Out-File $publicVipNetworkFile -Force
}

function Get-PrivateVipNetworkConfig {
    $privateVipNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["privateVipNetworkFile"]
    $privateVipNetwork = Get-Config $privateVipNetworkFile
    return $privateVipNetwork
}

function Set-PrivateVipNetworkConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Network
    )

    $privateVipNetworkFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["privateVipNetworkFile"]   
    $Network | ConvertTo-Json -Depth 100 | Out-File $privateVipNetworkFile -Force
}

function Get-DeploymentConfig {
    $config = Get-Config $(Get-DeploymentFile)
    
    # config upgrade for productkey
    $p = $config | Get-Member -Name productKey -ErrorAction SilentlyContinue
    if ($null -eq $p) {
        $config | add-member -NotePropertyName productKey -NotePropertyValue ""
    }

    return $config
}

function Update-MacAddress {
    param($mac)

    $macEle = $mac.Split("-")
    $rand = Get-AddressRandmoizerSeed
    $strRand = [string]$rand

    if ($strRand.Length -eq 1) {
        $strRand = "0$strRand"
    }

    $macEle[3] = $strRand
    $result = $macEle -join '-'

    return $result
}

function Get-DefaultMacPoolConfig {
    $configFileName = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["macpoolFile"]
    $config = Get-Config $configFileName

    $depConfig = Get-DeploymentConfig

    if ($depConfig.randomizeAddresses) {
        $config.properties.startMacAddress = Update-MacAddress -mac $config.properties.startMacAddress
        $config.properties.endMacAddress = Update-MacAddress -mac $config.properties.endMacAddress
    }

    return $config
}

function Set-MacPoolConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$Config
    )

    $configFileName = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["macpoolFile"]
    $Config | ConvertTo-Json -Depth 100 | Out-File $configFileName -Force
}

function Get-SdnConfig {
    $configFileName = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["sdnConfigFile"]
    $config = Get-Config $configFileName
    return $config
}

function Test-ValidDepId {
    param(
        [parameter(Mandatory = $true)][string] $id
    )

    if ($id.Length -gt 9) {
        Write-TraceLog "Test-ValidDepId failed, id $id must be less than 9 characters"
        return $false
    }

    $names = @("NC-$id", "$id-$(Get-RouterVMSuffix)", "$id-$(Get-NCVMSuffix)0", "$id-$(Get-MUXVMSuffix)0", "$id-$(Get-GWVMSuffix)0")
    foreach($name in $names) {
        $result = (Resolve-DnsName $name -ErrorAction SilentlyContinue)

        if ($result -ne $null) {
            Write-TraceLog "Test-ValidDepId failed, another deployment with id $id already exists"
            return $false
        }
    }
   
    Write-TraceLog "Test-ValidDepId $id passed all validations"
    return $true
}
function Get-NewDepId {
    while($true) {
        $id = ((New-Guid).guid).split("-")[0]
        # Skip if the name is already in use
        if ($(Test-ValidDepId -id $id)) {
            return $id
        }        
    }
}

function Set-DeploymentId {
    param(
        [parameter(Mandatory = $false)][string] $id
    )

    $internalConfig = Get-TurnKeySdnInternalConfig -configType state
    $internalConfig.depId = $id

    if ([String]::IsNullOrEmpty($internalConfig.torId)) {
        $internalConfig.torId = $id
    }

    Set-TurnKeySdnInternalConfig -configType state -config $internalConfig
}

function Get-TurnKeySdnDeploymentId {

    $configFileName = Join-Path (Get-StorePath) $script:CMap["state"]
    $config = Get-Config $configFileName
    return $config.depId
}

function Get-TorId {

    $configFileName = Join-Path (Get-StorePath) $script:CMap["state"]
    $config = Get-Config $configFileName
    return $config.torId
}

function Get-StateFileWithoutInit {
    $csv = Get-CSV

    if ($csv -ne $null) {
        $installPath = Join-Path $csv "TurnKeySdn"
    }
    else {
        $installPath = Join-Path $Env:SystemDrive "TurnKeySdn"
    }

    $storePath = Join-Path $installPath ".store"
    $configFileName = Join-Path $storePath $script:CMap["state"]

    return $configFileName
}

function Remove-TurnKeySdnStore {

    param (
        [parameter(Mandatory = $false)][switch] $SkipStore
    )

    try {
        $depConfig = Get-DeploymentConfig
        $deployFolder = $depConfig.vmLocation

        if (-not [string]::IsNullOrEmpty($deployFolder)) {
            Write-TraceLog "Remove-TurnKeySdnStore removing deployment folder $deployFolder"
            Remove-Item $depConfig.vmLocation -Recurse -Force -ErrorAction SilentlyContinue
        }
    }
    catch {
        Write-TraceLog "Remove-TurnKeySdnStore: Failed to remove vmLocation $deployFolder, error $_"
    }

    try {
        $workloadConfig = Get-TurnKeySdnWorkloadConfig
        $workloadDeployFolder = $workloadConfig.deploymentpath

        if (-not [String]::IsNullOrEmpty($workloadDeployFolder)) {
            Write-TraceLog "Remove-TurnKeySdnStore removing workload folder $workloadDeployFolder"
            Remove-Item $workloadDeployFolder -Recurse -Force -ErrorAction SilentlyContinue
        }
    }
    catch {
        Write-TraceLog "Remove-TurnKeySdnStore: Failed to remove deploymentpath $workloadDeployFolder, error $_"
    }

    if (Test-IsInitialized) {
        try {
            $inernalWorkConfig = Get-InternalWorkloadConfigPath
            
            if (-not [String]::IsNullOrEmpty($inernalWorkConfig)) {
                Write-TraceLog "Remove-TurnKeySdnStore removing workload config folder $inernalWorkConfig"
                Remove-Item $inernalWorkConfig -Recurse -Force -ErrorAction SilentlyContinue
            }
        }
        catch {
            Write-TraceLog "Remove-TurnKeySdnStore: Failed to remove deploymentpath $inernalWorkConfig, error $_"
        }


        try {
            $inernalDepConfig = Get-InternalDeploymentConfigPath
            
            if (-not [String]::IsNullOrEmpty($inernalDepConfig)) {
                Write-TraceLog "Remove-TurnKeySdnStore removing deployment config folder $inernalDepConfig"
                Remove-Item $inernalDepConfig -Recurse -Force -ErrorAction SilentlyContinue
            }
        }
        catch {
            Write-TraceLog "Remove-TurnKeySdnStore: Failed to remove deploymentpath $inernalDepConfig, error $_"
        }
    }

    $configPresent = Test-TurnKeySdnStateConfigExist
    if ($($SkipStore.IsPresent) -and $configPresent) {
        Write-TraceLog "Remove-TurnKeySdnStore: Resetting install states"
        $state = Get-StateInternal
        $state.depId = ""
        $state.initialized = $false
        $state.installState = $script:InstallStateNone
        $state.mgmtIPOffset = "0"
        Set-TurnKeySdnInternalConfig -configType state -config $state
        Write-TraceLog "Remove-TurnKeySdnStore: Skipping store path removal"
        return
    }

    try {
        $storePath = Get-TurnKeySdnPath

        if (-not [String]::IsNullOrEmpty($storePath)) {
            Write-TraceLog "Remove-TurnKeySdnStore removing storePath $storePath"
            Remove-Item $storePath -Recurse -Force -ErrorAction SilentlyContinue
        }
    }
    catch {
        Write-TraceLog "Remove-TurnKeySdnStore: Failed to remove storePath $storePath, error $_"
    }
}

function Get-TurnKeySdnRestEndpoint {
    $sdnConfig = Get-SdnConfig

    $endpoint = $sdnConfig.networkController.restName

    if (-not [String]::IsNullOrEmpty($endpoint)) {
        return $endpoint
    }

    if ([String]::IsNullOrEmpty($sdnConfig.networkController.restIpAddress)) {
        throw "Invalid sdn configuration, both restname and IP are empty"
    }

    return $sdnConfig.networkController.restIpAddress.split("/")[0]
}
function Get-TurnKeySdnNCRuntime() {
    $sdnConfig = Get-SdnConfig
    return $sdnConfig.networkController.runtime
}

function Set-TurnKeySdnConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$sdnConfig
    )

    $configString = $sdnConfig | ConvertTo-Json -Depth 10
    $configFile = Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["sdnConfigFile"]
    Set-Content -Path $configFile -Value $configString -Encoding UTF8
}

function Set-DeploymentConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$deploymentConfig
    )    

    $configString = $deploymentConfig | ConvertTo-Json -Depth 10
    Set-Content -Path $(Get-DeploymentFile) -Value $configString -Encoding UTF8
}

function LoadSdnExpressConfig {
    $sdnexpress = Import-LocalizedData `
        -BaseDirectory $script:CMap["sdnExpressConfigPath"] `
        -FileName $script:CMap["sdnExpressTemplateFile"]

    return $sdnexpress
}

function Get-WorkloadConfigPath {
    param(
        [ValidateSet("LoadBalancer", "VNET", "LogicalNetwork", "Gateway", "None", "HLK")]
        [Parameter(Mandatory = $false)] $WorkloadType,
        [Parameter(Mandatory = $false)] $WorkloadFolder
    )

    if ($WorkloadType -eq "None" -or [String]::IsNullOrEmpty($WorkloadType)) {
        $WorkloadType = "LoadBalancer"
    }

    if ([String]::IsNullOrEmpty($WorkloadFolder)) {
        $WorkloadFolder = $WorkloadType
    }

    $path = Join-Path(Get-InternalWorkloadConfigPath) $WorkloadFolder

    if (-not (Test-Path $path)) {
        throw "Workload $WorkloadType not found at $path"
    }

    return $path
}
function Get-TurnKeySdnWorkloadConfig {
    $workloadConfigFile = Join-Path (Get-InternalWorkloadConfigPath) $script:CMap["workload"]
    $workloadConfig = Get-Config $workloadConfigFile
    return $workloadConfig
}
function Get-SdnWorkloadDeploymentPath {
    $workloadConfig = Get-TurnKeySdnWorkloadConfig

    if (-not [String]::isnullorempty($workloadConfig.deploymentpath)) {
        return $workloadConfig.deploymentpath
    }
}

function Set-TurnKeySdnWorkloadConfig {
    param(
        [parameter(Mandatory = $true)][PSCustomObject]$config
    )    

    $configString = $config | ConvertTo-Json -Depth 10
    $configFile = Join-Path (Get-InternalWorkloadConfigPath) $script:CMap["workload"]
    Set-Content -Path $configFile -Value $configString -Encoding UTF8
}

function Get-SdnWorkloadVirtualGateways {
    param(
        [Parameter(Mandatory = $true)] $WorkloadConfigPath
    )

    $jsonPath = Join-Path $workloadConfigPath "jsons\virtualgateways"

    if (-not $(Test-Path $jsonPath)) {
        return $null
    }

    Get-ChildItem $jsonPath
}
function Get-SdnWorkloadLogicalNetworks {
    param(
        [Parameter(Mandatory = $true)] $WorkloadConfigPath
    )

    $jsonPath = Join-Path $workloadConfigPath "jsons\logicalnetworks"

    if (-not $(Test-Path $jsonPath)) {
        return $null
    }

    Get-ChildItem $jsonPath
}

function Get-SdnWorkloadNetworkInterfaces {
    param(
        [Parameter(Mandatory = $true)] $WorkloadConfigPath
    )

    $nicJsonPath = Join-Path $workloadConfigPath "jsons\networkinterfaces"

    if (-not $(Test-Path $nicJsonPath)) {
        return $null
    }

    Get-ChildItem $nicJsonPath
}


function Get-SdnWorkloadLoadbalancers {
    param(
        [Parameter(Mandatory=$true)] $WorkloadConfigPath
    )

    $lbJsonPath = Join-Path $workloadConfigPath "jsons\loadbalancers"

    if (-not $(Test-Path $lbJsonPath)) {
        return $null
    }

    Get-ChildItem $lbJsonPath
}

function Get-TurnKeySdnHyperVHosts {
    $depConfig = Get-DeploymentConfig

    if ($depConfig.hyperVHosts.Count -gt 0) {
        return $depConfig.hyperVHosts
    }

    if (Test-IsCluster) {
        Write-TraceLog "Get-TurnKeySdnHyperVHosts: No hosts found, defaulting to clusternodes"
        $hypervHosts = (get-cluster | get-clusternode).Name
    }
    else {
        Write-TraceLog "Get-TurnKeySdnHyperVHosts: No hosts found, defaulting to local host"
        $hypervHosts = @($(hostname))
    }

    return $hypervHosts
}

function Get-SdnSwitchName {
    $depConfig = Get-DeploymentConfig
    return $depConfig.sdnSwitchName
}

function Initialize-TurnKeySdnDeploymentId {

    $config = Get-TurnKeySdnInternalConfig -configType state
    $updated = $false

    if ([String]::IsNullOrEmpty($config.depId)) {
        $config.depId = Get-NewDepId
        $updated = $true
    }

    if ([String]::IsNullOrEmpty($config.torId)) {
        $config.torId = $config.depId
        $updated = $true
    }

    if ([String]::IsNullOrEmpty($config.randomizerSeed)) {
        $config.randomizerSeed = Get-AddressRandmoizerSeed
        $updated = $true
    }

    if ($updated) {       
        Set-TurnKeySdnInternalConfig -configType state -config $config
    }
}

function Initialize-Store {

    Initialize-StorePath
    
    $script:CMap["deploymentConfigPath"] = Join-Path $script:CMap["turnKeySdnPath"] "DeploymentConfig"
    $script:CMap["workloadConfigPath"] = Join-Path $script:CMap["turnKeySdnPath"] "WorkloadConfig"

    $internalConfigPath = $script:CMap["deploymentConfigPath"]
    $internalWorkloadConfigPath = $script:CMap["workloadConfigPath"]

    if (-not (Test-Path $internalConfigPath)) {
        New-Item $internalConfigPath -ItemType Directory -ErrorAction Stop | Out-Null
    }

    if (-not (Test-Path $internalWorkloadConfigPath)) {
        New-Item $internalWorkloadConfigPath -ItemType Directory -ErrorAction Stop | Out-Null
    }

    $userConfigPath = $script:CMap["userConfigPath"]
    Write-TraceLog "Copying user config from $userConfigPath to $internalConfigPath"

    robocopy $userConfigPath $script:CMap["deploymentConfigPath"] /E /XO /NC /NS /NP /NFL /NDL /NJH /NJS

    $userWorkloadConfigPath = $script:CMap["userWorkloadConfigPath"]
    Write-TraceLog "Copying user workload config from $userWorkloadConfigPath to $internalWorkloadConfigPath"

    robocopy $userWorkloadConfigPath $internalWorkloadConfigPath /E /XO /NC /NS /NP /NFL /NDL /NJH /NJS

    $vhdStore = Get-VhdStore

    if (-not (Test-Path $vhdStore)) {
        New-Item $vhdStore -ItemType Directory -ErrorAction Stop | Out-Null
    }

    $credFile = Join-Path (Get-StorePath) $script:CMap["credential"]
    if (-not $(Test-Path $credFile)) {
        $cred = @{}
        $cred["username"] = ""
        $cred["password"] = ""
        Set-TurnKeySdnInternalConfig -configType credential -config $cred
    }

    $stateFile = Join-Path (Get-StorePath) $script:CMap["state"]
    if (-not $(Test-Path $stateFile)) {
        $state = @{}
        $state["depId"] = ""
        $state["torId"] = ""
        $state["randomizerSeed"] = ""
        $state["initialized"] = $false
        $state["installState"] = $script:InstallStateNone
        $state["mgmtIPOffset"] = "0"
        Set-TurnKeySdnInternalConfig -configType state -config $state
    }

    Initialize-TurnKeySdnDeploymentId
}

function Get-DeploymentFile {
    return Join-Path (Get-InternalDeploymentConfigPath) $script:CMap["deploymentFile"]
}

function Get-MgmtNicName {
    return $script:MgmtHostNicName
}

function Get-DefaultWorkloadVhdShare {
    return $script:DefaultTestVhdShare
}

function Get-DefaultWorkloadVhdFile {
    return $script:DefaultTestVhdFile
}

function Get-StateInternal {
    $stateFile = Get-StateFileWithoutInit
    $config = Get-Config $stateFile
    return $config
}

function Set-InstallState {
    param(
        [ValidateSet("installed", "installFailed", "installing", "none")]
        [parameter(Mandatory = $true)][string] $state
    )

    $config = Get-StateInternal
    $config.installState = $state
    Set-TurnKeySdnInternalConfig -configType state -config $config
}

function Test-IsInstalled {
    try {
        $config = Get-StateInternal
    }
    catch {
        return $false
    }
    return $config.installState -ieq "installed"
}

function Test-IsInitialized {

    try {
        $config = Get-StateInternal
    }
    catch {
        return $false
    }

    return $config.initialized
}

function Set-Initialized {
    $config = Get-TurnKeySdnInternalConfig -configType state
    $config.initialized = $true
    Set-TurnKeySdnInternalConfig -configType state -config $config
}

function Get-NextManagementIPOffset {

    $config = Get-StateInternal
    [int]$offset = $config.mgmtIPOffset
    $config.mgmtIPOffset = $offset + 1
    Set-TurnKeySdnInternalConfig -configType state -config $config
    return $offset
}

function Initialize-ManagementIPOffset {
    $config = Get-StateInternal
    $config.mgmtIPOffset = 0
    Set-TurnKeySdnInternalConfig -configType state -config $config
}

function Get-MsftCorpRoutes {
    return $script:MSFTCorpRoutes
}

function Test-RRASRouterEnabled {
    $depConfig = Get-DeploymentConfig
    return $depConfig.useRRASRouter
}

function Get-DefaultInternetSwitchName {
    return $script:InternetSwitchDefaultName
}

function Get-DefaultSdnSwitchName {
    return $script:SdnSwitchDefaultName
}

function Get-RouterVMSuffix {
    "-TOR"
}

function Get-NCVMSuffix {
    "-NC"
}

function Get-MUXVMSuffix {
    "-MUX"
}

function Get-GWVMSuffix {
    "-GW"
}
# SIG # Begin signature block
# MIIoKgYJKoZIhvcNAQcCoIIoGzCCKBcCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCXqtYGTYkJpISt
# /7UjRGQIzF1ySN2koe6itde46cmWzqCCDXYwggX0MIID3KADAgECAhMzAAADrzBA
# DkyjTQVBAAAAAAOvMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24xKDAmBgNVBAMTH01pY3Jvc29mdCBDb2RlIFNpZ25p
# bmcgUENBIDIwMTEwHhcNMjMxMTE2MTkwOTAwWhcNMjQxMTE0MTkwOTAwWjB0MQsw
# CQY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