When using the NetApp Cloud Insights PS Tool - insight-migration.py - to migrate multiple OCI Servers into one CI instance, the Annotation Definition values for FLEXIBLE_ENUM and FIXED_ENUM type annotations (lists) get overwritten. To get around this, I wrote this fairly simple PowerShell tool that will process AnnotationDefinition.json files and give an output. The script is as follows:
PARAM(
[Parameter(Mandatory)][String]$SrcFile,
[Parameter(Mandatory)][String]$AddFile,
[Parameter(Mandatory)][String]$OutFile
)
WRITE-HOST "Getting Annotation Definitions in source file $SrcFile"
$AnnoDefs = GET-CONTENT -Raw -Path $SrcFile | ConvertFrom-Json
$AnnoDefs = $AnnoDefs | WHERE-OBJECT {(($_.type -eq "FLEXIBLE_ENUM") -OR ($_.type -eq "FIXED_ENUM")) -AND ($_.isUserDefined -eq "True")}
WRITE-HOST "Getting Annotation Definitions in additional file $AddFile"
$newAnnoDefs = GET-CONTENT -Raw -Path $AddFile | ConvertFrom-Json
$newAnnoDefs = $newAnnoDefs | WHERE-OBJECT {(($_.type -eq "FLEXIBLE_ENUM") -OR ($_.type -eq "FIXED_ENUM")) -AND ($_.isUserDefined -eq "True")}
WRITE-HOST "Cycling through the Annotation Definitions in the additional file."
FOREACH($newAD IN $newAnnoDefs){
$IDX = [array]::indexof($AnnoDefs.name,$newAD.name)
IF($IDX -eq -1){
WRITE-HOST "We do not have -"($newAD.name)"- adding!"
$AnnoDefs += $newAD}
IF($IDX -ne -1){
WRITE-HOST "Cycling through the Enum Values."
FOREACH($enumValue in $newAD.enumvalues){
IF($AnnoDefs[$IDX].enumvalues.name -contains $enumValue.name){
WRITE-HOST "EnumValue already exists!"}
ELSE{
WRITE-HOST "Adding EnumValue:"$newAD.name"->"$enumValue.name
$AnnoDefs[$IDX].enumvalues += $enumValue}
}
}
}
WRITE-HOST "Outputting Annotation Definitions to output file $OutFile"
$AnnoDefs | ConvertTo-Json -Depth 3 | Set-Content $OutFile
Lessons learned:
- It does work.
- You will need to run it with a proper AnnotationValues.json, otherwise it errors.
- It's worth checking the errors as it could be weird characters stopping the import (in which case you can just edit the AnnotationDefinition.json file to remove the offenders.
- For another post: Need a way of comparing the Annotation Definitions we are loading, with what we get at the end (i.e. if migration tool errored, which annotation failed to come across.)
Comments
Post a Comment